Skip to content

Commit b3c573e

Browse files
committed
Arduino_RGB_Display implementation for board version 3.x
1 parent 4f9ca9b commit b3c573e

File tree

4 files changed

+169
-4
lines changed

4 files changed

+169
-4
lines changed

src/databus/Arduino_ESP32RGBPanel.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ESP_LCD_Panel implementation for esp32s3.
2+
13
#include "Arduino_ESP32RGBPanel.h"
24

35
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
@@ -129,5 +131,103 @@ uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
129131

130132
return (uint16_t *)_rgb_panel->fb;
131133
}
134+
135+
136+
#else
137+
138+
// Implementation for ESP32 board version 3.x
139+
// no need to include a copy of core esp32 types any more.
140+
141+
Arduino_ESP32RGBPanel::Arduino_ESP32RGBPanel(
142+
int8_t de, int8_t vsync, int8_t hsync, int8_t pclk,
143+
int8_t r0, int8_t r1, int8_t r2, int8_t r3, int8_t r4,
144+
int8_t g0, int8_t g1, int8_t g2, int8_t g3, int8_t g4, int8_t g5,
145+
int8_t b0, int8_t b1, int8_t b2, int8_t b3, int8_t b4,
146+
uint16_t hsync_polarity, uint16_t hsync_front_porch, uint16_t hsync_pulse_width, uint16_t hsync_back_porch,
147+
uint16_t vsync_polarity, uint16_t vsync_front_porch, uint16_t vsync_pulse_width, uint16_t vsync_back_porch,
148+
uint16_t pclk_active_neg, int32_t prefer_speed, bool useBigEndian,
149+
uint16_t de_idle_high, uint16_t pclk_idle_high)
150+
: _de(de), _vsync(vsync), _hsync(hsync), _pclk(pclk),
151+
_r0(r0), _r1(r1), _r2(r2), _r3(r3), _r4(r4),
152+
_g0(g0), _g1(g1), _g2(g2), _g3(g3), _g4(g4), _g5(g5),
153+
_b0(b0), _b1(b1), _b2(b2), _b3(b3), _b4(b4),
154+
_hsync_polarity(hsync_polarity), _hsync_front_porch(hsync_front_porch), _hsync_pulse_width(hsync_pulse_width), _hsync_back_porch(hsync_back_porch),
155+
_vsync_polarity(vsync_polarity), _vsync_front_porch(vsync_front_porch), _vsync_pulse_width(vsync_pulse_width), _vsync_back_porch(vsync_back_porch),
156+
_pclk_active_neg(pclk_active_neg), _prefer_speed(prefer_speed), _useBigEndian(useBigEndian),
157+
_de_idle_high(de_idle_high), _pclk_idle_high(pclk_idle_high)
158+
{
159+
}
160+
161+
bool Arduino_ESP32RGBPanel::begin(int32_t speed)
162+
{
163+
if (speed == GFX_NOT_DEFINED)
164+
{
165+
#ifdef CONFIG_SPIRAM_MODE_QUAD
166+
_speed = 6000000L;
167+
#else
168+
_speed = 12000000L;
169+
#endif
170+
}
171+
else
172+
{
173+
_speed = speed;
174+
}
175+
176+
return true;
177+
}
178+
179+
uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
180+
{
181+
uint32_t buffers = 1;
182+
void *frame_buffer = nullptr;
183+
184+
esp_lcd_rgb_panel_config_t panel_config = {
185+
.clk_src = LCD_CLK_SRC_DEFAULT, // = LCD_CLK_SRC_PLL160M
186+
.timings = {
187+
.pclk_hz = (_prefer_speed == GFX_NOT_DEFINED) ? _speed : _prefer_speed,
188+
.h_res = w,
189+
.v_res = h,
190+
.hsync_pulse_width = _hsync_pulse_width,
191+
.hsync_back_porch = _hsync_back_porch,
192+
.hsync_front_porch = _hsync_front_porch,
193+
.vsync_pulse_width = _vsync_pulse_width,
194+
.vsync_back_porch = _vsync_back_porch,
195+
.vsync_front_porch = _vsync_front_porch,
196+
// struct {
197+
// uint32_t hsync_idle_low: 1; /*!< The hsync signal is low in IDLE state */
198+
// uint32_t vsync_idle_low: 1; /*!< The vsync signal is low in IDLE state */
199+
// uint32_t de_idle_high: 1; /*!< The de signal is high in IDLE state */
200+
// uint32_t pclk_active_neg: 1; /*!< Whether the display data is clocked out on the falling edge of PCLK */
201+
// uint32_t pclk_idle_high: 1; /*!< The PCLK stays at high level in IDLE phase */
202+
// } flags; /*!< LCD RGB timing flags */
203+
204+
},
205+
.data_width = 16, // RGB565 in parallel mode, thus 16 bits in width
206+
.bits_per_pixel = 16,
207+
.num_fbs = 1,
208+
209+
.sram_trans_align = 8,
210+
.psram_trans_align = 64,
211+
.hsync_gpio_num = _hsync,
212+
.vsync_gpio_num = _vsync,
213+
.de_gpio_num = _de,
214+
.pclk_gpio_num = _pclk,
215+
.disp_gpio_num = GPIO_NUM_NC, // -1
216+
.data_gpio_nums = {_b0, _b1, _b2, _b3, _b4, _g0, _g1, _g2, _g3, _g4, _g5, _r0, _r1, _r2, _r3, _r4},
217+
218+
.flags = {
219+
.fb_in_psram = true, // allocate frame buffer from PSRAM
220+
}};
221+
222+
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_config, &_panel_handle));
223+
224+
ESP_ERROR_CHECK(esp_lcd_panel_reset(_panel_handle));
225+
ESP_ERROR_CHECK(esp_lcd_panel_init(_panel_handle));
226+
227+
ESP_ERROR_CHECK(esp_lcd_rgb_panel_get_frame_buffer(_panel_handle, buffers, &frame_buffer));
228+
229+
return ((uint16_t *)frame_buffer);
230+
} // getFrameBuffer
231+
132232
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
133233
#endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)

src/databus/Arduino_ESP32RGBPanel.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#pragma once
22

3+
// ESP_LCD_Panel implementation for esp32s3.
4+
5+
// This panel implementation requires a hardware setup with
6+
// * RGB LCD peripheral supported (esps3 for now)
7+
// * Octal PSRAM onboard
8+
// * RGB panel, 16 bit-width, with HSYNC, VSYNC and DE signal
9+
//
10+
// It uses a Single Frame Buffer in PSRAM
11+
//
12+
// See: (ESP32 board version 3.x)
13+
// * https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/api-reference/peripherals/lcd/rgb_lcd.html
14+
// * https://github.com/espressif/esp-idf/blob/master/examples/peripherals/lcd/rgb_panel/README.md
15+
//
16+
// The prior implementation (ESP32 board version 2.x) was largely undocumented.
17+
318
#include "Arduino_DataBus.h"
419

520
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
@@ -95,5 +110,59 @@ class Arduino_ESP32RGBPanel
95110
esp_rgb_panel_t *_rgb_panel;
96111
};
97112

113+
#else
114+
115+
// Implementation for ESP32 board version 3.x
116+
// no need to include a copy of core esp32 types any more.
117+
118+
#include "esp_lcd_panel_rgb.h"
119+
#include "esp_lcd_panel_ops.h"
120+
121+
#include "esp32s3/rom/cache.h"
122+
// This function is located in ROM (also see esp_rom/${target}/ld/${target}.rom.ld)
123+
extern int Cache_WriteBack_Addr(uint32_t addr, uint32_t size);
124+
125+
class Arduino_ESP32RGBPanel
126+
{
127+
public:
128+
Arduino_ESP32RGBPanel(
129+
int8_t de, int8_t vsync, int8_t hsync, int8_t pclk,
130+
int8_t r0, int8_t r1, int8_t r2, int8_t r3, int8_t r4,
131+
int8_t g0, int8_t g1, int8_t g2, int8_t g3, int8_t g4, int8_t g5,
132+
int8_t b0, int8_t b1, int8_t b2, int8_t b3, int8_t b4,
133+
uint16_t hsync_polarity, uint16_t hsync_front_porch, uint16_t hsync_pulse_width, uint16_t hsync_back_porch,
134+
uint16_t vsync_polarity, uint16_t vsync_front_porch, uint16_t vsync_pulse_width, uint16_t vsync_back_porch,
135+
uint16_t pclk_active_neg = 0, int32_t prefer_speed = GFX_NOT_DEFINED, bool useBigEndian = false,
136+
uint16_t de_idle_high = 0, uint16_t pclk_idle_high = 0);
137+
138+
bool begin(int32_t speed = GFX_NOT_DEFINED);
139+
140+
uint16_t *getFrameBuffer(int16_t w, int16_t h);
141+
142+
protected:
143+
private:
144+
int32_t _speed;
145+
int8_t _de, _vsync, _hsync, _pclk;
146+
int8_t _r0, _r1, _r2, _r3, _r4;
147+
int8_t _g0, _g1, _g2, _g3, _g4, _g5;
148+
int8_t _b0, _b1, _b2, _b3, _b4;
149+
uint16_t _hsync_polarity;
150+
uint16_t _hsync_front_porch;
151+
uint16_t _hsync_pulse_width;
152+
uint16_t _hsync_back_porch;
153+
uint16_t _vsync_polarity;
154+
uint16_t _vsync_front_porch;
155+
uint16_t _vsync_pulse_width;
156+
uint16_t _vsync_back_porch;
157+
uint16_t _pclk_active_neg;
158+
int32_t _prefer_speed;
159+
bool _useBigEndian;
160+
uint16_t _de_idle_high;
161+
uint16_t _pclk_idle_high;
162+
163+
esp_lcd_panel_handle_t _panel_handle = NULL;
164+
esp_lcd_rgb_panel_config_t *_rgb_panel;
165+
};
166+
98167
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
99168
#endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)

src/display/Arduino_RGB_Display.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "../Arduino_DataBus.h"
22

33
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
4-
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
54

65
#include "../Arduino_GFX.h"
76
#include "Arduino_RGB_Display.h"
@@ -519,5 +518,4 @@ uint16_t *Arduino_RGB_Display::getFramebuffer()
519518
return _framebuffer;
520519
}
521520

522-
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
523521
#endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)

src/display/Arduino_RGB_Display.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "../Arduino_DataBus.h"
44

55
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
6-
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
76

87
#include "../Arduino_GFX.h"
98
#include "../databus/Arduino_ESP32RGBPanel.h"
@@ -2298,5 +2297,4 @@ class Arduino_RGB_Display : public Arduino_GFX
22982297
private:
22992298
};
23002299

2301-
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
23022300
#endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)

0 commit comments

Comments
 (0)