Skip to content

Commit

Permalink
Fixed 3.5" TFT text rotation issue
Browse files Browse the repository at this point in the history
Fixed MADCTL values for HX8357B
  • Loading branch information
driverblock committed Nov 13, 2014
1 parent ecf4cf1 commit 97a8285
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
28 changes: 25 additions & 3 deletions Adafruit_TFTLCD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
setLR(); // CS_IDLE happens here
}

if ((driver == ID_9341) || (driver == ID_HX8357D)) {
// MEME, HX8357D uses same registers but different values
if (driver == ID_9341) {
// MEME, HX8357D uses same registers as 9341 but different values
uint16_t t;

switch (rotation) {
Expand All @@ -775,7 +775,29 @@ void Adafruit_TFTLCD::setRotation(uint8_t x) {
// For 9341, init default full-screen address window:
setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here
}
}

if (driver == ID_HX8357D) {
// MEME, HX8357D uses same registers as 9341 but different values
uint16_t t;

switch (rotation) {
case 2:
t = HX8357B_MADCTL_RGB;
break;
case 3:
t = HX8357B_MADCTL_MX | HX8357B_MADCTL_MV | HX8357B_MADCTL_RGB;
break;
case 0:
t = HX8357B_MADCTL_MX | HX8357B_MADCTL_MY | HX8357B_MADCTL_RGB;
break;
case 1:
t = HX8357B_MADCTL_MY | HX8357B_MADCTL_MV | HX8357B_MADCTL_RGB;
break;
}
writeRegister8(ILI9341_MADCTL, t ); // MADCTL
// For 8357, init default full-screen address window:
setAddrWindow(0, 0, _width - 1, _height - 1); // CS_IDLE happens here
}}

#ifdef read8isFunctionalized
#define read8(x) x=read8fn()
Expand Down
2 changes: 2 additions & 0 deletions examples/rotationtest/rotationtest.pde
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ void setup(void) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Expand Down
8 changes: 8 additions & 0 deletions registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@

#define HX8357B_SETGAMMA 0xC8
#define HX8357B_SETPANELRELATED 0xE9

#define HX8357B_MADCTL_MY 0x80
#define HX8357B_MADCTL_MX 0x40
#define HX8357B_MADCTL_MV 0x20
#define HX8357B_MADCTL_ML 0x10
#define HX8357B_MADCTL_RGB 0x00
#define HX8357B_MADCTL_BGR 0x08
#define HX8357B_MADCTL_MH 0x04

0 comments on commit 97a8285

Please sign in to comment.