Skip to content

Commit

Permalink
clangf
Browse files Browse the repository at this point in the history
  • Loading branch information
ladyada committed Jan 24, 2025
1 parent 4e18f58 commit cce029c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 103 deletions.
191 changes: 105 additions & 86 deletions Adafruit_ST7796S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand All @@ -24,37 +24,51 @@

#include "Adafruit_ST7796S.h"

static const uint8_t PROGMEM st7796s_init[] = {
14, // 14 commands
ST77XX_SWRESET, ST_CMD_DELAY, // Software reset
150,
0xF0, 1, // Unlock manufacturer
0xC3,
0xF0, 1,
0x96,
0xC5, 1, // VCOM Control
0x1C,
ST77XX_MADCTL, 1, // Memory Access
0x48,
ST77XX_COLMOD, 1, // Color Mode - 16 bit
0x55,
0xB0, 1, // Interface Control
0x80,
0xB4, 1, // Inversion Control
0x00,
0xB6, 3, // Display Function Control
0x80, 0x02, 0x3B,
0xB7, 1, // Entry Mode
0xC6,
0xF0, 1, // Lock manufacturer commands
0x69,
0xF0, 1,
0x3C,
ST77XX_SLPOUT, ST_CMD_DELAY, // Exit sleep
150,
ST77XX_DISPON, ST_CMD_DELAY, // Display on
150
};
static const uint8_t PROGMEM st7796s_init[] = {14, // 14 commands
ST77XX_SWRESET,
ST_CMD_DELAY, // Software reset
150,
0xF0,
1, // Unlock manufacturer
0xC3,
0xF0,
1,
0x96,
0xC5,
1, // VCOM Control
0x1C,
ST77XX_MADCTL,
1, // Memory Access
0x48,
ST77XX_COLMOD,
1, // Color Mode - 16 bit
0x55,
0xB0,
1, // Interface Control
0x80,
0xB4,
1, // Inversion Control
0x00,
0xB6,
3, // Display Function Control
0x80,
0x02,
0x3B,
0xB7,
1, // Entry Mode
0xC6,
0xF0,
1, // Lock manufacturer commands
0x69,
0xF0,
1,
0x3C,
ST77XX_SLPOUT,
ST_CMD_DELAY, // Exit sleep
150,
ST77XX_DISPON,
ST_CMD_DELAY, // Display on
150};

/**
* @brief Constructor with software SPI.
Expand All @@ -64,8 +78,10 @@ static const uint8_t PROGMEM st7796s_init[] = {
* @param SCLK SPI clock pin.
* @param RST Reset pin (optional).
*/
Adafruit_ST7796S::Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t MOSI, int8_t SCLK, int8_t RST)
: Adafruit_ST77xx(ST7796S_TFTWIDTH, ST7796S_TFTHEIGHT, CS, RS, MOSI, SCLK, RST) {}
Adafruit_ST7796S::Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t MOSI,
int8_t SCLK, int8_t RST)
: Adafruit_ST77xx(ST7796S_TFTWIDTH, ST7796S_TFTHEIGHT, CS, RS, MOSI, SCLK,
RST) {}

/**
* @brief Constructor with hardware SPI.
Expand All @@ -84,8 +100,10 @@ Adafruit_ST7796S::Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t RST)
* @param RS Data/command pin.
* @param RST Reset pin (optional).
*/
Adafruit_ST7796S::Adafruit_ST7796S(SPIClass *spiClass, int8_t CS, int8_t RS, int8_t RST)
: Adafruit_ST77xx(ST7796S_TFTWIDTH, ST7796S_TFTHEIGHT, spiClass, CS, RS, RST) {}
Adafruit_ST7796S::Adafruit_ST7796S(SPIClass *spiClass, int8_t CS, int8_t RS,
int8_t RST)
: Adafruit_ST77xx(ST7796S_TFTWIDTH, ST7796S_TFTHEIGHT, spiClass, CS, RS,
RST) {}
#endif

/**
Expand All @@ -96,64 +114,65 @@ Adafruit_ST7796S::Adafruit_ST7796S(SPIClass *spiClass, int8_t CS, int8_t RS, int
* @param colOffset Column offset for display.
* @param colorOrder Color order (RGB or BGR).
*/
void Adafruit_ST7796S::init(uint16_t width, uint16_t height, uint8_t rowOffset, uint8_t colOffset,
ST7796S_ColorOrder colorOrder) {
_width = width;
_height = height;
_rowstart = rowOffset;
_colstart = colOffset;
_colorOrder = colorOrder;
windowWidth = width;
windowHeight = height;
void Adafruit_ST7796S::init(uint16_t width, uint16_t height, uint8_t rowOffset,
uint8_t colOffset, ST7796S_ColorOrder colorOrder) {
_width = width;
_height = height;
_rowstart = rowOffset;
_colstart = colOffset;
_colorOrder = colorOrder;
windowWidth = width;
windowHeight = height;

commonInit(NULL);
displayInit(st7796s_init);
invertOnCommand = ST77XX_INVOFF;
invertOffCommand = ST77XX_INVON;
invertDisplay(false);
setRotation(0);
commonInit(NULL);
displayInit(st7796s_init);
invertOnCommand = ST77XX_INVOFF;
invertOffCommand = ST77XX_INVON;
invertDisplay(false);
setRotation(0);
}

/**
* @brief Set the display rotation.
* @param m Rotation value (0-3).
*/
void Adafruit_ST7796S::setRotation(uint8_t m) {
uint8_t madctl = 0;
uint8_t madctl = 0;

rotation = m & 3; // can't be higher than 3
rotation = m & 3; // can't be higher than 3

switch (rotation) {
case 0:
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _colstart;
_ystart = _rowstart;
_width = windowWidth;
_height = windowHeight;
break;
case 1:
madctl = ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _rowstart;
_ystart = _colstart;
_height = windowWidth;
_width = windowHeight;
break;
case 2:
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _colstart;
_ystart = _rowstart;
_width = windowWidth;
_height = windowHeight;
break;
case 3:
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MX | ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _rowstart;
_ystart = _colstart;
_height = windowWidth;
_width = windowHeight;
break;
}
switch (rotation) {
case 0:
madctl = ST77XX_MADCTL_MX | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _colstart;
_ystart = _rowstart;
_width = windowWidth;
_height = windowHeight;
break;
case 1:
madctl = ST77XX_MADCTL_MV | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _rowstart;
_ystart = _colstart;
_height = windowWidth;
_width = windowHeight;
break;
case 2:
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _colstart;
_ystart = _rowstart;
_width = windowWidth;
_height = windowHeight;
break;
case 3:
madctl = ST77XX_MADCTL_MY | ST77XX_MADCTL_MX | ST77XX_MADCTL_MV |
ST77XX_MADCTL_RGB | _colorOrder;
_xstart = _rowstart;
_ystart = _colstart;
_height = windowWidth;
_width = windowHeight;
break;
}

Serial.println(madctl, HEX);
sendCommand(ST77XX_MADCTL, &madctl, 1);
Serial.println(madctl, HEX);
sendCommand(ST77XX_MADCTL, &madctl, 1);
}
33 changes: 16 additions & 17 deletions Adafruit_ST7796S.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand Down Expand Up @@ -44,32 +44,31 @@
* @brief Enum for ST7796S color order.
*/
enum ST7796S_ColorOrder {
ST7796S_RGB = 0x00, ///< Red-Green-Blue color order
ST7796S_BGR = 0x08 ///< Blue-Green-Red color order
ST7796S_RGB = 0x00, ///< Red-Green-Blue color order
ST7796S_BGR = 0x08 ///< Blue-Green-Red color order
};

/**
* @brief Adafruit driver for the ST7796S TFT display.
*/
class Adafruit_ST7796S : public Adafruit_ST77xx {
public:
Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t MOSI, int8_t SCLK, int8_t RST = -1);
Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t RST = -1);
public:
Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t MOSI, int8_t SCLK,
int8_t RST = -1);
Adafruit_ST7796S(int8_t CS, int8_t RS, int8_t RST = -1);
#if !defined(ESP8266)
Adafruit_ST7796S(SPIClass *spiClass, int8_t CS, int8_t RS, int8_t RST);
Adafruit_ST7796S(SPIClass *spiClass, int8_t CS, int8_t RS, int8_t RST);
#endif

void init(uint16_t width = ST7796S_TFTWIDTH,
uint16_t height = ST7796S_TFTHEIGHT,
uint8_t rowOffset = 0,
uint8_t colOffset = 0,
ST7796S_ColorOrder colorOrder = ST7796S_RGB);
void init(uint16_t width = ST7796S_TFTWIDTH,
uint16_t height = ST7796S_TFTHEIGHT, uint8_t rowOffset = 0,
uint8_t colOffset = 0, ST7796S_ColorOrder colorOrder = ST7796S_RGB);

void setRotation(uint8_t r);
void setRotation(uint8_t r);

private:
ST7796S_ColorOrder _colorOrder; ///< Color order setting.
uint16_t windowWidth, windowHeight; ///< Dimensions of the display window.
private:
ST7796S_ColorOrder _colorOrder; ///< Color order setting.
uint16_t windowWidth, windowHeight; ///< Dimensions of the display window.
};

#endif

0 comments on commit cce029c

Please sign in to comment.