Bodmer / TFT_HX8357

Arduino library for HX8357 TFT display
118 stars 52 forks source link

BMP images flipped #38

Open Pre2 opened 4 years ago

Pre2 commented 4 years ago

Impressive library! Minor (solved) bug: While testing the example "Draw_SDcard_Bitmap.ino" on Arduino MEGA for a TFT-3.5" display, 480x320 size, 16-bit (model MAR3513) parallel interface, driver ILI9486 (marked on the module) and set as such in User_Setup.h, the following issue occurred, for any rotation 0...3 (SdFat library was used) : -The BMB files are Left-Right flipped and writing text on a blank page with the same orientation gives inverted text. I modified TFT_HX8357.cpp and now all works fine:

/ Function name: setRotation Description: rotate the screen orientation m = 0-3 or 4-7 for BMP drawing /

define MADCTL_MY 0x80

define MADCTL_MX 0x40

define MADCTL_MV 0x20

define MADCTL_ML 0x10

define MADCTL_RGB 0x00

define MADCTL_BGR 0x08

define MADCTL_SS 0x02

define MADCTL_GS 0x01

ifdef ILI9481

void TFT_HX8357::setRotation(uint8_t m) { writecommand(HX8357_MADCTL); rotation = m % 4; switch (rotation) { case 0: // Portrait

ifdef ILI9486 // MADCTL [MY, MX, MV, ML, BGR, MH, xx, xx]

writedata (0x08+(m>3)*0x90);    // Modified MVP for BMP 

else

 writedata(MADCTL_BGR | MADCTL_SS);

endif

 _width  = HX8357_TFTWIDTH;
 _height = HX8357_TFTHEIGHT;
 break;

case 1: // Landscape (Portrait + 90)

ifdef ILI9486

writedata (0x68-(m>3)*0x40);    // Modified MVP for BMP

else

 writedata(MADCTL_MV | MADCTL_BGR);

endif

 _width  = HX8357_TFTHEIGHT;
 _height = HX8357_TFTWIDTH;
 break;

case 2: // Inverter portrait

ifdef ILI9486

writedata (0xD8-(m>3)*0x90);    // Modified MVP for BMP

else

 writedata( MADCTL_BGR | MADCTL_GS);

endif

 _width  = HX8357_TFTWIDTH;
 _height = HX8357_TFTHEIGHT;
 break;

case 3: // Inverted landscape

ifdef ILI9486

writedata (0xA8+(m>3)*0x40);    // Modified MVP for BMP

else

 writedata(MADCTL_MV | MADCTL_BGR | MADCTL_SS | MADCTL_GS);

endif

 _width  = HX8357_TFTHEIGHT;
 _height = HX8357_TFTWIDTH;
 break;

} }