Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Adafruit_ILI9341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,57 @@ void Adafruit_ILI9341::setRotation(uint8_t m) {
sendCommand(ILI9341_MADCTL, &m, 1);
}

/**************************************************************************/
/*!
@brief Set origin of (0,0) and orientation of TFT display
@param m The index for rotation, from 0-3 inclusive
@param mirrored True to mirror display, false to keep display as-is
*/
/**************************************************************************/
void Adafruit_ILI9341::setRotation(uint8_t m, bool mirrored) {
rotation = m % 4; // can't be higher than 3
switch (rotation) {
case 0:
if (mirrored) {
m = (MADCTL_BGR);
} else {
m = (MADCTL_MX | MADCTL_BGR);
}
_width = ILI9341_TFTWIDTH;
_height = ILI9341_TFTHEIGHT;
break;
case 1:
if (mirrored) {
m = (MADCTL_MY | MADCTL_MV | MADCTL_BGR);
} else {
m = (MADCTL_MV | MADCTL_BGR);
}
_width = ILI9341_TFTHEIGHT;
_height = ILI9341_TFTWIDTH;
break;
case 2:
if (mirrored) {
m = (MADCTL_MX | MADCTL_MY | MADCTL_BGR);
} else {
m = (MADCTL_MY | MADCTL_BGR);
}
_width = ILI9341_TFTWIDTH;
_height = ILI9341_TFTHEIGHT;
break;
case 3:
if (mirrored) {
m = (MADCTL_MX | MADCTL_MV | MADCTL_BGR);
} else {
m = (MADCTL_MX | MADCTL_MY | MADCTL_MV | MADCTL_BGR);
}
_width = ILI9341_TFTHEIGHT;
_height = ILI9341_TFTWIDTH;
break;
}

sendCommand(ILI9341_MADCTL, &m, 1);
}

/**************************************************************************/
/*!
@brief Enable/Disable display color inversion
Expand Down
1 change: 1 addition & 0 deletions Adafruit_ILI9341.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Adafruit_ILI9341 : public Adafruit_SPITFT {

void begin(uint32_t freq = 0);
void setRotation(uint8_t r);
void setRotation(uint8_t r, bool mirrored);
void invertDisplay(bool i);
void scrollTo(uint16_t y);
void setScrollMargins(uint16_t top, uint16_t bottom);
Expand Down