mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Add invert_colors option for st7735 (#2327)
This commit is contained in:
		| @@ -23,6 +23,7 @@ CONF_ROW_START = "row_start" | |||||||
| CONF_COL_START = "col_start" | CONF_COL_START = "col_start" | ||||||
| CONF_EIGHT_BIT_COLOR = "eight_bit_color" | CONF_EIGHT_BIT_COLOR = "eight_bit_color" | ||||||
| CONF_USE_BGR = "use_bgr" | CONF_USE_BGR = "use_bgr" | ||||||
|  | CONF_INVERT_COLORS = "invert_colors" | ||||||
|  |  | ||||||
| SPIST7735 = st7735_ns.class_( | SPIST7735 = st7735_ns.class_( | ||||||
|     "ST7735", cg.PollingComponent, display.DisplayBuffer, spi.SPIDevice |     "ST7735", cg.PollingComponent, display.DisplayBuffer, spi.SPIDevice | ||||||
| @@ -58,6 +59,7 @@ CONFIG_SCHEMA = cv.All( | |||||||
|             cv.Required(CONF_ROW_START): cv.int_, |             cv.Required(CONF_ROW_START): cv.int_, | ||||||
|             cv.Optional(CONF_EIGHT_BIT_COLOR, default=False): cv.boolean, |             cv.Optional(CONF_EIGHT_BIT_COLOR, default=False): cv.boolean, | ||||||
|             cv.Optional(CONF_USE_BGR, default=False): cv.boolean, |             cv.Optional(CONF_USE_BGR, default=False): cv.boolean, | ||||||
|  |             cv.Optional(CONF_INVERT_COLORS, default=False): cv.boolean, | ||||||
|         } |         } | ||||||
|     ) |     ) | ||||||
|     .extend(cv.COMPONENT_SCHEMA) |     .extend(cv.COMPONENT_SCHEMA) | ||||||
| @@ -90,6 +92,7 @@ async def to_code(config): | |||||||
|         config[CONF_ROW_START], |         config[CONF_ROW_START], | ||||||
|         config[CONF_EIGHT_BIT_COLOR], |         config[CONF_EIGHT_BIT_COLOR], | ||||||
|         config[CONF_USE_BGR], |         config[CONF_USE_BGR], | ||||||
|  |         config[CONF_INVERT_COLORS], | ||||||
|     ) |     ) | ||||||
|     await setup_st7735(var, config) |     await setup_st7735(var, config) | ||||||
|     await spi.register_spi_device(var, config) |     await spi.register_spi_device(var, config) | ||||||
|   | |||||||
| @@ -220,12 +220,14 @@ static const uint8_t PROGMEM | |||||||
| // clang-format on | // clang-format on | ||||||
| static const char *const TAG = "st7735"; | static const char *const TAG = "st7735"; | ||||||
|  |  | ||||||
| ST7735::ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr) | ST7735::ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr, | ||||||
|  |                bool invert_colors) | ||||||
|     : model_(model), |     : model_(model), | ||||||
|       colstart_(colstart), |       colstart_(colstart), | ||||||
|       rowstart_(rowstart), |       rowstart_(rowstart), | ||||||
|       eightbitcolor_(eightbitcolor), |       eightbitcolor_(eightbitcolor), | ||||||
|       usebgr_(usebgr), |       usebgr_(usebgr), | ||||||
|  |       invert_colors_(invert_colors), | ||||||
|       width_(width), |       width_(width), | ||||||
|       height_(height) {} |       height_(height) {} | ||||||
|  |  | ||||||
| @@ -281,6 +283,9 @@ void ST7735::setup() { | |||||||
|   } |   } | ||||||
|   sendcommand_(ST77XX_MADCTL, &data, 1); |   sendcommand_(ST77XX_MADCTL, &data, 1); | ||||||
|  |  | ||||||
|  |   if (this->invert_colors_) | ||||||
|  |     sendcommand_(ST77XX_INVON, nullptr, 0); | ||||||
|  |  | ||||||
|   this->init_internal_(this->get_buffer_length()); |   this->init_internal_(this->get_buffer_length()); | ||||||
|   memset(this->buffer_, 0x00, this->get_buffer_length()); |   memset(this->buffer_, 0x00, this->get_buffer_length()); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -37,7 +37,8 @@ class ST7735 : public PollingComponent, | |||||||
|                public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, |                public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW, spi::CLOCK_PHASE_LEADING, | ||||||
|                                      spi::DATA_RATE_8MHZ> { |                                      spi::DATA_RATE_8MHZ> { | ||||||
|  public: |  public: | ||||||
|   ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr); |   ST7735(ST7735Model model, int width, int height, int colstart, int rowstart, bool eightbitcolor, bool usebgr, | ||||||
|  |          bool invert_colors); | ||||||
|   void dump_config() override; |   void dump_config() override; | ||||||
|   void setup() override; |   void setup() override; | ||||||
|  |  | ||||||
| @@ -77,6 +78,7 @@ class ST7735 : public PollingComponent, | |||||||
|   uint8_t colstart_ = 0, rowstart_ = 0; |   uint8_t colstart_ = 0, rowstart_ = 0; | ||||||
|   bool eightbitcolor_ = false; |   bool eightbitcolor_ = false; | ||||||
|   bool usebgr_ = false; |   bool usebgr_ = false; | ||||||
|  |   bool invert_colors_ = false; | ||||||
|   int16_t width_ = 80, height_ = 80;  // Watch heap size |   int16_t width_ = 80, height_ = 80;  // Watch heap size | ||||||
|  |  | ||||||
|   GPIOPin *reset_pin_{nullptr}; |   GPIOPin *reset_pin_{nullptr}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user