mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	Support for Adafruit ESP32-S2 TFT Feather (#4912)
Support for optional PowerSupply component for ST7789V This commit makes the power supply required if the model configured in the ST7789V component is set to ADAFRUIT_S2_TFT_FEATHER_240X135. There are at least two boards from Adafruit with this configuration but with a different pin out. This also adds the board pins definition for the board I have. There is discussion on the forums about the other board's documentation not matching reality and I don't have a physical board to confirm.
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							8bb4c65272
						
					
				
				
					commit
					aeb94e166b
				
			| @@ -42,6 +42,39 @@ ESP32_BASE_PINS = { | |||||||
| } | } | ||||||
|  |  | ||||||
| ESP32_BOARD_PINS = { | ESP32_BOARD_PINS = { | ||||||
|  |     "adafruit_feather_esp32s2_tft": { | ||||||
|  |         "BUTTON": 0, | ||||||
|  |         "A0": 18, | ||||||
|  |         "A1": 17, | ||||||
|  |         "A2": 16, | ||||||
|  |         "A3": 15, | ||||||
|  |         "A4": 14, | ||||||
|  |         "A5": 8, | ||||||
|  |         "SCK": 36, | ||||||
|  |         "MOSI": 35, | ||||||
|  |         "MISO": 37, | ||||||
|  |         "RX": 2, | ||||||
|  |         "TX": 1, | ||||||
|  |         "D13": 13, | ||||||
|  |         "D12": 12, | ||||||
|  |         "D11": 11, | ||||||
|  |         "D10": 10, | ||||||
|  |         "D9": 9, | ||||||
|  |         "D6": 6, | ||||||
|  |         "D5": 5, | ||||||
|  |         "NEOPIXEL": 33, | ||||||
|  |         "PIN_NEOPIXEL": 33, | ||||||
|  |         "NEOPIXEL_POWER": 34, | ||||||
|  |         "SCL": 41, | ||||||
|  |         "SDA": 42, | ||||||
|  |         "TFT_I2C_POWER": 21, | ||||||
|  |         "TFT_CS": 7, | ||||||
|  |         "TFT_DC": 39, | ||||||
|  |         "TFT_RESET": 40, | ||||||
|  |         "TFT_BACKLIGHT": 45, | ||||||
|  |         "LED": 13, | ||||||
|  |         "LED_BUILTIN": 13, | ||||||
|  |     }, | ||||||
|     "adafruit_qtpy_esp32c3": { |     "adafruit_qtpy_esp32c3": { | ||||||
|         "A0": 4, |         "A0": 4, | ||||||
|         "A1": 3, |         "A1": 3, | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| import esphome.codegen as cg | import esphome.codegen as cg | ||||||
| import esphome.config_validation as cv | import esphome.config_validation as cv | ||||||
| from esphome import pins | from esphome import pins | ||||||
| from esphome.components import display, spi | from esphome.components import display, spi, power_supply | ||||||
| from esphome.const import ( | from esphome.const import ( | ||||||
|     CONF_BACKLIGHT_PIN, |     CONF_BACKLIGHT_PIN, | ||||||
|     CONF_DC_PIN, |     CONF_DC_PIN, | ||||||
| @@ -11,6 +11,7 @@ from esphome.const import ( | |||||||
|     CONF_MODEL, |     CONF_MODEL, | ||||||
|     CONF_RESET_PIN, |     CONF_RESET_PIN, | ||||||
|     CONF_WIDTH, |     CONF_WIDTH, | ||||||
|  |     CONF_POWER_SUPPLY, | ||||||
| ) | ) | ||||||
| from . import st7789v_ns | from . import st7789v_ns | ||||||
|  |  | ||||||
| @@ -32,6 +33,7 @@ MODELS = { | |||||||
|     "TTGO_TDISPLAY_135X240": ST7789VModel.ST7789V_MODEL_TTGO_TDISPLAY_135_240, |     "TTGO_TDISPLAY_135X240": ST7789VModel.ST7789V_MODEL_TTGO_TDISPLAY_135_240, | ||||||
|     "ADAFRUIT_FUNHOUSE_240X240": ST7789VModel.ST7789V_MODEL_ADAFRUIT_FUNHOUSE_240_240, |     "ADAFRUIT_FUNHOUSE_240X240": ST7789VModel.ST7789V_MODEL_ADAFRUIT_FUNHOUSE_240_240, | ||||||
|     "ADAFRUIT_RR_280X240": ST7789VModel.ST7789V_MODEL_ADAFRUIT_RR_280_240, |     "ADAFRUIT_RR_280X240": ST7789VModel.ST7789V_MODEL_ADAFRUIT_RR_280_240, | ||||||
|  |     "ADAFRUIT_S2_TFT_FEATHER_240X135": ST7789VModel.ST7789V_MODEL_ADAFRUIT_S2_TFT_FEATHER_240_135, | ||||||
|     "CUSTOM": ST7789VModel.ST7789V_MODEL_CUSTOM, |     "CUSTOM": ST7789VModel.ST7789V_MODEL_CUSTOM, | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -58,6 +60,14 @@ def validate_st7789v(config): | |||||||
|         raise cv.Invalid( |         raise cv.Invalid( | ||||||
|             f'Do not specify {CONF_HEIGHT}, {CONF_WIDTH}, {CONF_OFFSET_HEIGHT} or {CONF_OFFSET_WIDTH} when using {CONF_MODEL} that is not "CUSTOM"' |             f'Do not specify {CONF_HEIGHT}, {CONF_WIDTH}, {CONF_OFFSET_HEIGHT} or {CONF_OFFSET_WIDTH} when using {CONF_MODEL} that is not "CUSTOM"' | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |     if ( | ||||||
|  |         config[CONF_MODEL].upper() == "ADAFRUIT_S2_TFT_FEATHER_240X135" | ||||||
|  |         and CONF_POWER_SUPPLY not in config | ||||||
|  |     ): | ||||||
|  |         raise cv.Invalid( | ||||||
|  |             f'{CONF_POWER_SUPPLY} must be specified when {CONF_MODEL} is "ADAFRUIT_S2_TFT_FEATHER_240X135"' | ||||||
|  |         ) | ||||||
|     return config |     return config | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -69,6 +79,7 @@ CONFIG_SCHEMA = cv.All( | |||||||
|             cv.Required(CONF_RESET_PIN): pins.gpio_output_pin_schema, |             cv.Required(CONF_RESET_PIN): pins.gpio_output_pin_schema, | ||||||
|             cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema, |             cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema, | ||||||
|             cv.Optional(CONF_BACKLIGHT_PIN): pins.gpio_output_pin_schema, |             cv.Optional(CONF_BACKLIGHT_PIN): pins.gpio_output_pin_schema, | ||||||
|  |             cv.Optional(CONF_POWER_SUPPLY): cv.use_id(power_supply.PowerSupply), | ||||||
|             cv.Optional(CONF_EIGHTBITCOLOR, default=False): cv.boolean, |             cv.Optional(CONF_EIGHTBITCOLOR, default=False): cv.boolean, | ||||||
|             cv.Optional(CONF_HEIGHT): cv.int_, |             cv.Optional(CONF_HEIGHT): cv.int_, | ||||||
|             cv.Optional(CONF_WIDTH): cv.int_, |             cv.Optional(CONF_WIDTH): cv.int_, | ||||||
| @@ -113,3 +124,7 @@ async def to_code(config): | |||||||
|             config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void |             config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void | ||||||
|         ) |         ) | ||||||
|         cg.add(var.set_writer(lambda_)) |         cg.add(var.set_writer(lambda_)) | ||||||
|  |  | ||||||
|  |     if CONF_POWER_SUPPLY in config: | ||||||
|  |         ps = await cg.get_variable(config[CONF_POWER_SUPPLY]) | ||||||
|  |         cg.add(var.set_power_supply(ps)) | ||||||
|   | |||||||
| @@ -8,6 +8,10 @@ static const char *const TAG = "st7789v"; | |||||||
|  |  | ||||||
| void ST7789V::setup() { | void ST7789V::setup() { | ||||||
|   ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V..."); |   ESP_LOGCONFIG(TAG, "Setting up SPI ST7789V..."); | ||||||
|  | #ifdef USE_POWER_SUPPLY | ||||||
|  |   this->power_.request(); | ||||||
|  |   // the PowerSupply component takes care of post turn-on delay | ||||||
|  | #endif | ||||||
|   this->spi_setup(); |   this->spi_setup(); | ||||||
|   this->dc_pin_->setup();  // OUTPUT |   this->dc_pin_->setup();  // OUTPUT | ||||||
|  |  | ||||||
| @@ -128,6 +132,9 @@ void ST7789V::dump_config() { | |||||||
|   LOG_PIN("  Reset Pin: ", this->reset_pin_); |   LOG_PIN("  Reset Pin: ", this->reset_pin_); | ||||||
|   LOG_PIN("  B/L Pin: ", this->backlight_pin_); |   LOG_PIN("  B/L Pin: ", this->backlight_pin_); | ||||||
|   LOG_UPDATE_INTERVAL(this); |   LOG_UPDATE_INTERVAL(this); | ||||||
|  | #ifdef USE_POWER_SUPPLY | ||||||
|  |   ESP_LOGCONFIG(TAG, "  Power Supply Configured: yes"); | ||||||
|  | #endif | ||||||
| } | } | ||||||
|  |  | ||||||
| float ST7789V::get_setup_priority() const { return setup_priority::PROCESSOR; } | float ST7789V::get_setup_priority() const { return setup_priority::PROCESSOR; } | ||||||
| @@ -162,6 +169,13 @@ void ST7789V::set_model(ST7789VModel model) { | |||||||
|       this->offset_width_ = 20; |       this->offset_width_ = 20; | ||||||
|       break; |       break; | ||||||
|  |  | ||||||
|  |     case ST7789V_MODEL_ADAFRUIT_S2_TFT_FEATHER_240_135: | ||||||
|  |       this->height_ = 240; | ||||||
|  |       this->width_ = 135; | ||||||
|  |       this->offset_height_ = 52; | ||||||
|  |       this->offset_width_ = 40; | ||||||
|  |       break; | ||||||
|  |  | ||||||
|     default: |     default: | ||||||
|       break; |       break; | ||||||
|   } |   } | ||||||
| @@ -323,6 +337,8 @@ const char *ST7789V::model_str_() { | |||||||
|       return "Adafruit Funhouse 240x240"; |       return "Adafruit Funhouse 240x240"; | ||||||
|     case ST7789V_MODEL_ADAFRUIT_RR_280_240: |     case ST7789V_MODEL_ADAFRUIT_RR_280_240: | ||||||
|       return "Adafruit Round-Rectangular 280x240"; |       return "Adafruit Round-Rectangular 280x240"; | ||||||
|  |     case ST7789V_MODEL_ADAFRUIT_S2_TFT_FEATHER_240_135: | ||||||
|  |       return "Adafruit ESP32-S2 TFT Feather"; | ||||||
|     default: |     default: | ||||||
|       return "Custom"; |       return "Custom"; | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -3,6 +3,9 @@ | |||||||
| #include "esphome/core/component.h" | #include "esphome/core/component.h" | ||||||
| #include "esphome/components/spi/spi.h" | #include "esphome/components/spi/spi.h" | ||||||
| #include "esphome/components/display/display_buffer.h" | #include "esphome/components/display/display_buffer.h" | ||||||
|  | #ifdef USE_POWER_SUPPLY | ||||||
|  | #include "esphome/components/power_supply/power_supply.h" | ||||||
|  | #endif | ||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace st7789v { | namespace st7789v { | ||||||
| @@ -11,6 +14,7 @@ enum ST7789VModel { | |||||||
|   ST7789V_MODEL_TTGO_TDISPLAY_135_240, |   ST7789V_MODEL_TTGO_TDISPLAY_135_240, | ||||||
|   ST7789V_MODEL_ADAFRUIT_FUNHOUSE_240_240, |   ST7789V_MODEL_ADAFRUIT_FUNHOUSE_240_240, | ||||||
|   ST7789V_MODEL_ADAFRUIT_RR_280_240, |   ST7789V_MODEL_ADAFRUIT_RR_280_240, | ||||||
|  |   ST7789V_MODEL_ADAFRUIT_S2_TFT_FEATHER_240_135, | ||||||
|   ST7789V_MODEL_CUSTOM |   ST7789V_MODEL_CUSTOM | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -120,6 +124,9 @@ class ST7789V : public PollingComponent, | |||||||
|   void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; } |   void set_dc_pin(GPIOPin *dc_pin) { this->dc_pin_ = dc_pin; } | ||||||
|   void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; } |   void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; } | ||||||
|   void set_backlight_pin(GPIOPin *backlight_pin) { this->backlight_pin_ = backlight_pin; } |   void set_backlight_pin(GPIOPin *backlight_pin) { this->backlight_pin_ = backlight_pin; } | ||||||
|  | #ifdef USE_POWER_SUPPLY | ||||||
|  |   void set_power_supply(power_supply::PowerSupply *power_supply) { this->power_.set_parent(power_supply); } | ||||||
|  | #endif | ||||||
|  |  | ||||||
|   void set_eightbitcolor(bool eightbitcolor) { this->eightbitcolor_ = eightbitcolor; } |   void set_eightbitcolor(bool eightbitcolor) { this->eightbitcolor_ = eightbitcolor; } | ||||||
|   void set_height(uint32_t height) { this->height_ = height; } |   void set_height(uint32_t height) { this->height_ = height; } | ||||||
| @@ -143,6 +150,9 @@ class ST7789V : public PollingComponent, | |||||||
|   GPIOPin *dc_pin_{nullptr}; |   GPIOPin *dc_pin_{nullptr}; | ||||||
|   GPIOPin *reset_pin_{nullptr}; |   GPIOPin *reset_pin_{nullptr}; | ||||||
|   GPIOPin *backlight_pin_{nullptr}; |   GPIOPin *backlight_pin_{nullptr}; | ||||||
|  | #ifdef USE_POWER_SUPPLY | ||||||
|  |   power_supply::PowerSupplyRequester power_; | ||||||
|  | #endif | ||||||
|  |  | ||||||
|   bool eightbitcolor_{false}; |   bool eightbitcolor_{false}; | ||||||
|   uint16_t height_{0}; |   uint16_t height_{0}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user