Skip to content

Commit 1005ca3

Browse files
Merge pull request #558 from mathertel/master
New Arduino_RGB_Display implementation for board version 3.x
2 parents b3b99a5 + 692c7c2 commit 1005ca3

File tree

4 files changed

+164
-4
lines changed

4 files changed

+164
-4
lines changed

src/databus/Arduino_ESP32RGBPanel.cpp

Lines changed: 97 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,100 @@ uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
129131

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

src/databus/Arduino_ESP32RGBPanel.h

Lines changed: 67 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,57 @@ 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+
uint16_t _de_idle_high;
160+
uint16_t _pclk_idle_high;
161+
162+
esp_lcd_panel_handle_t _panel_handle = NULL;
163+
};
164+
98165
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
99166
#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)