2025-02-16 06:38:47 -05:00

52 lines
1.5 KiB
C++

#ifndef SSD1306_H
#define SSD1306_H
#include <esp_lcd_panel_ssd1306.h>
#include "panel_device.h"
// According to SSD1306 datasheet
// https://www.digikey.com/en/products/detail/winstar-display/WEA012864DWPP3N00003/20533255
// 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
class SSD1306 : public IPanelDevice {
public:
// Constructors allow overriding ssd1306 config.
explicit SSD1306(I2C &i2c) :
SSD1306(i2c, {.height = SCREEN_HEIGHT}) { }
SSD1306(I2C &i2c,
esp_lcd_panel_ssd1306_config_t config,
int width = SCREEN_WIDTH,
int height = SCREEN_HEIGHT
);
virtual ~SSD1306() = default;
void *vendor_config() override
{
return &ssd1306_config_;
}
// The configuration structure specific to the SSD1306.
esp_lcd_panel_ssd1306_config_t ssd1306_config_;
// For 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];
private:
void init_panel(esp_lcd_panel_dev_config_t &config,
esp_lcd_panel_io_handle_t io,
esp_lcd_panel_handle_t &panel) override;
};
#endif // SSD1306_H