ST7735_t3 Library - Can TFT_MAD_MX be Changed?

mgaert

Active member
I'd like to change the display mirroring in my ST7789 320X480 display. Seems like I need to change TFT_MAD_MX and/or TFT_MAD_MY values. I don't see a way to do that in this library. Perhaps it's not implemented. Thoughts on if or how this can be done?

Thanks!
 
Note: The defines for things like TFT_MAD_MX are just the names for the different bits in the MADCTL register.

What you probably need is the ability change what is stored in the MADCTL register for the different rotations.

There are probably several different ways to accomplish this. You could hack it. Or someone could add in some method,
to say the image is mirrored. Or you could probably do some simple hack by sub-classing the ST7789 class, like:

C++:
class ST7789_custom : public ST7789_t3 {

 public:

  ST7789_custom(uint8_t CS, uint8_t RS, uint8_t RST = -1) : ST7789_t3(CS, RS, RST) {}
  virtual void  setRotation(uint8_t m);
};
And add then:
C++:
void  ST7789_custom::setRotation(uint8_t m)
{
  beginSPITransaction();
  writecommand(ST7735_MADCTL);
  rotation = m % 4; // can't be higher than 3
  switch (rotation) {
   case 0:
     writedata_last(ST77XX_MADCTL_MX | ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB);

     _xstart = _colstart;
     _ystart = _rowstart;
     _width = _screenWidth;
     _height = _screenHeight;
     break;
   case 1:
     writedata_last(ST77XX_MADCTL_MY | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB);

     _xstart = _rowstart;
     _ystart = _colstart2;
     _height = _screenWidth;
     _width = _screenHeight;
     break;
  case 2:
     writedata_last(ST77XX_MADCTL_RGB);
     _xstart = _colstart2;
     _ystart = _rowstart2;
     _width = _screenWidth;
     _height = _screenHeight;
     break;

   case 3:
     writedata_last(ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB);
     _xstart = _rowstart2;
     _ystart = _colstart;
     _height = _screenWidth;
     _width = _screenHeight;
     break;
  }
And change which flags are set for each of the rotations...
 
Interesting, thank you! I also had some problems with RGB vs BGR. Maybe I can throw some shade on that, too.
 
I made some quick changes to the ST7789_t3.cpp code. It did change the mirroring and orientation but it didn't do what I wanted. No big, not critical. Thanks for all the info of course.

Had one further question... It seems the display I have is showing colors in BGR order. I couldn't see how to change this. I tried changing
Code:
#define ST77XX_MADCTL_RGB 0x00
to
Code:
#define ST77XX_MADCTL_RGB 0x01
which matches the Sitronix display's data sheet. Didn't make any difference.

Any thoughts?

Thanks!
 
Sorry, first issue I noticed and should have noticed earlier:
ST7789 does not 320x480...

That is an ST7796, which I picked up one of these a bit ago and started working on a sub-class... But so far it was not
fully working...

I will try to take a look again in the next few days.
 
I have a fork/branch up at: https://github.com/KurtE/ST7735_t3/tree/ST7796

Which has a version which might be working:
Sketch needs to include:
Code:
#include <ST7796_t3.h> // Hardware-specific library

Define the object:
Code:
ST7796_t3 tft = ST7796_t3(TFT_CS, TFT_DC, TFT_RST);

And initialize it:
Code:
tft.init(320, 480);   // initialize a ST7789 chip, 240x240 pixels

Need to do some more testing and probably update some of the examples to include this information as options...
 
Haven’t had a chance to try this yet. I did try an older Adafruit library for ST7796S, which works fine but slower. I read that Adafruit ‘cripples’ Teensy boards so their libraries run slower there. Is that true? If so that is not friendly!
 
FYI, I tried the 'graphicstest.ino' and it worked perfectly. I did have to invert the display to get the correct colors but that no big deal. Thanks!
 
Back
Top