52 lines
1.5 KiB
C
Raw Normal View History

2025-02-15 10:11:49 -05:00
#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
2025-02-15 17:12:06 -05:00
class SSD1306 : public IPanelDevice {
2025-02-15 10:11:49 -05:00
public:
2025-02-15 17:12:06 -05:00
// Constructors allow overriding ssd1306 config.
2025-02-15 18:16:25 -05:00
explicit SSD1306(I2C &i2c) :
2025-02-15 17:12:06 -05:00
SSD1306(i2c, {.height = SCREEN_HEIGHT}) { }
2025-02-15 10:11:49 -05:00
2025-02-15 18:16:25 -05:00
SSD1306(I2C &i2c,
esp_lcd_panel_ssd1306_config_t config,
int width = SCREEN_WIDTH,
int height = SCREEN_HEIGHT
);
2025-02-15 17:12:06 -05:00
virtual ~SSD1306() = default;
2025-02-15 18:26:26 -05:00
void *vendor_config() override
{
return &ssd1306_config_;
}
2025-02-15 17:12:06 -05:00
// The configuration structure specific to the SSD1306.
esp_lcd_panel_ssd1306_config_t ssd1306_config_;
2025-02-15 10:11:49 -05:00
// 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];
2025-02-15 17:12:06 -05:00
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;
2025-02-15 10:11:49 -05:00
};
#endif // SSD1306_H