Pass RST pin through I2C.

This commit is contained in:
Shaun Reed 2025-02-15 18:16:25 -05:00
parent 6493988324
commit 8636de8f2f
5 changed files with 31 additions and 20 deletions

View File

@ -12,7 +12,7 @@ I2C i2c(PIN_SDA, PIN_SCL, PIN_RST);
void setup() void setup()
{ {
SSD1306 ssd1306(i2c.i2c_bus_); SSD1306 ssd1306(i2c);
Display d(&ssd1306); Display d(&ssd1306);
d.set_text("Test test 12345678910", d.set_text("Test test 12345678910",

View File

@ -5,10 +5,9 @@ Panel::Panel(IPanelDevice *device) :
device_(device), device_(device),
io_handle_(nullptr), io_handle_(nullptr),
esp_panel_(nullptr), esp_panel_(nullptr),
// According to SSD1306 datasheet
panel_config_( panel_config_(
(esp_lcd_panel_dev_config_t) { (esp_lcd_panel_dev_config_t) {
.reset_gpio_num = -1, // TODO: PIN_RST, .reset_gpio_num = device_->rst_num_,
.bits_per_pixel = 1, .bits_per_pixel = 1,
// .vendor_config should be set in IPanelDevice::init_panel override // .vendor_config should be set in IPanelDevice::init_panel override
} }

View File

@ -15,9 +15,23 @@
class IPanelDevice { class IPanelDevice {
public: public:
explicit IPanelDevice(i2c_master_bus_handle_t i2c, explicit IPanelDevice(I2C &i2c,
esp_lcd_panel_io_i2c_config_t io_config) : esp_lcd_panel_io_i2c_config_t config,
i2c_bus_(i2c), 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) { } io_config_(io_config) { }
virtual ~IPanelDevice() = default; virtual ~IPanelDevice() = default;
@ -45,6 +59,7 @@ public:
int32_t width_; int32_t width_;
int32_t height_; int32_t height_;
int rst_num_;
// LVGL reserves 2x4 bytes in the buffer to be used as a palette. // LVGL reserves 2x4 bytes in the buffer to be used as a palette.
size_t lv_buf_size_; size_t lv_buf_size_;

View File

@ -4,7 +4,7 @@
// To use LV_COLOR_FORMAT_I1 we need an extra buffer to hold the converted data. // 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]; 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, esp_lcd_panel_ssd1306_config_t config,
int width, int width,
int height) : int height) :
@ -16,14 +16,12 @@ SSD1306::SSD1306(i2c_master_bus_handle_t i2c,
.lcd_cmd_bits = LCD_CMD_BITS, .lcd_cmd_bits = LCD_CMD_BITS,
.lcd_param_bits = LCD_CMD_BITS, .lcd_param_bits = LCD_CMD_BITS,
.scl_speed_hz = LCD_PIXEL_CLOCK_HZ, .scl_speed_hz = LCD_PIXEL_CLOCK_HZ,
} },
width,
height
), ),
ssd1306_config_(config) 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, void SSD1306::init_panel(esp_lcd_panel_dev_config_t &config,
esp_lcd_panel_io_handle_t io, esp_lcd_panel_io_handle_t io,

View File

@ -17,18 +17,17 @@
#define LCD_CMD_BITS 8 #define LCD_CMD_BITS 8
#define LCD_PARAM_BITS 8 #define LCD_PARAM_BITS 8
#define PIN_RST -1
class SSD1306 : public IPanelDevice { class SSD1306 : public IPanelDevice {
public: public:
// Constructors allow overriding ssd1306 config. // Constructors allow overriding ssd1306 config.
explicit SSD1306(i2c_master_bus_handle_t i2c) : explicit SSD1306(I2C &i2c) :
SSD1306(i2c, {.height = SCREEN_HEIGHT}) { } SSD1306(i2c, {.height = SCREEN_HEIGHT}) { }
explicit SSD1306(i2c_master_bus_handle_t i2c, SSD1306(I2C &i2c,
esp_lcd_panel_ssd1306_config_t config, esp_lcd_panel_ssd1306_config_t config,
int width = SCREEN_WIDTH, int width = SCREEN_WIDTH,
int height = SCREEN_HEIGHT); int height = SCREEN_HEIGHT
);
virtual ~SSD1306() = default; virtual ~SSD1306() = default;