diff --git a/esp/cpp/07_lcd-panel/main/display.cpp b/esp/cpp/07_lcd-panel/main/display.cpp index 8f57dda..0d83b88 100644 --- a/esp/cpp/07_lcd-panel/main/display.cpp +++ b/esp/cpp/07_lcd-panel/main/display.cpp @@ -26,29 +26,28 @@ Display::Display(const I2C &i2c) : } // Create a lvgl display. - // TODO: Use PanelDevice functions + // TODO: Use PanelDevice functions to get SSD1306 specs display_ = lv_display_create(LCD_H_RES, LCD_V_RES); // associate the i2c panel handle to the display lv_display_set_user_data(display_, panel_.get()); + // Create draw buffer. ESP_LOGI(TAG, "Allocate separate LVGL draw buffers"); - // TODO: Use PanelDevice functions - size_t draw_buffer_sz = LCD_H_RES * LCD_V_RES / 8 + LVGL_PALETTE_SIZE; - buf_ = heap_caps_calloc(1, draw_buffer_sz, - MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + // TODO: Use PanelDevice functions to get SSD1306 specs + buf_size_ = LCD_H_RES * LCD_V_RES / 8 + LVGL_PALETTE_SIZE; + buf_ = heap_caps_calloc(1, buf_size_, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); assert(buf_); // LVGL9 suooprt new monochromatic format. lv_display_set_color_format(display_, LV_COLOR_FORMAT_I1); // Initialize LVGL draw buffers. - lv_display_set_buffers(display_, buf_, nullptr, draw_buffer_sz, + lv_display_set_buffers(display_, buf_, nullptr, buf_size_, LV_DISPLAY_RENDER_MODE_FULL); lv_display_set_rotation(display_, LV_DISPLAY_ROTATION_0); // Set callback which can copy the rendered image to an area of the display. lv_display_set_flush_cb(display_, Display::lvgl_flush_cb); - ESP_LOGI(TAG, - "Register io panel event callback for LVGL flush ready notification"); + ESP_LOGI(TAG, "Register io panel callback for LVGL flush ready notification"); const esp_lcd_panel_io_callbacks_t cbs = { .on_color_trans_done = Display::lvgl_flush_ready, }; @@ -189,19 +188,21 @@ I2C::I2C() : Panel::Panel(i2c_master_bus_handle_t i2c) : io_handle_(nullptr), panel_(nullptr), + // According to SSD1306 datasheet panel_config_( (esp_lcd_panel_dev_config_t) { .reset_gpio_num = PIN_RST, .bits_per_pixel = 1, } ), + // According to SSD1306 datasheet io_config_( (esp_lcd_panel_io_i2c_config_t) { .dev_addr = I2C_HW_ADDR, - .control_phase_bytes = 1, // According to SSD1306 datasheet - .dc_bit_offset = 6, // According to SSD1306 datasheet - .lcd_cmd_bits = LCD_CMD_BITS, // According to SSD1306 datasheet - .lcd_param_bits = LCD_CMD_BITS, // According to SSD1306 datasheet + .control_phase_bytes = 1, + .dc_bit_offset = 6, + .lcd_cmd_bits = LCD_CMD_BITS, + .lcd_param_bits = LCD_CMD_BITS, .scl_speed_hz = LCD_PIXEL_CLOCK_HZ, } ) diff --git a/esp/cpp/07_lcd-panel/main/display.h b/esp/cpp/07_lcd-panel/main/display.h index 8ada444..6e5c968 100644 --- a/esp/cpp/07_lcd-panel/main/display.h +++ b/esp/cpp/07_lcd-panel/main/display.h @@ -106,8 +106,15 @@ private: lv_display_t *display_; + // Size of the draw buffer associated with the lv_display_t. + size_t buf_size_; + + // Draw buffer associated with the lv_display_t. void *buf_; + // Objects stored in the screen associated with this display. + // @sa Display::set_text + // @sa lv_display_get_screen_active std::unordered_map objects_; }; diff --git a/esp/cpp/07_lcd-panel/main/panel_device.h b/esp/cpp/07_lcd-panel/main/panel_device.h index b7220f0..7f084d3 100644 --- a/esp/cpp/07_lcd-panel/main/panel_device.h +++ b/esp/cpp/07_lcd-panel/main/panel_device.h @@ -9,11 +9,11 @@ #define LVGL_PALETTE_SIZE 8 template -class PanelDevice { +class PanelDeviceInterface { public: - PanelDevice(size_t width, size_t height) : width_(width), height_(height) { } + PanelDeviceInterface(size_t width, size_t height) : width_(width), height_(height) { } - ~PanelDevice() = default; + ~PanelDeviceInterface() = default; [[nodiscard]] size_t get_width() const { return width_; } @@ -47,9 +47,9 @@ protected: }; template -void PanelDevice::create_panel(esp_lcd_panel_dev_config_t &config, - esp_lcd_panel_io_handle_t io, - esp_lcd_panel_handle_t &panel) +void PanelDeviceInterface::create_panel(esp_lcd_panel_dev_config_t &config, + esp_lcd_panel_io_handle_t io, + esp_lcd_panel_handle_t &panel) { // If the passed handle is already allocated, delete it. if (panel != nullptr) { diff --git a/esp/cpp/07_lcd-panel/main/ssd1306.cpp b/esp/cpp/07_lcd-panel/main/ssd1306.cpp index 2a114b2..cf87f62 100644 --- a/esp/cpp/07_lcd-panel/main/ssd1306.cpp +++ b/esp/cpp/07_lcd-panel/main/ssd1306.cpp @@ -7,7 +7,7 @@ uint8_t SSD1306::oled_buffer_[LCD_H_RES * LCD_V_RES / 8]; SSD1306::SSD1306(esp_lcd_panel_ssd1306_config_t ssd_config, int width, int height) : - PanelDevice(width, height) + PanelDeviceInterface(width, height) { vendor_config_ = ssd_config; } diff --git a/esp/cpp/07_lcd-panel/main/ssd1306.h b/esp/cpp/07_lcd-panel/main/ssd1306.h index 85d4895..4cd250d 100644 --- a/esp/cpp/07_lcd-panel/main/ssd1306.h +++ b/esp/cpp/07_lcd-panel/main/ssd1306.h @@ -22,7 +22,7 @@ #define PIN_SCL GPIO_NUM_22 #define PIN_RST -1 -class SSD1306 : public PanelDevice { +class SSD1306 : public PanelDeviceInterface { public: explicit SSD1306(esp_lcd_panel_ssd1306_config_t ssd_config, int width = SCREEN_WIDTH, int height = SCREEN_HEIGHT);