From 577428fef96c14abfbe3a8d05646d98b4cf7ee2e Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Sat, 1 Nov 2025 16:58:50 -0400 Subject: [PATCH] Pull in display code and test. --- esp/cpp/08_dht11-lcd/main/CMakeLists.txt | 4 +- esp/cpp/08_dht11-lcd/main/display.cpp | 56 +++ esp/cpp/08_dht11-lcd/main/display.h | 114 +++++ esp/cpp/08_dht11-lcd/main/idf_component.yml | 2 + esp/cpp/08_dht11-lcd/main/main.cpp | 23 +- esp/cpp/08_dht11-lcd/main/panel.h | 87 ++++ esp/cpp/08_dht11-lcd/main/panel_device.cpp | 145 +++++++ esp/cpp/08_dht11-lcd/main/panel_device.h | 435 ++++++++++++++++++++ esp/cpp/08_dht11-lcd/main/scoped_lock.cpp | 12 + esp/cpp/08_dht11-lcd/main/scoped_lock.h | 28 ++ esp/cpp/08_dht11-lcd/main/ssd1306.h | 106 +++++ esp/cpp/08_dht11-lcd/main/time_keeper.h | 161 ++++++++ esp/cpp/08_dht11-lcd/sdkconfig | 377 +++++++++++++++++ esp/cpp/components/i2c/include/i2c.h | 13 +- 14 files changed, 1553 insertions(+), 10 deletions(-) create mode 100644 esp/cpp/08_dht11-lcd/main/display.cpp create mode 100644 esp/cpp/08_dht11-lcd/main/display.h create mode 100644 esp/cpp/08_dht11-lcd/main/panel.h create mode 100644 esp/cpp/08_dht11-lcd/main/panel_device.cpp create mode 100644 esp/cpp/08_dht11-lcd/main/panel_device.h create mode 100644 esp/cpp/08_dht11-lcd/main/scoped_lock.cpp create mode 100644 esp/cpp/08_dht11-lcd/main/scoped_lock.h create mode 100644 esp/cpp/08_dht11-lcd/main/ssd1306.h create mode 100644 esp/cpp/08_dht11-lcd/main/time_keeper.h diff --git a/esp/cpp/08_dht11-lcd/main/CMakeLists.txt b/esp/cpp/08_dht11-lcd/main/CMakeLists.txt index 1fe236e..39179ac 100644 --- a/esp/cpp/08_dht11-lcd/main/CMakeLists.txt +++ b/esp/cpp/08_dht11-lcd/main/CMakeLists.txt @@ -1,6 +1,6 @@ idf_component_register( SRCS - main.cpp - main.h + main.cpp display.cpp panel_device.cpp scoped_lock.cpp + main.h display.h panel.h panel_device.h scoped_lock.h time_keeper.h ssd1306.h INCLUDE_DIRS . ) diff --git a/esp/cpp/08_dht11-lcd/main/display.cpp b/esp/cpp/08_dht11-lcd/main/display.cpp new file mode 100644 index 0000000..0177461 --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/display.cpp @@ -0,0 +1,56 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#include + +#include "display.h" + +// Static TimeKeeper for managing ESP timers across all displays. +TimeKeeper Display::timers_; + +Display::Display(IPanelDevice &device) : + panel_(device) +{ + if (!lv_is_initialized()) { + ESP_LOGI(TAG, "Initialize LVGL"); + lv_init(); + } + + ESP_LOGI(TAG, "Creating LVGL display"); + lv_display_ = panel_.device_->create_display(); + // associate the i2c panel handle to the display + lv_display_set_user_data(lv_display_, panel_.esp_panel_); + + panel_.register_display_callbacks(lv_display_); +} + +void Display::set_text(const char *text, + const char *name, + lv_label_long_mode_t long_mode, + lv_align_t align) +{ + // Lock the mutex due to the LVGL APIs are not thread-safe. + ScopedLock lock; + + ESP_LOGI(TAG, "Display LVGL Scroll Text"); + lv_obj_t *scr = lv_display_get_screen_active(lv_display_); + + // Create the label if it's `name` doesn't already exist in the map keys. + if (!lv_objects_.count(name)) { + lv_objects_[name] = lv_label_create(scr); + } + auto obj = lv_objects_[name]; + + // Set text and long mode. + lv_label_set_long_mode(obj, long_mode); + lv_label_set_text(obj, text); + + // Set the size of the screen. + // If you use rotation 90 or 270 use lv_display_get_vertical_resolution. + lv_obj_set_width(obj, lv_display_get_horizontal_resolution(lv_display_)); + lv_obj_align(obj, align, 0, 0); +} diff --git a/esp/cpp/08_dht11-lcd/main/display.h b/esp/cpp/08_dht11-lcd/main/display.h new file mode 100644 index 0000000..3c110a2 --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/display.h @@ -0,0 +1,114 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#ifndef DISPLAY_H +#define DISPLAY_H + +#include + +#include + +#include "time_keeper.h" +#include "panel.h" +#include "scoped_lock.h" + +/** + * Encapsulates lv_display handle and related LVGL operations. + * Contains helper methods that wrap basic LVGL operations such as drawing text. + * The underlying lv_display can be obtained for manual LVGL operations. + * @sa ScopedLock + * @sa Display::get() + */ +class Display { +public: + /** + * Construct a new Display using an object that implements IPanelDevice. + * + * @param device An object that implements the IPanelDevice interface. + */ + explicit Display(IPanelDevice &device); + + ~Display() = default; + + Display(const Display &) = delete; + + Display(Display &) = delete; + + Display &operator=(Display &) = delete; + + using lv_display_handle_t = lv_display_t *; + + // + // GETTERS + + /** + * Getter for accessing LVGL display handle. + * + * @sa ScopedLock for calling custom LVGL API's not implemented by Display. + */ + [[nodiscard]] inline lv_display_handle_t get() const { return lv_display_; } + + /** + * Getter for accessing LVGL display handle. + * + * @sa ScopedLock for calling custom LVGL API's not implemented by Display. + */ + [[nodiscard]] inline lv_display_handle_t get() { return lv_display_; } + + /// Dereference operator for accessing LVGL display handle. + [[nodiscard]] inline lv_display_handle_t operator*() const { return get(); } + + /// Dereference operator for accessing LVGL display handle. + [[nodiscard]] inline lv_display_handle_t operator*() { return get(); } + + // + // LVGL OPERATIONS + + /** + * Create a LVGL label with some given text on the current display. + * The name of the object can be reused to change text on this label later. + * + * @param text Text to write to the display. + * @param name Name for the LVGL label object associated with this text. + * @param long_mode LVGL long mode for text wider than the current display. + * @param align LVGL alignment to use for placing the label on the display. + */ + void set_text(const char *text, + const char *name, + lv_label_long_mode_t long_mode = LV_LABEL_LONG_SCROLL_CIRCULAR, + lv_align_t align = LV_ALIGN_TOP_MID); + + // + // PUBLIC STATIC MEMBERS + + /// Public static TimeKeeper for managing ESP timers across all displays. + static TimeKeeper timers_; + +private: + + // + // PRIVATE MEMBERS + + /// Panel associated with this Display. + Panel panel_; + + /// LVGL display handle. + lv_display_handle_t lv_display_; + + /** + * LVGL object handles stored in the LVGL screen associated with this Display. + * + * @sa Display::set_text + * @sa lv_display_get_screen_active + */ + std::unordered_map lv_objects_; + + /// Tag used for ESP logging. + constexpr static const char *TAG = "Display"; +}; + +#endif // DISPLAY_H diff --git a/esp/cpp/08_dht11-lcd/main/idf_component.yml b/esp/cpp/08_dht11-lcd/main/idf_component.yml index 6a93930..aaca421 100644 --- a/esp/cpp/08_dht11-lcd/main/idf_component.yml +++ b/esp/cpp/08_dht11-lcd/main/idf_component.yml @@ -1,5 +1,7 @@ ## IDF Component Manager Manifest File dependencies: idf: '>=5.3.0' + lvgl/lvgl: "9.2.0" + esp_lcd_sh1107: "^1" i2c: path: ../../components/i2c \ No newline at end of file diff --git a/esp/cpp/08_dht11-lcd/main/main.cpp b/esp/cpp/08_dht11-lcd/main/main.cpp index b23df53..849513a 100644 --- a/esp/cpp/08_dht11-lcd/main/main.cpp +++ b/esp/cpp/08_dht11-lcd/main/main.cpp @@ -7,6 +7,8 @@ */ #include "i2c.h" +#include "display.h" +#include "ssd1306.h" // Pin may vary based on your schematic. #define PIN_SDA GPIO_NUM_21 @@ -15,6 +17,25 @@ extern "C" void app_main(void) { - init_i2c(PIN_SDA, PIN_SCL); + I2C_init(PIN_SDA, PIN_SCL); + auto i2c = I2C_get(); + SSD1306 ssd1306(i2c); + Display d(ssd1306); + d.set_text("Test test 12345678910", + "test-text1", + LV_LABEL_LONG_SCROLL, + LV_ALIGN_CENTER); + + d.set_text("Test test changing text", + "test-text1", + LV_LABEL_LONG_SCROLL, + LV_ALIGN_CENTER); + + d.set_text("Hello hello hello hello hello hello hello hello!", "test-text2"); + + d.set_text("A random sentence with no meaning at all.", + "test-text3", + LV_LABEL_LONG_CLIP, + LV_ALIGN_BOTTOM_MID); } diff --git a/esp/cpp/08_dht11-lcd/main/panel.h b/esp/cpp/08_dht11-lcd/main/panel.h new file mode 100644 index 0000000..595e095 --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/panel.h @@ -0,0 +1,87 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#ifndef PANEL_H +#define PANEL_H + +#include "panel_device.h" + +/** + * Encapsulates esp_lcd_panel handles and operations. + * The only exception is esp_lcd_panel_io_i2c_config_t owned by IPanelDevice. + * This structure requires details specific to the implementing device. + * + * Panel is an implementation detail of Display, not meant to be used directly. + */ +struct Panel { + /** + * Construct a new Panel using an object that implements IPanelDevice. + * + * @param device An object that implements the IPanelDevice interface. + */ + explicit Panel(IPanelDevice &device) : + device_(&device), + esp_io_(nullptr), + esp_panel_(nullptr), + esp_panel_config_( + (esp_lcd_panel_dev_config_t) { + .reset_gpio_num = static_cast(device_->rst_num_), + .bits_per_pixel = 1, + .vendor_config = device_->vendor_config(), + } + ) + { + esp_io_ = device_->create_io_handle(); + + device_->create_panel(esp_panel_config_, esp_io_, esp_panel_); + + ESP_LOGI(TAG, "Resetting panel display"); + ESP_ERROR_CHECK(esp_lcd_panel_reset(esp_panel_)); + ESP_LOGI(TAG, "Initializing panel display"); + ESP_ERROR_CHECK(esp_lcd_panel_init(esp_panel_)); + ESP_LOGI(TAG, "Turning on panel display"); + ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(esp_panel_, true)); + } + + ~Panel() = default; + + // + // PUBLIC MEMBERS + + /// Pointer to object using known interface for IPanelDevice. + IPanelDevice *device_; + + /// ESP LCD panel IO handle. + esp_lcd_panel_io_handle_t esp_io_; + + /// ESP LCD panel handle. + esp_lcd_panel_handle_t esp_panel_; + + /// ESP LCD panel configuration structure. + esp_lcd_panel_dev_config_t esp_panel_config_; + + /** + * Registers LVGL draw buffers and callbacks for rendering the display. + * + * @param display_handle Pointer to the LVGL display to use for rendering. + */ + inline void register_display_callbacks(lv_display_t *display_handle) const + { + device_->register_rendering_data(display_handle, esp_io_); + device_->register_lvgl_tick_timer(); + } + +private: + + // + // PRIVATE MEMBERS + + /// Tag used for ESP logging. + constexpr static const char *TAG = "Panel"; +}; + +#endif //PANEL_H diff --git a/esp/cpp/08_dht11-lcd/main/panel_device.cpp b/esp/cpp/08_dht11-lcd/main/panel_device.cpp new file mode 100644 index 0000000..a78c2bb --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/panel_device.cpp @@ -0,0 +1,145 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#include "panel_device.h" +#include "display.h" + +bool IPanelDevice::lvgl_flush_ready_cb(esp_lcd_panel_io_handle_t, + esp_lcd_panel_io_event_data_t *, + void *user_ctx) +{ + auto *disp = (lv_display_t *) user_ctx; + lv_display_flush_ready(disp); + return false; +} + +void IPanelDevice::lvgl_flush_cb(lv_display_t *display, const lv_area_t *area, + uint8_t *px_map) // NOLINT(*-non-const-parameter) +{ + auto panel_handle = + (esp_lcd_panel_handle_t) lv_display_get_user_data(display); + + // Necessary because LVGL reserves 2x4 bytes in the buffer for a palette. + // Since we are monochrome, we don't need these additional bytes. + // For more information about the monochrome, please refer to: + // https://docs.lvgl.io/9.2/porting/display.html#monochrome-displays + // Skip the palette here. + px_map += LVGL_PALETTE_SIZE; + + uint16_t hor_res = lv_display_get_physical_horizontal_resolution(display); + int32_t x1 = area->x1; + int32_t x2 = area->x2; + int32_t y1 = area->y1; + int32_t y2 = area->y2; + + + // As of 03/01/2025 master branch of LVGL contains this helper for the same. + // https://docs.lvgl.io/master/API/draw/sw/lv_draw_sw_utils.html + // lv_draw_sw_i1_convert_to_vtiled() + for (int32_t y = y1; y <= y2; y++) { + for (int32_t x = x1; x <= x2; x++) { + // Get the byte offset of the pixel coordinates using horizontal-mapping. + int h_offset = Pixel::horizontal_byte_offset(x, y, hor_res); + // True if the pixel is lit, else false. + bool chroma_color = px_map[h_offset] & Pixel::msb_mask(x); + + // We need an additional buffer for transposing the pixel data to the + // vertical format required by the display driver. + uint8_t *buf = IPanelDevice::get_additional_draw_buffer(); + // Move to the position in the auxillary buffer where the pixel is stored. + buf += Pixel::vertical_byte_offset(x, y, hor_res); + + // Write the single bit to the monochrome display mapped vertically. + // Take the Least Significant Bit mask of the Y coordinate to select the + // bit representing a pixel at position y in a vertically-mapped display. + if (chroma_color) { + // Set the vertically-mapped pixel to on. + *buf &= ~Pixel::lsb_mask(y); + } else { + // Set the vertically-mapped pixel to off. + *buf |= Pixel::lsb_mask(y); + } + } + } + // Pass the draw buffer to the driver. + ESP_ERROR_CHECK( + esp_lcd_panel_draw_bitmap(panel_handle, x1, y1, x2 + 1, y2 + 1, + IPanelDevice::get_additional_draw_buffer())); +} + +void IPanelDevice::lvgl_increase_tick_cb(void *) +{ + // Tell LVGL how many milliseconds has elapsed + lv_tick_inc(LVGL_TICK_PERIOD_MS); +} + +[[noreturn]] void IPanelDevice::lvgl_port_task(void *) +{ + // Optionally initialize some LVGL objects here before entering loop below. + + ESP_LOGI(TAG, "Starting LVGL task"); + for (uint32_t time_to_next_ms = 0; true; usleep(1000 * time_to_next_ms)) { + // Obtain LVGL API lock before calling any LVGL methods. + ScopedLock lock; + + // Optionally handle LVGL input or event logic here. + + // Update LVGL periodic timers. + time_to_next_ms = lv_timer_handler(); + } +} + +void IPanelDevice::register_rendering_data(lv_display_t *display_handle, + esp_lcd_panel_io_handle_t io_handle) +{ + // Create draw buffer. + ESP_LOGI(TAG, "Allocate separate LVGL draw buffers"); + lv_buf_ = heap_caps_calloc(1, lv_buf_size_, + MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + assert(lv_buf_); + + ESP_LOGI(TAG, "Set LVGL draw buffers"); + // Color format must be set first, LVGL9 support new monochromatic format. + lv_display_set_color_format(display_handle, LV_COLOR_FORMAT_I1); + lv_display_set_buffers(display_handle, lv_buf_, nullptr, + lv_buf_size_, + LV_DISPLAY_RENDER_MODE_FULL); + lv_display_set_rotation(display_handle, LV_DISPLAY_ROTATION_0); + + ESP_LOGI(TAG, "Set LVGL callback for flushing to the display"); + lv_display_set_flush_cb(display_handle, IPanelDevice::lvgl_flush_cb); + + ESP_LOGI(TAG, "Register io panel callback for LVGL flush ready notification"); + const esp_lcd_panel_io_callbacks_t cbs = { + .on_color_trans_done = IPanelDevice::lvgl_flush_ready_cb, + }; + ESP_ERROR_CHECK( + esp_lcd_panel_io_register_event_callbacks(io_handle, &cbs, + display_handle)); +} + +void IPanelDevice::register_lvgl_tick_timer() +{ + ESP_LOGI(TAG, "Use esp_timer to increase LVGL tick"); + const esp_timer_create_args_t esp_timer_args = { + .callback = &IPanelDevice::lvgl_increase_tick_cb, + // Data to pass to the IPanelDevice::lvgl_port_task callback. + .arg = nullptr, + .name = "lvgl_tick", + }; + Display::timers_.start_new_timer_periodic(esp_timer_args, + LVGL_TICK_PERIOD_MS * 1000); + + // LVGL requires a FreeRTOS task for running it's event loop. + // The lvgl_port_task callback can update the UI or handle input logic. + // For this basic example we don't do either of these things. + ESP_LOGI(TAG, "Create LVGL FreeRTOS task"); + // Optionally set user data to pass to LVGL's FreeRTOS task callback here. + void *user_data = nullptr; + xTaskCreate(lvgl_port_task, "LVGL", LVGL_TASK_STACK_SIZE, + user_data, LVGL_TASK_PRIORITY, nullptr); +} diff --git a/esp/cpp/08_dht11-lcd/main/panel_device.h b/esp/cpp/08_dht11-lcd/main/panel_device.h new file mode 100644 index 0000000..aa3e9b0 --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/panel_device.h @@ -0,0 +1,435 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#ifndef PANEL_DEVICE_H +#define PANEL_DEVICE_H + +#include +#include +#include +#include + +#include + +#include "i2c.h" + +// LVGL reserves 2x4 bytes in the buffer to be used as a palette. +// This additional space must be added to the IPanelDevice::buf_size_. +#define LVGL_PALETTE_SIZE 8 +#define LVGL_TICK_PERIOD_MS 5 +#define LVGL_TASK_STACK_SIZE (4 * 1024) +#define LVGL_TASK_PRIORITY 2 + +#define LCD_H_RES 128 +#define LCD_V_RES 64 + +/** + * Wraps some foundational operations performed on pixel coordinates when + * dealing with pointer arithmetic. Most of these could be done ad-hoc as needed + * but using this helper reduces the risk of errors. + */ +struct Pixel { + /** + * Calculate byte offset for the pixel at [x,y] within a horizontally-mapped + * monochrome uint8 draw buffer, using the initialized horizontal resolution. + * + * We use `>> 3` because each pixel requires 1 bit, but each uint8 in the draw + * buffer can hold 8 bits. To find the uint8 value in our draw buffer that + * stores this pixel's value we must compensate for this when using pixel + * coordinates in byte math. + * + * Therefore, each uint8 in the draw buffer stores the state of 8 pixels. + * Below is an example of calculating for [x, y] pixel coordinates [20, 10]. + * The example uses a horizontal resolution of 128. + * + * For the horizontal case, each row (y) of the image is represented by + * `hor_res >> 3` bytes (16). The byte-offset of the first pixel in the 10th + * row for example is `16 * 10` = 160. + * + * Since the pixels are stored horizontally we must calculate the 20th pixel + * column (x) as `160 + (20 >> 3)`, or `160 + (20 / 8)` to get a final offset + * of 162. + * + * @param x X pixel coordinate to find byte offset. + * @param y Y pixel coordinate to find byte offset. + * @param hor_res horizontal resolution of the display. + * @return byte offset for a single-byte monochrome pixel at [x,y]. + */ + [[maybe_unused]] [[nodiscard]] static ptrdiff_t + horizontal_byte_offset(const int32_t &x, const int32_t &y, + const int32_t &hor_res = LCD_V_RES) + { + // Convert pixel (bit) coordinates to byte coordinates in the draw buffer. + return (hor_res >> 3) * y + (x >> 3); + } + + /** + * Calculate byte offset for the pixel at [x,y] within a vertically-mapped + * monochrome uint8 draw buffer, using the initialized horizontal resolution. + * + * We use `>> 3` because each pixel requires 1 bit, but each uint8 in the draw + * buffer can hold 8 bits. To find the uint8 value in our draw buffer that + * stores this pixel's value we must compensate for this when using pixel + * coordinates in byte math. + * + * Therefore, each uint8 in the draw buffer stores the state of 8 pixels. + * Below is an example of calculating for [x, y] pixel coordinates [20, 10]. + * The example uses a horizontal resolution of 128. + * + * For the vertical case, each row (y) of the image is represented by + * `hor_res` bytes (128) - one for each column (x). Because the pixels are + * stored vertically, the byte-offset of the first pixel in the 10th row is + * `128 * (10 >> 3)` or * `128 * (10 / 8)` = 128. + * + * From this location we can simply calculate the 20th pixel column (x) as + * `128 + 20` to get a final offset of 148, because the pixels are stored in a + * columnar format. + * + * @param x X pixel coordinate to find byte offset. + * @param y Y pixel coordinate to find byte offset. + * @param hor_res horizontal resolution of the display. + * @return byte offset for a single-byte monochrome pixel at [x,y]. + */ + [[maybe_unused]] [[nodiscard]] static ptrdiff_t + vertical_byte_offset(const int32_t &x, const int32_t &y, + const int32_t &hor_res = LCD_V_RES) + { + // Convert pixel (bit) coordinates to byte coordinates in the draw buffer. + return hor_res * (y >> 3) + x; + } + + /** + * Finds the Most Significant Bit location of bit `i` in a byte. + * + * MSB LSB + * bits 7 6 5 4 3 2 1 0 + * data 8 7 6 5 4 3 2 1 + * Left Right + * + * @return bitmask for MSB location of `i`. + */ + [[maybe_unused]] [[nodiscard]] static uint8_t + msb_mask(const int32_t &i) { return 1 << (7 - i % 8); } + + /** + * Finds the Least Significant Bit location of bit `i` in a byte. + * + * LSB MSB + * bits 0 1 2 3 4 5 6 7 + * data 1 2 3 4 5 6 7 8 + * Left Right + * + * @return bitmask for LSB location of `i`. + */ + [[maybe_unused]] [[nodiscard]] static uint8_t + lsb_mask(const int32_t &i) { return 1 << (i % 8); } +}; + + +/** + * Encapsulates vendor specific ESP LCD panel initialization logic. + * This pure virtual interface can be inherited from for using new LCD devices. + * See SSD1306 as an example to implement IPanelDevice for NT35510 or ST7789. + * + * At this time only I2C is supported. + * Classes that inherit from this interface should likely be marked final. + */ +class IPanelDevice { +public: + /** + * Construct an IPanelDevice. + * + * @param i2c I2C object. Eventually this will mature to IProtocol or similar. + * @param config I2C configuration for this device. + * @param height Height of the device screen in pixels. + * @param width Width of the device screen in pixels. + */ + explicit IPanelDevice(i2c_master_bus_handle_t &i2c, + esp_lcd_panel_io_i2c_config_t config, + int width, + int height) : + IPanelDevice(i2c, config, width, height, + width * height / 8 + LVGL_PALETTE_SIZE) { } + + /** + * Construct an IPanelDevice. + * + * @param i2c I2C object. Eventually this will mature to IProtocol or similar. + * @param config I2C configuration for this device. + * @param height Height of the device screen in pixels. + * @param width Width of the device screen in pixels. + * @param draw_buf_size Size of the draw buffer for this device. + */ + explicit IPanelDevice(i2c_master_bus_handle_t &, + esp_lcd_panel_io_i2c_config_t io_config, + int width, + int height, + size_t draw_buf_size) : + width_(width), + height_(height), + rst_num_(-1), + lv_buf_size_(draw_buf_size), + esp_io_config_(io_config), + lv_buf_(nullptr) { } + + virtual ~IPanelDevice() = default; + + // + // PUBLIC METHODS + + /** + * Create an LVGL display using the width and height of this device. + * + * @return Handle to the created LVGL display. + */ + [[nodiscard]] lv_display_t *create_display() const + { + auto display = lv_display_create(width_, height_); + assert(display); + return display; + } + + /** + * Create an ESP LCD panel IO handle. + * + * @return The created ESP LCD panel IO handle. + */ + [[nodiscard]] esp_lcd_panel_io_handle_t create_io_handle() + { + ESP_LOGI(TAG, "Creating panel IO handle"); + esp_lcd_panel_io_handle_t handle = nullptr; + ESP_ERROR_CHECK( + esp_lcd_new_panel_io_i2c(I2C_get(), &esp_io_config_, &handle)); + return handle; + } + + /** + * Create and initialize an ESP panel handle. + * IPanelDevice implementors must initialize the panel within init_panel. + * + * @param config ESP LCD panel configuration. + * @param io ESP LCD panel IO handle. + * @param [out] panel ESP LCD panel handle output pointer location. + */ + void 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) { + ESP_LOGI(TAG, "Removing unused panel"); + esp_lcd_panel_del(panel); + } + + ESP_LOGI(TAG, "Installing vendor panel driver"); + // Call pure virtual method responsible for initializing the panel handle. + init_panel(config, io, panel); + } + + /** + * Retrieve the device specific vendor configuration structure. + * + * @return Address of vendor configuration structure. + * @sa SSD1306::vendor_config + */ + virtual void *vendor_config() = 0; + + /** + * Registers LVGL draw buffers and callbacks for this display. + * + * An implementation of the interface can optionally override this method to + * provide custom LVGL callbacks and display configurations. + * + * @param display_handle LVGL display handle to use for rendering. + * @param io_handle IO handle for the ESP LCD panel. + */ + virtual void register_rendering_data(lv_display_t *display_handle, + esp_lcd_panel_io_handle_t io_handle); + + /** + * Registers LVGL ticker timer callback for rendering this display. + * + * An implementation of the interface can optionally override this method to + * provide custom LVGL callbacks and tick configurations. + */ + virtual void register_lvgl_tick_timer(); + + // + // PUBLIC MEMBERS + + /// Width of the device screen in pixels. + int32_t width_; + + /// Height of the device screen in pixels. + int32_t height_; + + /// RST GPIO pin number. + int rst_num_; + + /// LVGL draw buffer size for the device. + size_t lv_buf_size_; + + /// ESP LCD panel IO configuration. + esp_lcd_panel_io_i2c_config_t esp_io_config_; + +protected: + /** + * Static accessor to a static buffer to store draw buffer data for the panel. + * + * This method is protected to allow an implementation to provide a custom + * callback method similar to IPanelDevice::lvgl_flush_cb. + * + * The buffer is allocated statically within the scope of this function to + * allow creating multiple panels that _each_ manage their own statically + * allocated draw buffer data. This simplifies implementing the interface by + * taking this responsibility off of the implementor. The buffer will only be + * allocated if this method is called, so the memory is only used if required. + * + * @return Pointer to uint8 draw buffer data. + * @sa register_rendering_data for overriding LVGL rendering callbacks. + */ + static uint8_t *get_additional_draw_buffer() + { + // Static to the scope of this function, not the compilation unit. + // For LV_COLOR_FORMAT_I1 we need an extra buffer to hold converted data. + static uint8_t oled_buffer[LCD_H_RES * LCD_V_RES / 8]; + return oled_buffer; + } + +private: + + // + // PRIVATE METHODS + + /** + * Initializes the ESP panel using vendor specific APIs and configurations. + * This method should implement any setup logic specific to the device. + * + * @param config ESP LCD panel configuration. + * @param io ESP LCD panel IO handle. + * @param [out] panel ESP LCD panel handle output pointer location. + */ + virtual void init_panel(esp_lcd_panel_dev_config_t &config, + esp_lcd_panel_io_handle_t io, + esp_lcd_panel_handle_t &panel) = 0; + + // + // PRIVATE STATIC METHODS + +/** + * The callback invoked when panel IO finishes transferring color data. + * This signals that the panel is ready to flush image data to the display. + * + * @param panel LCD panel IO handles. + * @param data Panel IO event data, fed by driver. + * @param user_ctx User data, passed from `esp_lcd_panel_io_xxx_config_t`. + * @return Whether a high priority task has been waken up by this function. + * @sa SSD1306::SSD1306 for setting user_ctx data passed to the callback. + * @sa register_rendering_data for overriding this callback. + */ + static bool lvgl_flush_ready_cb(esp_lcd_panel_io_handle_t panel, + esp_lcd_panel_io_event_data_t *data, + void *user_ctx); + + /** + * The callback invoked for flushing the rendered image to the display. + * + * `px_map` contains the rendered image as raw pixel map and it should be + * copied to `area` on the display. + * + * The following details are crucial for understanding the logic surrounding + * flushing to the display in this example. + * + * The order of bits within the px_map from _LVGL_ is MSB first. + * MSB LSB + * bits 7 6 5 4 3 2 1 0 + * pixels 0 1 2 3 4 5 6 7 + * Left Right + * + * The bytes from _LVGL_ are mapped to pixel rows of the display + * 8 bits (pixels) per byte - + * [0, 0, 0, 0, 0, 0, 0, 0] + * [0, 0, 0, 0, 0, 0, 0, 0] + * [0, 0, 0, 0, 0, 0, 0, 0] + * + * The order of bits expected by the _display driver_ is LSB first. + * We must preserve pairing of each bit and pixel when writing to the display. + * LSB MSB + * bits 0 1 2 3 4 5 6 7 + * pixels 7 6 5 4 3 2 1 0 + * Left Right + * + * Bytes expected by the _display driver_ map to pixel columns of the display. + * 8 bits (pixels) per byte - + * [0, [0, [0, [0, + * 0, 0, 0, 0, + * 0, 0, 0, 0, + * 0, 0, 0, 0, + * 0, 0, 0, 0, + * 0, 0, 0, 0, + * 0, 0, 0, 0, + * 0] 0] 0] 0] + * + * These layouts in memory have no opinion on the shape of the image. The + * beginning and end of a row or a column for example is entirely dependent + * on how the data is accessed. The vertical and horitzontal resolution may + * vary between displays. + * + * For the LV_COLOR_FORMAT_I1 color format we are using, an additional buffer + * is needed for transposing the bits to the vertical arrangement required by + * the display driver that is outlined above. + * + * This callback implementation is an example of handling this transposition + * and flushing the data to the display in the expected format. + * + * @param display LVGL display handle to use for rendering. + * @param area Area of the display being flushed. + * @param px_map Rendered image data for writing to the display area. + * @sa register_rendering_data for overriding this callback. + * @sa get_additional_draw_buffer + */ + static void lvgl_flush_cb(lv_display_t *display, + const lv_area_t *area, + uint8_t *px_map); + + /** + * Callback invoked for every period of the timer. + * + * This callback _must_ call lv_tick_inc to inform LVGL how much time has + * elapsed since the last period of the timer. + * + * @param data User data passed to the callback. + * @sa register_lvgl_tick_timer for setting user data and the tick period of + * the timer, or overriding this callback entirely. + */ + static void lvgl_increase_tick_cb(void *data); + + /** + * FreeRTOS task callback invoked for handling LVGL events or updating the UI. + * + * This function is intentionally an endless loop and should never return. + * LVGL initialization logic can optionally be added before entering the loop. + * Input logic can optionally be handled within the loop. + * + * This callback _must_ call lv_timer_handler to handle LVGL periodic timers. + * + * @param data User data passed to the callback. + * @sa register_lvgl_tick_timer for overriding this callback. + */ + [[noreturn]] static void lvgl_port_task(void *data); + + // + // PRIVATE MEMBERS + + /// LVGL draw buffer associated with this Display's lv_display_t. + void *lv_buf_; + + /// Tag used for ESP logging. + constexpr static const char *TAG = "IPanelDevice"; +}; + +#endif // PANEL_DEVICE_H diff --git a/esp/cpp/08_dht11-lcd/main/scoped_lock.cpp b/esp/cpp/08_dht11-lcd/main/scoped_lock.cpp new file mode 100644 index 0000000..b0f301d --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/scoped_lock.cpp @@ -0,0 +1,12 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#include "scoped_lock.h" + +// LVGL library is not thread-safe, this example calls LVGL APIs from tasks. +// We must use a mutex to protect it. +_lock_t ScopedLock::lv_lock_; diff --git a/esp/cpp/08_dht11-lcd/main/scoped_lock.h b/esp/cpp/08_dht11-lcd/main/scoped_lock.h new file mode 100644 index 0000000..9cd8f64 --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/scoped_lock.h @@ -0,0 +1,28 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#ifndef SCOPED_LOCK_H +#define SCOPED_LOCK_H + +#include + +/** + * Obtains LVGL API mutex lock for the duration of local scope. + * + * LVGL library is not thread-safe, this lock should be held when making calls + * to the LVGL API, and released as soon as possible when finished. + */ +struct ScopedLock { + explicit ScopedLock() { _lock_acquire(&lv_lock_); } + + ~ScopedLock() { _lock_release(&lv_lock_); } + + /// Mutex used to protect LVGL API calls. + static _lock_t lv_lock_; +}; + +#endif // SCOPED_LOCK_H diff --git a/esp/cpp/08_dht11-lcd/main/ssd1306.h b/esp/cpp/08_dht11-lcd/main/ssd1306.h new file mode 100644 index 0000000..53aef34 --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/ssd1306.h @@ -0,0 +1,106 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#ifndef SSD1306_H +#define SSD1306_H + +#include + +#include "panel_device.h" + +// According to specific display hardware. +// https://www.digikey.com/en/products/detail/winstar-display/WEA012864DWPP3N00003/20533255 +#define SCREEN_WIDTH 128 // OLED display width, in pixels. +#define SCREEN_HEIGHT 64 // OLED display height, in pixels. + +// According to SSD1306 datasheet. +// https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf +#define I2C_HW_ADDR 0x3C +#define LCD_PIXEL_CLOCK_HZ (400 * 1000) +// Bit number used to represent command and parameter +#define LCD_CMD_BITS 8 +#define LCD_PARAM_BITS 8 + +/** + * Example of implementing the IPanelDevice interface for SSD1306 LCD device. + */ +class SSD1306 final : public IPanelDevice { +public: + /** + * Construct a new SSD1306 device. + * + * @param i2c I2C master bus to manage this device. + */ + explicit SSD1306(i2c_master_bus_handle_t &i2c) : + SSD1306(i2c, {.height = SCREEN_HEIGHT}) { } + + /** + * Construct a new SSD1306 device given a specific SSD1306 configuration. + * + * @param i2c I2C master bus to manage this device. + * @param config SSD1306 vendor configuration. + * @param width Width of the device screen in pixels. + * @param height Height of the device screen in pixels. + */ + SSD1306(i2c_master_bus_handle_t &i2c, + esp_lcd_panel_ssd1306_config_t config, + int width = SCREEN_WIDTH, + int height = SCREEN_HEIGHT + ) : + IPanelDevice(i2c, + (esp_lcd_panel_io_i2c_config_t) { + .dev_addr = I2C_HW_ADDR, + // User data to pass to the LVGL flush_ready callback. + // See IPanelDevice::lvgl_flush_ready_cb + .user_ctx = nullptr, + .control_phase_bytes = 1, + .dc_bit_offset = 6, + .lcd_cmd_bits = LCD_CMD_BITS, + .lcd_param_bits = LCD_PARAM_BITS, + .scl_speed_hz = LCD_PIXEL_CLOCK_HZ, + }, + width, + height + ), + ssd1306_config_(config) { } + + ~SSD1306() final = default; + + // + // PUBLIC METHODS + + /** + * Provides the SSD1306 vendor configuration to IPanelDevice consumers. + * + * @return Address of the SSD1306 vendor configuration structure. + */ + void *vendor_config() override + { + return &ssd1306_config_; + } + + // + // PUBLIC MEMBERS + + /// SSD1306 configuration structure. + esp_lcd_panel_ssd1306_config_t ssd1306_config_; + +private: + + // + // PRIVATE METHODS + + /// Initializes the ESP LCD panel handle for the SSD1306 device. + void init_panel(esp_lcd_panel_dev_config_t &config, + esp_lcd_panel_io_handle_t io, + esp_lcd_panel_handle_t &panel) override + { + ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io, &config, &panel)); + } +}; + +#endif // SSD1306_H diff --git a/esp/cpp/08_dht11-lcd/main/time_keeper.h b/esp/cpp/08_dht11-lcd/main/time_keeper.h new file mode 100644 index 0000000..71eafbb --- /dev/null +++ b/esp/cpp/08_dht11-lcd/main/time_keeper.h @@ -0,0 +1,161 @@ +/*############################################################################# +## Author: Shaun Reed ## +## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ## +## ## +## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ## +############################################################################## +*/ +#ifndef TIME_KEEPER_H +#define TIME_KEEPER_H + +#include +#include + +#include "i2c.h" + +/** + * Stores arguments and ESP timer handle for a Timer. + * In general Timers should be used via the TimeKeeper interface only. + * + * Timers cannot be copied, and are only created by a TimeKeeper instance. + * The TimeKeeper can delete existing Timers, calling it's destructor. + * The ESP timer will be deleted when this class desctructor is called. + */ +struct Timer { + explicit Timer(esp_timer_create_args_t args) : + args_(args), esp_timer_(nullptr) + { + ESP_LOGI(TAG, "Creating esp_timer with name: '%s'", args_.name); + ESP_ERROR_CHECK(esp_timer_create(&args, &esp_timer_)); + } + + ~Timer() + { + ESP_LOGI(TAG, "Destroying esp_timer with name: '%s'", args_.name); + ESP_ERROR_CHECK(esp_timer_delete(esp_timer_)); + } + + Timer(const Timer &) = delete; + + Timer(Timer &) = delete; + + Timer &operator=(Timer &) = delete; + + // + // PUBLIC MEMBERS + + /// Arguments passed to ESP API during timer creation. + esp_timer_create_args_t args_; + + /// ESP timer handle. + esp_timer_handle_t esp_timer_; + +private: + + // + // PRIVATE MEMBERS + + /// Tag used for ESP logging. + constexpr static const char *TAG = "Timer"; +}; + +/** + * ESP timer mananger class. + * + * Timers should only be accessed using the get_handle method. + * If the Timer destructor is called the underlying ESP timer will be deleted. + */ +struct TimeKeeper { + /// Timer handle type used for referring to Timers. + using TimerHandle = Timer *; + + // + // GETTERS + + TimerHandle get_handle(const char *name) + { + return &managed_timers_.at(name); + } + + TimerHandle operator[](const char *name) { return get_handle(name); } + + // + // PUBLIC METHODS + + /** + * Create a new managed Timer with the provided ESP arguments. + * The timer can be retrieved later using the args.name field value. + * + * @param args ESP timer creation arguments. + * @return TimerHandle Handle to a Timer managed by this TimeKeeper. + * @sa get_handle + * @sa operator[](const char*) + */ + [[maybe_unused]] TimerHandle create_timer(esp_timer_create_args_t args) + { + auto rt = managed_timers_.emplace(args.name, args); + if (!rt.second) { + ESP_LOGE(TAG, "Timer already exists with name '%s'", args.name); + return nullptr; + } + return &rt.first->second; + } + + /// Stop a Timer with the given name. + [[maybe_unused]] void stop_timer(const char *name) + { + ESP_ERROR_CHECK(esp_timer_stop(get_handle(name)->esp_timer_)); + } + + /// Delete a Timer with the given name. + [[maybe_unused]] void delete_timer(const char *name) + { + if (managed_timers_.erase(name) == 0) { + ESP_LOGE(TAG, "Attempt to delete timer that does not exist: '%s'", name); + } + } + + /// Create a Timer with the ESP args and call esp_timer_start_periodic. + [[maybe_unused]] void + start_new_timer_periodic(esp_timer_create_args_t args, + uint64_t period) + { + start_timer_periodic(create_timer(args)->args_.name, period); + } + + /// Calls esp_timer_start_periodic on the Timer with the given name. + [[maybe_unused]] void start_timer_periodic(const char *name, + uint64_t period) + { + ESP_ERROR_CHECK( + esp_timer_start_periodic(get_handle(name)->esp_timer_, period)); + } + + /// Create a Timer with the ESP args and call esp_timer_start_once. + [[maybe_unused]] void start_new_timer_once(esp_timer_create_args_t args, + uint64_t timeout_us) + { + start_timer_once(create_timer(args)->args_.name, timeout_us); + } + + /// Calls esp_timer_start_once on the Timer with the given name. + [[maybe_unused]] void start_timer_once(const char *name, + uint64_t timeout_us) + { + ESP_ERROR_CHECK( + esp_timer_start_once(get_handle(name)->esp_timer_, timeout_us)); + } + +private: + + // + // PRIVATE MEMBERS + + /// Existing ESP timers created for this TimeKeeper instance. + std::unordered_map managed_timers_; + + /// Tag used for ESP logging. + constexpr static const char *TAG = "TimeKeeper"; +}; + +#endif // TIME_KEEPER_H diff --git a/esp/cpp/08_dht11-lcd/sdkconfig b/esp/cpp/08_dht11-lcd/sdkconfig index 6fb7e3a..ccfd63b 100644 --- a/esp/cpp/08_dht11-lcd/sdkconfig +++ b/esp/cpp/08_dht11-lcd/sdkconfig @@ -2010,6 +2010,383 @@ CONFIG_WIFI_PROV_AUTOSTOP_TIMEOUT=30 CONFIG_WIFI_PROV_STA_ALL_CHANNEL_SCAN=y # CONFIG_WIFI_PROV_STA_FAST_SCAN is not set # end of Wi-Fi Provisioning Manager + +# +# LVGL configuration +# +CONFIG_LV_CONF_SKIP=y +# CONFIG_LV_CONF_MINIMAL is not set + +# +# Color Settings +# +# CONFIG_LV_COLOR_DEPTH_32 is not set +# CONFIG_LV_COLOR_DEPTH_24 is not set +CONFIG_LV_COLOR_DEPTH_16=y +# CONFIG_LV_COLOR_DEPTH_8 is not set +# CONFIG_LV_COLOR_DEPTH_1 is not set +CONFIG_LV_COLOR_DEPTH=16 +# end of Color Settings + +# +# Memory Settings +# +CONFIG_LV_USE_BUILTIN_MALLOC=y +# CONFIG_LV_USE_CLIB_MALLOC is not set +# CONFIG_LV_USE_MICROPYTHON_MALLOC is not set +# CONFIG_LV_USE_RTTHREAD_MALLOC is not set +# CONFIG_LV_USE_CUSTOM_MALLOC is not set +CONFIG_LV_USE_BUILTIN_STRING=y +# CONFIG_LV_USE_CLIB_STRING is not set +# CONFIG_LV_USE_CUSTOM_STRING is not set +CONFIG_LV_USE_BUILTIN_SPRINTF=y +# CONFIG_LV_USE_CLIB_SPRINTF is not set +# CONFIG_LV_USE_CUSTOM_SPRINTF is not set +CONFIG_LV_MEM_SIZE_KILOBYTES=64 +CONFIG_LV_MEM_POOL_EXPAND_SIZE_KILOBYTES=0 +CONFIG_LV_MEM_ADR=0x0 +# end of Memory Settings + +# +# HAL Settings +# +CONFIG_LV_DEF_REFR_PERIOD=33 +CONFIG_LV_DPI_DEF=130 +# end of HAL Settings + +# +# Operating System (OS) +# +CONFIG_LV_OS_NONE=y +# CONFIG_LV_OS_PTHREAD is not set +# CONFIG_LV_OS_FREERTOS is not set +# CONFIG_LV_OS_CMSIS_RTOS2 is not set +# CONFIG_LV_OS_RTTHREAD is not set +# CONFIG_LV_OS_WINDOWS is not set +# CONFIG_LV_OS_MQX is not set +# CONFIG_LV_OS_CUSTOM is not set +CONFIG_LV_USE_OS=0 +# end of Operating System (OS) + +# +# Rendering Configuration +# +CONFIG_LV_DRAW_BUF_STRIDE_ALIGN=1 +CONFIG_LV_DRAW_BUF_ALIGN=4 +CONFIG_LV_DRAW_LAYER_SIMPLE_BUF_SIZE=24576 +CONFIG_LV_USE_DRAW_SW=y +CONFIG_LV_DRAW_SW_SUPPORT_RGB565=y +CONFIG_LV_DRAW_SW_SUPPORT_RGB565A8=y +CONFIG_LV_DRAW_SW_SUPPORT_RGB888=y +CONFIG_LV_DRAW_SW_SUPPORT_XRGB8888=y +CONFIG_LV_DRAW_SW_SUPPORT_ARGB8888=y +CONFIG_LV_DRAW_SW_SUPPORT_L8=y +CONFIG_LV_DRAW_SW_SUPPORT_AL88=y +CONFIG_LV_DRAW_SW_SUPPORT_A8=y +CONFIG_LV_DRAW_SW_SUPPORT_I1=y +CONFIG_LV_DRAW_SW_DRAW_UNIT_CNT=1 +# CONFIG_LV_USE_DRAW_ARM2D_SYNC is not set +# CONFIG_LV_USE_NATIVE_HELIUM_ASM is not set +CONFIG_LV_DRAW_SW_COMPLEX=y +# CONFIG_LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not set +CONFIG_LV_DRAW_SW_SHADOW_CACHE_SIZE=0 +CONFIG_LV_DRAW_SW_CIRCLE_CACHE_SIZE=4 +CONFIG_LV_DRAW_SW_ASM_NONE=y +# CONFIG_LV_DRAW_SW_ASM_NEON is not set +# CONFIG_LV_DRAW_SW_ASM_HELIUM is not set +# CONFIG_LV_DRAW_SW_ASM_CUSTOM is not set +CONFIG_LV_USE_DRAW_SW_ASM=0 +# CONFIG_LV_USE_DRAW_VGLITE is not set +# CONFIG_LV_USE_DRAW_PXP is not set +# CONFIG_LV_USE_DRAW_DAVE2D is not set +# CONFIG_LV_USE_DRAW_SDL is not set +# CONFIG_LV_USE_DRAW_VG_LITE is not set +# CONFIG_LV_USE_VECTOR_GRAPHIC is not set +# end of Rendering Configuration + +# +# Feature Configuration +# + +# +# Logging +# +# CONFIG_LV_USE_LOG is not set +# end of Logging + +# +# Asserts +# +CONFIG_LV_USE_ASSERT_NULL=y +CONFIG_LV_USE_ASSERT_MALLOC=y +# CONFIG_LV_USE_ASSERT_STYLE is not set +# CONFIG_LV_USE_ASSERT_MEM_INTEGRITY is not set +# CONFIG_LV_USE_ASSERT_OBJ is not set +CONFIG_LV_ASSERT_HANDLER_INCLUDE="assert.h" +# end of Asserts + +# +# Debug +# +# CONFIG_LV_USE_REFR_DEBUG is not set +# CONFIG_LV_USE_LAYER_DEBUG is not set +# CONFIG_LV_USE_PARALLEL_DRAW_DEBUG is not set +# end of Debug + +# +# Others +# +# CONFIG_LV_ENABLE_GLOBAL_CUSTOM is not set +CONFIG_LV_CACHE_DEF_SIZE=0 +CONFIG_LV_IMAGE_HEADER_CACHE_DEF_CNT=0 +CONFIG_LV_GRADIENT_MAX_STOPS=2 +CONFIG_LV_COLOR_MIX_ROUND_OFS=128 +# CONFIG_LV_OBJ_STYLE_CACHE is not set +# CONFIG_LV_USE_OBJ_ID is not set +# CONFIG_LV_USE_OBJ_PROPERTY is not set +# end of Others +# end of Feature Configuration + +# +# Compiler Settings +# +# CONFIG_LV_BIG_ENDIAN_SYSTEM is not set +CONFIG_LV_ATTRIBUTE_MEM_ALIGN_SIZE=1 +# CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM is not set +# CONFIG_LV_USE_FLOAT is not set +# CONFIG_LV_USE_MATRIX is not set +# CONFIG_LV_USE_PRIVATE_API is not set +# end of Compiler Settings + +# +# Font Usage +# + +# +# Enable built-in fonts +# +# CONFIG_LV_FONT_MONTSERRAT_8 is not set +# CONFIG_LV_FONT_MONTSERRAT_10 is not set +# CONFIG_LV_FONT_MONTSERRAT_12 is not set +CONFIG_LV_FONT_MONTSERRAT_14=y +# CONFIG_LV_FONT_MONTSERRAT_16 is not set +# CONFIG_LV_FONT_MONTSERRAT_18 is not set +# CONFIG_LV_FONT_MONTSERRAT_20 is not set +# CONFIG_LV_FONT_MONTSERRAT_22 is not set +# CONFIG_LV_FONT_MONTSERRAT_24 is not set +# CONFIG_LV_FONT_MONTSERRAT_26 is not set +# CONFIG_LV_FONT_MONTSERRAT_28 is not set +# CONFIG_LV_FONT_MONTSERRAT_30 is not set +# CONFIG_LV_FONT_MONTSERRAT_32 is not set +# CONFIG_LV_FONT_MONTSERRAT_34 is not set +# CONFIG_LV_FONT_MONTSERRAT_36 is not set +# CONFIG_LV_FONT_MONTSERRAT_38 is not set +# CONFIG_LV_FONT_MONTSERRAT_40 is not set +# CONFIG_LV_FONT_MONTSERRAT_42 is not set +# CONFIG_LV_FONT_MONTSERRAT_44 is not set +# CONFIG_LV_FONT_MONTSERRAT_46 is not set +# CONFIG_LV_FONT_MONTSERRAT_48 is not set +# CONFIG_LV_FONT_MONTSERRAT_28_COMPRESSED is not set +# CONFIG_LV_FONT_DEJAVU_16_PERSIAN_HEBREW is not set +# CONFIG_LV_FONT_SIMSUN_14_CJK is not set +# CONFIG_LV_FONT_SIMSUN_16_CJK is not set +# CONFIG_LV_FONT_UNSCII_8 is not set +# CONFIG_LV_FONT_UNSCII_16 is not set +# end of Enable built-in fonts + +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_8 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_10 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_12 is not set +CONFIG_LV_FONT_DEFAULT_MONTSERRAT_14=y +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_16 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_18 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_20 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_22 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_24 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_26 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_28 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_30 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_32 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_34 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_36 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_38 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_40 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_42 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_44 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_46 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_48 is not set +# CONFIG_LV_FONT_DEFAULT_MONTSERRAT_28_COMPRESSED is not set +# CONFIG_LV_FONT_DEFAULT_DEJAVU_16_PERSIAN_HEBREW is not set +# CONFIG_LV_FONT_DEFAULT_SIMSUN_14_CJK is not set +# CONFIG_LV_FONT_DEFAULT_SIMSUN_16_CJK is not set +# CONFIG_LV_FONT_DEFAULT_UNSCII_8 is not set +# CONFIG_LV_FONT_DEFAULT_UNSCII_16 is not set +# CONFIG_LV_FONT_FMT_TXT_LARGE is not set +# CONFIG_LV_USE_FONT_COMPRESSED is not set +CONFIG_LV_USE_FONT_PLACEHOLDER=y +# end of Font Usage + +# +# Text Settings +# +CONFIG_LV_TXT_ENC_UTF8=y +# CONFIG_LV_TXT_ENC_ASCII is not set +CONFIG_LV_TXT_BREAK_CHARS=" ,.;:-_)}" +CONFIG_LV_TXT_LINE_BREAK_LONG_LEN=0 +# CONFIG_LV_USE_BIDI is not set +# CONFIG_LV_USE_ARABIC_PERSIAN_CHARS is not set +# end of Text Settings + +# +# Widget Usage +# +CONFIG_LV_WIDGETS_HAS_DEFAULT_VALUE=y +CONFIG_LV_USE_ANIMIMG=y +CONFIG_LV_USE_ARC=y +CONFIG_LV_USE_BAR=y +CONFIG_LV_USE_BUTTON=y +CONFIG_LV_USE_BUTTONMATRIX=y +CONFIG_LV_USE_CALENDAR=y +# CONFIG_LV_CALENDAR_WEEK_STARTS_MONDAY is not set +CONFIG_LV_USE_CALENDAR_HEADER_ARROW=y +CONFIG_LV_USE_CALENDAR_HEADER_DROPDOWN=y +# CONFIG_LV_USE_CALENDAR_CHINESE is not set +CONFIG_LV_USE_CANVAS=y +CONFIG_LV_USE_CHART=y +CONFIG_LV_USE_CHECKBOX=y +CONFIG_LV_USE_DROPDOWN=y +CONFIG_LV_USE_IMAGE=y +CONFIG_LV_USE_IMAGEBUTTON=y +CONFIG_LV_USE_KEYBOARD=y +CONFIG_LV_USE_LABEL=y +CONFIG_LV_LABEL_TEXT_SELECTION=y +CONFIG_LV_LABEL_LONG_TXT_HINT=y +CONFIG_LV_LABEL_WAIT_CHAR_COUNT=3 +CONFIG_LV_USE_LED=y +CONFIG_LV_USE_LINE=y +CONFIG_LV_USE_LIST=y +CONFIG_LV_USE_MENU=y +CONFIG_LV_USE_MSGBOX=y +CONFIG_LV_USE_ROLLER=y +CONFIG_LV_USE_SCALE=y +CONFIG_LV_USE_SLIDER=y +CONFIG_LV_USE_SPAN=y +CONFIG_LV_SPAN_SNIPPET_STACK_SIZE=64 +CONFIG_LV_USE_SPINBOX=y +CONFIG_LV_USE_SPINNER=y +CONFIG_LV_USE_SWITCH=y +CONFIG_LV_USE_TEXTAREA=y +CONFIG_LV_TEXTAREA_DEF_PWD_SHOW_TIME=1500 +CONFIG_LV_USE_TABLE=y +CONFIG_LV_USE_TABVIEW=y +CONFIG_LV_USE_TILEVIEW=y +CONFIG_LV_USE_WIN=y +# end of Widget Usage + +# +# Themes +# +CONFIG_LV_USE_THEME_DEFAULT=y +# CONFIG_LV_THEME_DEFAULT_DARK is not set +CONFIG_LV_THEME_DEFAULT_GROW=y +CONFIG_LV_THEME_DEFAULT_TRANSITION_TIME=80 +CONFIG_LV_USE_THEME_SIMPLE=y +# CONFIG_LV_USE_THEME_MONO is not set +# end of Themes + +# +# Layouts +# +CONFIG_LV_USE_FLEX=y +CONFIG_LV_USE_GRID=y +# end of Layouts + +# +# 3rd Party Libraries +# +CONFIG_LV_FS_DEFAULT_DRIVE_LETTER=0 +# CONFIG_LV_USE_FS_STDIO is not set +# CONFIG_LV_USE_FS_POSIX is not set +# CONFIG_LV_USE_FS_WIN32 is not set +# CONFIG_LV_USE_FS_FATFS is not set +# CONFIG_LV_USE_FS_MEMFS is not set +# CONFIG_LV_USE_FS_LITTLEFS is not set +# CONFIG_LV_USE_FS_ARDUINO_ESP_LITTLEFS is not set +# CONFIG_LV_USE_FS_ARDUINO_SD is not set +# CONFIG_LV_USE_LODEPNG is not set +# CONFIG_LV_USE_LIBPNG is not set +# CONFIG_LV_USE_BMP is not set +# CONFIG_LV_USE_TJPGD is not set +# CONFIG_LV_USE_LIBJPEG_TURBO is not set +# CONFIG_LV_USE_GIF is not set +# CONFIG_LV_BIN_DECODER_RAM_LOAD is not set +# CONFIG_LV_USE_RLE is not set +# CONFIG_LV_USE_QRCODE is not set +# CONFIG_LV_USE_BARCODE is not set +# CONFIG_LV_USE_FREETYPE is not set +# CONFIG_LV_USE_TINY_TTF is not set +# CONFIG_LV_USE_RLOTTIE is not set +# CONFIG_LV_USE_THORVG is not set +# CONFIG_LV_USE_LZ4 is not set +# CONFIG_LV_USE_FFMPEG is not set +# end of 3rd Party Libraries + +# +# Others +# +# CONFIG_LV_USE_SNAPSHOT is not set +# CONFIG_LV_USE_SYSMON is not set +# CONFIG_LV_USE_PROFILER is not set +# CONFIG_LV_USE_MONKEY is not set +# CONFIG_LV_USE_GRIDNAV is not set +# CONFIG_LV_USE_FRAGMENT is not set +# CONFIG_LV_USE_IMGFONT is not set +CONFIG_LV_USE_OBSERVER=y +# CONFIG_LV_USE_IME_PINYIN is not set +# CONFIG_LV_USE_FILE_EXPLORER is not set +# end of Others + +# +# Devices +# +# CONFIG_LV_USE_SDL is not set +# CONFIG_LV_USE_X11 is not set +# CONFIG_LV_USE_WAYLAND is not set +# CONFIG_LV_USE_LINUX_FBDEV is not set +# CONFIG_LV_USE_NUTTX is not set +# CONFIG_LV_USE_LINUX_DRM is not set +# CONFIG_LV_USE_TFT_ESPI is not set +# CONFIG_LV_USE_EVDEV is not set +# CONFIG_LV_USE_LIBINPUT is not set +# CONFIG_LV_USE_ST7735 is not set +# CONFIG_LV_USE_ST7789 is not set +# CONFIG_LV_USE_ST7796 is not set +# CONFIG_LV_USE_ILI9341 is not set +# CONFIG_LV_USE_GENERIC_MIPI is not set +# CONFIG_LV_USE_RENESAS_GLCDC is not set +# CONFIG_LV_USE_OPENGLES is not set +# CONFIG_LV_USE_QNX is not set +# end of Devices + +# +# Examples +# +CONFIG_LV_BUILD_EXAMPLES=y +# end of Examples + +# +# Demos +# +# CONFIG_LV_USE_DEMO_WIDGETS is not set +# CONFIG_LV_USE_DEMO_KEYPAD_AND_ENCODER is not set +# CONFIG_LV_USE_DEMO_RENDER is not set +# CONFIG_LV_USE_DEMO_SCROLL is not set +# CONFIG_LV_USE_DEMO_STRESS is not set +# CONFIG_LV_USE_DEMO_MUSIC is not set +# CONFIG_LV_USE_DEMO_FLEX_LAYOUT is not set +# CONFIG_LV_USE_DEMO_MULTILANG is not set +# end of Demos +# end of LVGL configuration # end of Component config # CONFIG_IDF_EXPERIMENTAL_FEATURES is not set diff --git a/esp/cpp/components/i2c/include/i2c.h b/esp/cpp/components/i2c/include/i2c.h index 1877667..acdccc6 100644 --- a/esp/cpp/components/i2c/include/i2c.h +++ b/esp/cpp/components/i2c/include/i2c.h @@ -14,7 +14,7 @@ #include /// Tag used for ESP logging. -static const char* TAG = "I2C component"; +static const char* I2C_TAG = "I2C component"; /** * Construct an ESP I2C master bus given a specific ESP I2C configuration. @@ -22,10 +22,10 @@ static const char* TAG = "I2C component"; * * @param config ESP I2C master bus configuration. */ -inline void init_config_i2c(const i2c_master_bus_config_t config) +inline void I2C_config_init(const i2c_master_bus_config_t config) { i2c_master_bus_handle_t i2c; - ESP_LOGI(TAG, "Initializing new master I2C bus"); + ESP_LOGI(I2C_TAG, "Initializing new master I2C bus"); ESP_ERROR_CHECK(i2c_new_master_bus(&config, &i2c)); } @@ -36,9 +36,9 @@ inline void init_config_i2c(const i2c_master_bus_config_t config) * @param sda GPIO pin for SDA * @param scl GPIO pin for SCL */ -inline void init_i2c(gpio_num_t sda, gpio_num_t scl) +inline void I2C_init(gpio_num_t sda, gpio_num_t scl) { - return init_config_i2c((i2c_master_bus_config_t){ + return I2C_config_init((i2c_master_bus_config_t){ .i2c_port = I2C_BUS_PORT, .sda_io_num = sda, .scl_io_num = scl, @@ -55,12 +55,11 @@ inline void init_i2c(gpio_num_t sda, gpio_num_t scl) * ESP I2C master bus handle getter. * This will fail if an I2C instance was never constructed. */ -static i2c_master_bus_handle_t get() +static i2c_master_bus_handle_t I2C_get() { i2c_master_bus_handle_t i2c = NULL; ESP_ERROR_CHECK(i2c_master_get_bus_handle(0, &i2c)); return i2c; } - #endif //I2C_H