84 lines
2.7 KiB
C
Raw Normal View History

2025-02-16 07:21:16 -05:00
/*
* https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/lcd/index.html#functional-overview
*
* Implementing the interface draw to an LCD using various interface modes.
* I2C interface mode is SSD1306
* SPI interface mode is ST7789
* I80 interface mode is NT35510 or ST7789
*
* Actually, I think any driver can be used with any interface mode
* Along with additional third party drivers via the component manager
* https://github.com/espressif/esp-idf/tree/0d6099ec533c4b647fb7a7b0b8942bc7aeb82f90/examples/peripherals/lcd/spi_lcd_touch#spi-lcd-and-touch-panel-example
*/
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 specific display hardware.
2025-02-15 10:11:49 -05:00
// 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 LCD_H_RES 128
#define LCD_V_RES 64
2025-02-15 10:11:49 -05:00
#define I2C_HW_ADDR 0x3C
#define LCD_PIXEL_CLOCK_HZ (400 * 1000)
2025-02-16 09:38:28 -05:00
// Bit number used to represent command and parameter
2025-02-15 10:11:49 -05:00
#define LCD_CMD_BITS 8
#define LCD_PARAM_BITS 8
2025-02-16 09:38:28 -05:00
class SSD1306 final : 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
) :
IPanelDevice(i2c,
(esp_lcd_panel_io_i2c_config_t) {
.dev_addr = I2C_HW_ADDR,
.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) { }
2025-02-15 17:12:06 -05:00
2025-02-16 09:38:28 -05:00
~SSD1306() final = default;
2025-02-15 17:12:06 -05:00
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,
2025-02-16 07:21:16 -05:00
esp_lcd_panel_handle_t &panel) override
{
ESP_ERROR_CHECK(esp_lcd_new_panel_ssd1306(io, &config, &panel));
}
2025-02-15 10:11:49 -05:00
};
#endif // SSD1306_H