109 lines
2.8 KiB
C++
109 lines
2.8 KiB
C++
#ifndef DISPLAY_H
|
|
#define DISPLAY_H
|
|
|
|
#include <esp_lcd_types.h>
|
|
#include <esp_lcd_panel_ssd1306.h>
|
|
#include <driver/i2c_types.h>
|
|
#include "misc/lv_types.h"
|
|
#include "misc/lv_area.h"
|
|
|
|
#define I2C_BUS_PORT 0
|
|
#define LVGL_TICK_PERIOD_MS 5
|
|
#define LVGL_TASK_STACK_SIZE (4 * 1024)
|
|
#define LVGL_TASK_PRIORITY 2
|
|
#define LVGL_PALETTE_SIZE 8
|
|
|
|
static const char *TAG = "lcd-panel";
|
|
|
|
// https://www.digikey.com/en/products/detail/winstar-display/WEA012864DWPP3N00003/20533255
|
|
// According to SSD1306 datasheet
|
|
// Bit number used to represent command and parameter
|
|
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
|
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
|
#define LCD_H_RES SCREEN_WIDTH
|
|
#define LCD_V_RES SCREEN_HEIGHT
|
|
#define I2C_HW_ADDR 0x3C
|
|
#define LCD_PIXEL_CLOCK_HZ (400 * 1000)
|
|
#define LCD_CMD_BITS 8
|
|
#define LCD_PARAM_BITS 8
|
|
|
|
// Pin may vary based on your schematic
|
|
#define PIN_SDA GPIO_NUM_21
|
|
#define PIN_SCL GPIO_NUM_22
|
|
#define PIN_RST -1
|
|
|
|
struct ScopedLock {
|
|
explicit ScopedLock(_lock_t& lock) : lock_(&lock) { _lock_acquire(lock_); }
|
|
~ScopedLock() { _lock_release(lock_); }
|
|
|
|
private:
|
|
_lock_t* lock_;
|
|
};
|
|
|
|
class Display {
|
|
public:
|
|
Display();
|
|
|
|
~Display() = default;
|
|
|
|
|
|
[[nodiscard]] inline const lv_display_t *get() const { return display_; }
|
|
|
|
[[nodiscard]] inline lv_display_t *get() { return display_; }
|
|
|
|
[[nodiscard]] inline const lv_display_t *operator*() const { return get(); }
|
|
|
|
[[nodiscard]] inline lv_display_t *operator*() { return get(); }
|
|
|
|
static bool lvgl_flush_ready(esp_lcd_panel_io_handle_t panel,
|
|
esp_lcd_panel_io_event_data_t *data,
|
|
void *user_ctx);
|
|
|
|
static void
|
|
lvgl_flush_cb(lv_display_t *display, const lv_area_t *area, uint8_t *px_map);
|
|
|
|
static void lvgl_increase_tick(void *arg);
|
|
|
|
static void lvgl_port_task(void *arg);
|
|
|
|
// To use LV_COLOR_FORMAT_I1, we need an extra buffer to hold the converted data
|
|
static uint8_t oled_buffer_[LCD_H_RES * LCD_V_RES / 8];
|
|
|
|
// LVGL library is not thread-safe, this example will call LVGL APIs from different tasks, so use a mutex to protect it
|
|
static _lock_t lvgl_api_lock_;
|
|
|
|
protected:
|
|
esp_lcd_panel_io_handle_t io_handle_;
|
|
|
|
esp_lcd_panel_handle_t panel_handle_;
|
|
|
|
esp_lcd_panel_dev_config_t panel_config_;
|
|
|
|
esp_lcd_panel_ssd1306_config_t ssd1306_config_;
|
|
|
|
i2c_master_bus_handle_t i2c_bus_;
|
|
|
|
private:
|
|
void init_i2c();
|
|
|
|
// virtual void *vendor_config() = 0;
|
|
|
|
lv_display_t *display_;
|
|
|
|
void * vendor_config_;
|
|
void * buf_;
|
|
};
|
|
|
|
//class SSD1306 : public Display {
|
|
//public:
|
|
// SSD1306();
|
|
//
|
|
// void * vendor_config() override;
|
|
//
|
|
//private:
|
|
// esp_lcd_panel_dev_config_t panel_config_;
|
|
// esp_lcd_panel_ssd1306_config_t ssd1306_config_;
|
|
//};
|
|
|
|
#endif // DISPLAY_H
|