9 static const uint8_t ST_CMD_DELAY = 0x80;
11 static const uint8_t ST77XX_NOP = 0x00;
12 static const uint8_t ST77XX_SWRESET = 0x01;
13 static const uint8_t ST77XX_RDDID = 0x04;
14 static const uint8_t ST77XX_RDDST = 0x09;
16 static const uint8_t ST77XX_SLPIN = 0x10;
17 static const uint8_t ST77XX_SLPOUT = 0x11;
18 static const uint8_t ST77XX_PTLON = 0x12;
19 static const uint8_t ST77XX_NORON = 0x13;
21 static const uint8_t ST77XX_INVOFF = 0x20;
22 static const uint8_t ST77XX_INVON = 0x21;
23 static const uint8_t ST77XX_DISPOFF = 0x28;
24 static const uint8_t ST77XX_DISPON = 0x29;
25 static const uint8_t ST77XX_CASET = 0x2A;
26 static const uint8_t ST77XX_RASET = 0x2B;
27 static const uint8_t ST77XX_RAMWR = 0x2C;
28 static const uint8_t ST77XX_RAMRD = 0x2E;
30 static const uint8_t ST77XX_PTLAR = 0x30;
31 static const uint8_t ST77XX_TEOFF = 0x34;
32 static const uint8_t ST77XX_TEON = 0x35;
33 static const uint8_t ST77XX_MADCTL = 0x36;
34 static const uint8_t ST77XX_COLMOD = 0x3A;
36 static const uint8_t ST77XX_MADCTL_MY = 0x80;
37 static const uint8_t ST77XX_MADCTL_MX = 0x40;
38 static const uint8_t ST77XX_MADCTL_MV = 0x20;
39 static const uint8_t ST77XX_MADCTL_ML = 0x10;
40 static const uint8_t ST77XX_MADCTL_RGB = 0x00;
42 static const uint8_t ST77XX_RDID1 = 0xDA;
43 static const uint8_t ST77XX_RDID2 = 0xDB;
44 static const uint8_t ST77XX_RDID3 = 0xDC;
45 static const uint8_t ST77XX_RDID4 = 0xDD;
48 static const uint8_t ST7735_MADCTL_BGR = 0x08;
50 static const uint8_t ST7735_MADCTL_MH = 0x04;
52 static const uint8_t ST7735_FRMCTR1 = 0xB1;
53 static const uint8_t ST7735_FRMCTR2 = 0xB2;
54 static const uint8_t ST7735_FRMCTR3 = 0xB3;
55 static const uint8_t ST7735_INVCTR = 0xB4;
56 static const uint8_t ST7735_DISSET5 = 0xB6;
58 static const uint8_t ST7735_PWCTR1 = 0xC0;
59 static const uint8_t ST7735_PWCTR2 = 0xC1;
60 static const uint8_t ST7735_PWCTR3 = 0xC2;
61 static const uint8_t ST7735_PWCTR4 = 0xC3;
62 static const uint8_t ST7735_PWCTR5 = 0xC4;
63 static const uint8_t ST7735_VMCTR1 = 0xC5;
65 static const uint8_t ST7735_PWCTR6 = 0xFC;
67 static const uint8_t ST7735_GMCTRP1 = 0xE0;
68 static const uint8_t ST7735_GMCTRN1 = 0xE1;
74 ST77XX_SWRESET, ST_CMD_DELAY,
76 ST77XX_SLPOUT, ST_CMD_DELAY,
78 ST77XX_COLMOD, 1+ST_CMD_DELAY,
81 ST7735_FRMCTR1, 3+ST_CMD_DELAY,
94 ST7735_PWCTR1, 2+ST_CMD_DELAY,
103 ST7735_VMCTR1, 2+ST_CMD_DELAY,
110 0x09, 0x16, 0x09, 0x20,
111 0x21, 0x1B, 0x13, 0x19,
112 0x17, 0x15, 0x1E, 0x2B,
113 0x04, 0x05, 0x02, 0x0E,
114 ST7735_GMCTRN1,16+ST_CMD_DELAY,
115 0x0B, 0x14, 0x08, 0x1E,
116 0x22, 0x1D, 0x18, 0x1E,
117 0x1B, 0x1A, 0x24, 0x2B,
118 0x06, 0x06, 0x02, 0x0F,
126 ST77XX_NORON, ST_CMD_DELAY,
128 ST77XX_DISPON, ST_CMD_DELAY,
133 ST77XX_SWRESET, ST_CMD_DELAY,
135 ST77XX_SLPOUT, ST_CMD_DELAY,
195 RCMD2GREEN160X80[] = {
207 0x02, 0x1c, 0x07, 0x12,
208 0x37, 0x32, 0x29, 0x2d,
209 0x29, 0x25, 0x2B, 0x39,
210 0x00, 0x01, 0x03, 0x10,
212 0x03, 0x1d, 0x07, 0x06,
213 0x2E, 0x2C, 0x29, 0x2D,
214 0x2E, 0x2E, 0x37, 0x3F,
215 0x00, 0x00, 0x02, 0x10,
216 ST77XX_NORON, ST_CMD_DELAY,
218 ST77XX_DISPON, ST_CMD_DELAY,
222 static const char *
const TAG =
"st7735";
229 eightbitcolor_(eightbitcolor),
231 invert_colors_(invert_colors),
236 ESP_LOGCONFIG(TAG,
"Setting up ST7735...");
248 ESP_LOGD(TAG,
" START");
250 ESP_LOGD(TAG,
" END");
254 if (this->
model_ == INITR_GREENTAB) {
258 }
else if ((this->
model_ == INITR_144GREENTAB) || (this->
model_ == INITR_HALLOWING)) {
264 }
else if (this->
model_ == INITR_MINI_160X80) {
277 if (this->
model_ != INITR_HALLOWING) {
278 data = ST77XX_MADCTL_MX | ST77XX_MADCTL_MY;
281 data = data | ST7735_MADCTL_BGR;
283 data = data | ST77XX_MADCTL_RGB;
321 this->
buffer_[pos++] = (color565 >> 8) & 0xff;
322 this->
buffer_[pos] = color565 & 0xff;
341 return "ST7735 GREENTAB";
343 return "ST7735 REDTAB";
345 return "ST7735 BLACKTAB";
346 case INITR_MINI_160X80:
347 return "ST7735 MINI160x80";
354 uint8_t num_commands,
cmd, num_args;
358 while (num_commands--) {
361 ms = num_args & ST_CMD_DELAY;
362 num_args &= ~ST_CMD_DELAY;
376 LOG_DISPLAY(
"",
"ST7735",
this);
377 ESP_LOGCONFIG(TAG,
" Model: %s", this->
model_str_());
378 LOG_PIN(
" CS Pin: ", this->
cs_);
379 LOG_PIN(
" DC Pin: ", this->
dc_pin_);
382 ESP_LOGD(TAG,
" Height: %d", this->
height_);
383 ESP_LOGD(TAG,
" Width: %d", this->
width_);
384 ESP_LOGD(TAG,
" ColStart: %d", this->
colstart_);
385 ESP_LOGD(TAG,
" RowStart: %d", this->
rowstart_);
386 LOG_UPDATE_INTERVAL(
this);
406 this->
senddata_(data_bytes, num_data_bytes);
413 for (uint8_t i = 0; i < num_data_bytes; i++) {
424 uint16_t x1 = offsetx;
426 uint16_t y1 = offsety;
467 static uint8_t byte[4];
468 byte[0] = (addr1 >> 8) & 0xFF;
469 byte[1] = addr1 & 0xFF;
470 byte[2] = (addr2 >> 8) & 0xFF;
471 byte[3] = addr2 & 0xFF;
478 static uint8_t byte[1024];
480 for (
int i = 0; i < size; i++) {
481 byte[index++] = (color >> 8) & 0xFF;
482 byte[index++] = color & 0xFF;
virtual void digital_write(bool value)=0
void senddata_(const uint8_t *data_bytes, uint8_t num_data_bytes)
void dump_config() override
static uint16_t color_to_565(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
void spi_setup() override
ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr, bool invert_colors)
void write_byte(uint8_t data)
void init_internal_(uint32_t buffer_length)
const char * model_str_()
static uint8_t color_to_332(Color color, ColorOrder color_order=ColorOrder::COLOR_ORDER_RGB)
void spi_master_write_color_(uint16_t color, uint16_t size)
void line(int x1, int y1, int x2, int y2, Color color=COLOR_ON)
Draw a straight line from the point [x1,y1] to [x2,y2] with the given color.
void spi_master_write_addr_(uint16_t addr1, uint16_t addr2)
void sendcommand_(uint8_t cmd, const uint8_t *data_bytes, uint8_t num_data_bytes)
void writedata_(uint8_t value)
void write_display_data_()
void draw_absolute_pixel_internal(int x, int y, Color color) override
uint8_t progmem_read_byte(const uint8_t *addr)
int get_width_internal() override
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML [] PROGMEM
void writecommand_(uint8_t value)
void write_array(const uint8_t *data, size_t length)
Implementation of SPI Controller mode.
static Color to_color(uint32_t colorcode, ColorOrder color_order, ColorBitness color_bitness=ColorBitness::COLOR_BITNESS_888, bool right_bit_aligned=true)
size_t get_buffer_length()
void display_init_(const uint8_t *addr)
int get_height_internal() override
void IRAM_ATTR HOT delay(uint32_t ms)