Pass RST pin through I2C.
This commit is contained in:
		
							parent
							
								
									6493988324
								
							
						
					
					
						commit
						8636de8f2f
					
				| @ -12,7 +12,7 @@ I2C i2c(PIN_SDA, PIN_SCL, PIN_RST); | ||||
| 
 | ||||
| void setup() | ||||
| { | ||||
|   SSD1306 ssd1306(i2c.i2c_bus_); | ||||
|   SSD1306 ssd1306(i2c); | ||||
|   Display d(&ssd1306); | ||||
| 
 | ||||
|   d.set_text("Test test 12345678910", | ||||
|  | ||||
| @ -5,10 +5,9 @@ Panel::Panel(IPanelDevice *device) : | ||||
|     device_(device), | ||||
|     io_handle_(nullptr), | ||||
|     esp_panel_(nullptr), | ||||
|     // According to SSD1306 datasheet
 | ||||
|     panel_config_( | ||||
|         (esp_lcd_panel_dev_config_t) { | ||||
|             .reset_gpio_num = -1, // TODO: PIN_RST,
 | ||||
|             .reset_gpio_num = device_->rst_num_, | ||||
|             .bits_per_pixel = 1, | ||||
|             // .vendor_config should be set in IPanelDevice::init_panel override
 | ||||
|         } | ||||
|  | ||||
| @ -15,9 +15,23 @@ | ||||
| 
 | ||||
| class IPanelDevice { | ||||
| public: | ||||
|   explicit IPanelDevice(i2c_master_bus_handle_t i2c, | ||||
|                         esp_lcd_panel_io_i2c_config_t io_config) : | ||||
|       i2c_bus_(i2c), | ||||
|   explicit IPanelDevice(I2C &i2c, | ||||
|                         esp_lcd_panel_io_i2c_config_t config, | ||||
|                         int width, | ||||
|                         int height) : | ||||
|       IPanelDevice(i2c, config, width, height, | ||||
|                    width * height / 8 + LVGL_PALETTE_SIZE) { } | ||||
| 
 | ||||
|   explicit IPanelDevice(I2C &i2c, | ||||
|                         esp_lcd_panel_io_i2c_config_t io_config, | ||||
|                         int width, | ||||
|                         int height, | ||||
|                         size_t draw_buf_size) : | ||||
|       width_(width), | ||||
|       height_(height), | ||||
|       rst_num_(i2c.rst_num_), | ||||
|       lv_buf_size_(draw_buf_size), | ||||
|       i2c_bus_(i2c.i2c_bus_), | ||||
|       io_config_(io_config) { } | ||||
| 
 | ||||
|   virtual ~IPanelDevice() = default; | ||||
| @ -45,6 +59,7 @@ public: | ||||
| 
 | ||||
|   int32_t width_; | ||||
|   int32_t height_; | ||||
|   int rst_num_; | ||||
| 
 | ||||
|   // LVGL reserves 2x4 bytes in the buffer to be used as a palette.
 | ||||
|   size_t lv_buf_size_; | ||||
|  | ||||
| @ -4,7 +4,7 @@ | ||||
| // To use LV_COLOR_FORMAT_I1 we need an extra buffer to hold the converted data.
 | ||||
| uint8_t SSD1306::oled_buffer_[LCD_H_RES * LCD_V_RES / 8]; | ||||
| 
 | ||||
| SSD1306::SSD1306(i2c_master_bus_handle_t i2c, | ||||
| SSD1306::SSD1306(I2C& i2c, | ||||
|                  esp_lcd_panel_ssd1306_config_t config, | ||||
|                  int width, | ||||
|                  int height) : | ||||
| @ -16,14 +16,12 @@ SSD1306::SSD1306(i2c_master_bus_handle_t i2c, | ||||
|                      .lcd_cmd_bits = LCD_CMD_BITS, | ||||
|                      .lcd_param_bits = LCD_CMD_BITS, | ||||
|                      .scl_speed_hz = LCD_PIXEL_CLOCK_HZ, | ||||
|                  } | ||||
|                  }, | ||||
|                  width, | ||||
|                  height | ||||
|     ), | ||||
|     ssd1306_config_(config) | ||||
| { | ||||
|   this->width_ = width; | ||||
|   this->height_ = height; | ||||
|   this->lv_buf_size_ = width_ * height_ / 8 + LVGL_PALETTE_SIZE; | ||||
| } | ||||
| { } | ||||
| 
 | ||||
| void SSD1306::init_panel(esp_lcd_panel_dev_config_t &config, | ||||
|                          esp_lcd_panel_io_handle_t io, | ||||
|  | ||||
| @ -17,18 +17,17 @@ | ||||
| #define LCD_CMD_BITS           8 | ||||
| #define LCD_PARAM_BITS         8 | ||||
| 
 | ||||
| #define PIN_RST                -1 | ||||
| 
 | ||||
| class SSD1306 : public IPanelDevice { | ||||
| public: | ||||
|   // Constructors allow overriding ssd1306 config.
 | ||||
|   explicit SSD1306(i2c_master_bus_handle_t i2c) : | ||||
|   explicit SSD1306(I2C &i2c) : | ||||
|       SSD1306(i2c, {.height = SCREEN_HEIGHT}) { } | ||||
| 
 | ||||
|   explicit SSD1306(i2c_master_bus_handle_t i2c, | ||||
|   SSD1306(I2C &i2c, | ||||
|           esp_lcd_panel_ssd1306_config_t config, | ||||
|           int width = SCREEN_WIDTH, | ||||
|                    int height = SCREEN_HEIGHT); | ||||
|           int height = SCREEN_HEIGHT | ||||
|   ); | ||||
| 
 | ||||
|   virtual ~SSD1306() = default; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user