diff --git a/Adafruit_ILI9341.cpp b/Adafruit_ILI9341.cpp index eda9b4a..4cb0528 100755 --- a/Adafruit_ILI9341.cpp +++ b/Adafruit_ILI9341.cpp @@ -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 diff --git a/Adafruit_ILI9341.h b/Adafruit_ILI9341.h index 525f0f4..73c08d7 100755 --- a/Adafruit_ILI9341.h +++ b/Adafruit_ILI9341.h @@ -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);