Skip to content

Commit 72f56a2

Browse files
combine code in different ESP_ARDUINO_VERSION_MAJOR
1 parent c4664a6 commit 72f56a2

File tree

2 files changed

+69
-205
lines changed

2 files changed

+69
-205
lines changed

src/databus/Arduino_ESP32RGBPanel.cpp

Lines changed: 60 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include "Arduino_ESP32RGBPanel.h"
44

55
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
6-
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
7-
86
Arduino_ESP32RGBPanel::Arduino_ESP32RGBPanel(
97
int8_t de, int8_t vsync, int8_t hsync, int8_t pclk,
108
int8_t r0, int8_t r1, int8_t r2, int8_t r3, int8_t r4,
@@ -45,143 +43,12 @@ bool Arduino_ESP32RGBPanel::begin(int32_t speed)
4543

4644
uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
4745
{
48-
esp_lcd_rgb_panel_config_t *_panel_config = (esp_lcd_rgb_panel_config_t *)heap_caps_calloc(1, sizeof(esp_lcd_rgb_panel_config_t), MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL);
49-
50-
_panel_config->clk_src = LCD_CLK_SRC_PLL160M;
51-
_panel_config->timings.pclk_hz = (_prefer_speed == GFX_NOT_DEFINED) ? _speed : _prefer_speed;
52-
_panel_config->timings.h_res = w;
53-
_panel_config->timings.v_res = h;
54-
// The following parameters should refer to LCD spec
55-
_panel_config->timings.hsync_pulse_width = _hsync_pulse_width;
56-
_panel_config->timings.hsync_back_porch = _hsync_back_porch;
57-
_panel_config->timings.hsync_front_porch = _hsync_front_porch;
58-
_panel_config->timings.vsync_pulse_width = _vsync_pulse_width;
59-
_panel_config->timings.vsync_back_porch = _vsync_back_porch;
60-
_panel_config->timings.vsync_front_porch = _vsync_front_porch;
61-
_panel_config->timings.flags.hsync_idle_low = (_hsync_polarity == 0) ? 1 : 0;
62-
_panel_config->timings.flags.vsync_idle_low = (_vsync_polarity == 0) ? 1 : 0;
63-
_panel_config->timings.flags.de_idle_high = _de_idle_high;
64-
_panel_config->timings.flags.pclk_active_neg = _pclk_active_neg;
65-
_panel_config->timings.flags.pclk_idle_high = _pclk_idle_high;
66-
67-
_panel_config->data_width = 16; // RGB565 in parallel mode, thus 16bit in width
68-
_panel_config->sram_trans_align = 8;
69-
_panel_config->psram_trans_align = 64;
70-
_panel_config->hsync_gpio_num = _hsync;
71-
_panel_config->vsync_gpio_num = _vsync;
72-
_panel_config->de_gpio_num = _de;
73-
_panel_config->pclk_gpio_num = _pclk;
74-
75-
if (_useBigEndian)
76-
{
77-
_panel_config->data_gpio_nums[0] = _g3;
78-
_panel_config->data_gpio_nums[1] = _g4;
79-
_panel_config->data_gpio_nums[2] = _g5;
80-
_panel_config->data_gpio_nums[3] = _r0;
81-
_panel_config->data_gpio_nums[4] = _r1;
82-
_panel_config->data_gpio_nums[5] = _r2;
83-
_panel_config->data_gpio_nums[6] = _r3;
84-
_panel_config->data_gpio_nums[7] = _r4;
85-
_panel_config->data_gpio_nums[8] = _b0;
86-
_panel_config->data_gpio_nums[9] = _b1;
87-
_panel_config->data_gpio_nums[10] = _b2;
88-
_panel_config->data_gpio_nums[11] = _b3;
89-
_panel_config->data_gpio_nums[12] = _b4;
90-
_panel_config->data_gpio_nums[13] = _g0;
91-
_panel_config->data_gpio_nums[14] = _g1;
92-
_panel_config->data_gpio_nums[15] = _g2;
93-
}
94-
else
95-
{
96-
_panel_config->data_gpio_nums[0] = _b0;
97-
_panel_config->data_gpio_nums[1] = _b1;
98-
_panel_config->data_gpio_nums[2] = _b2;
99-
_panel_config->data_gpio_nums[3] = _b3;
100-
_panel_config->data_gpio_nums[4] = _b4;
101-
_panel_config->data_gpio_nums[5] = _g0;
102-
_panel_config->data_gpio_nums[6] = _g1;
103-
_panel_config->data_gpio_nums[7] = _g2;
104-
_panel_config->data_gpio_nums[8] = _g3;
105-
_panel_config->data_gpio_nums[9] = _g4;
106-
_panel_config->data_gpio_nums[10] = _g5;
107-
_panel_config->data_gpio_nums[11] = _r0;
108-
_panel_config->data_gpio_nums[12] = _r1;
109-
_panel_config->data_gpio_nums[13] = _r2;
110-
_panel_config->data_gpio_nums[14] = _r3;
111-
_panel_config->data_gpio_nums[15] = _r4;
112-
}
113-
114-
_panel_config->disp_gpio_num = GPIO_NUM_NC;
115-
116-
_panel_config->flags.disp_active_low = 0;
117-
_panel_config->flags.relax_on_idle = 0;
118-
_panel_config->flags.fb_in_psram = 1; // allocate frame buffer in PSRAM
119-
120-
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(_panel_config, &_panel_handle));
121-
ESP_ERROR_CHECK(esp_lcd_panel_reset(_panel_handle));
122-
ESP_ERROR_CHECK(esp_lcd_panel_init(_panel_handle));
123-
124-
uint16_t color = random(0xffff);
125-
ESP_ERROR_CHECK(_panel_handle->draw_bitmap(_panel_handle, 0, 0, 1, 1, &color));
126-
127-
_rgb_panel = __containerof(_panel_handle, esp_rgb_panel_t, base);
128-
129-
LCD_CAM.lcd_ctrl2.lcd_vsync_idle_pol = _vsync_polarity;
130-
LCD_CAM.lcd_ctrl2.lcd_hsync_idle_pol = _hsync_polarity;
131-
132-
return (uint16_t *)_rgb_panel->fb;
133-
}
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;
46+
esp_lcd_rgb_panel_config_t panel_config = {
47+
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
48+
.clk_src = LCD_CLK_SRC_PLL160M,
16649
#else
167-
_speed = 12000000L;
50+
.clk_src = LCD_CLK_SRC_DEFAULT,
16851
#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
18552
.timings = {
18653
.pclk_hz = (_prefer_speed == GFX_NOT_DEFINED) ? _speed : _prefer_speed,
18754
.h_res = w,
@@ -198,33 +65,81 @@ uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
19865
.de_idle_high = _de_idle_high,
19966
.pclk_active_neg = _pclk_active_neg,
20067
.pclk_idle_high = _pclk_idle_high,
201-
}},
68+
},
69+
},
20270
.data_width = 16, // RGB565 in parallel mode, thus 16 bits in width
71+
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
72+
#else
20373
.bits_per_pixel = 16,
20474
.num_fbs = 1,
205-
75+
#endif
20676
.sram_trans_align = 8,
20777
.psram_trans_align = 64,
20878
.hsync_gpio_num = _hsync,
20979
.vsync_gpio_num = _vsync,
21080
.de_gpio_num = _de,
21181
.pclk_gpio_num = _pclk,
21282
.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-
21583
.flags = {
21684
.fb_in_psram = true, // allocate frame buffer from PSRAM
217-
}};
85+
},
86+
};
87+
88+
if (_useBigEndian)
89+
{
90+
panel_config.data_gpio_nums[0] = _g3;
91+
panel_config.data_gpio_nums[1] = _g4;
92+
panel_config.data_gpio_nums[2] = _g5;
93+
panel_config.data_gpio_nums[3] = _r0;
94+
panel_config.data_gpio_nums[4] = _r1;
95+
panel_config.data_gpio_nums[5] = _r2;
96+
panel_config.data_gpio_nums[6] = _r3;
97+
panel_config.data_gpio_nums[7] = _r4;
98+
panel_config.data_gpio_nums[8] = _b0;
99+
panel_config.data_gpio_nums[9] = _b1;
100+
panel_config.data_gpio_nums[10] = _b2;
101+
panel_config.data_gpio_nums[11] = _b3;
102+
panel_config.data_gpio_nums[12] = _b4;
103+
panel_config.data_gpio_nums[13] = _g0;
104+
panel_config.data_gpio_nums[14] = _g1;
105+
panel_config.data_gpio_nums[15] = _g2;
106+
}
107+
else
108+
{
109+
panel_config.data_gpio_nums[0] = _b0;
110+
panel_config.data_gpio_nums[1] = _b1;
111+
panel_config.data_gpio_nums[2] = _b2;
112+
panel_config.data_gpio_nums[3] = _b3;
113+
panel_config.data_gpio_nums[4] = _b4;
114+
panel_config.data_gpio_nums[5] = _g0;
115+
panel_config.data_gpio_nums[6] = _g1;
116+
panel_config.data_gpio_nums[7] = _g2;
117+
panel_config.data_gpio_nums[8] = _g3;
118+
panel_config.data_gpio_nums[9] = _g4;
119+
panel_config.data_gpio_nums[10] = _g5;
120+
panel_config.data_gpio_nums[11] = _r0;
121+
panel_config.data_gpio_nums[12] = _r1;
122+
panel_config.data_gpio_nums[13] = _r2;
123+
panel_config.data_gpio_nums[14] = _r3;
124+
panel_config.data_gpio_nums[15] = _r4;
125+
}
218126

219127
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&panel_config, &_panel_handle));
220128

221129
ESP_ERROR_CHECK(esp_lcd_panel_reset(_panel_handle));
222130
ESP_ERROR_CHECK(esp_lcd_panel_init(_panel_handle));
223131

224-
ESP_ERROR_CHECK(esp_lcd_rgb_panel_get_frame_buffer(_panel_handle, buffers, &frame_buffer));
132+
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
133+
esp_rgb_panel_t *_rgb_panel;
134+
_rgb_panel = __containerof(_panel_handle, esp_rgb_panel_t, base);
135+
136+
return (uint16_t *)_rgb_panel->fb;
137+
#else
138+
void *frame_buffer = nullptr;
139+
ESP_ERROR_CHECK(esp_lcd_rgb_panel_get_frame_buffer(_panel_handle, 1, &frame_buffer));
225140

226141
return ((uint16_t *)frame_buffer);
227-
} // getFrameBuffer
142+
#endif
143+
}
228144

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

src/databus/Arduino_ESP32RGBPanel.h

Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
#include "Arduino_DataBus.h"
1919

2020
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
21-
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
2221

23-
#include "esp_lcd_panel_io.h"
2422
#include "esp_lcd_panel_rgb.h"
25-
#include "esp_lcd_panel_vendor.h"
2623
#include "esp_lcd_panel_ops.h"
24+
25+
#include "esp32s3/rom/cache.h"
26+
// This function is located in ROM (also see esp_rom/${target}/ld/${target}.rom.ld)
27+
extern int Cache_WriteBack_Addr(uint32_t addr, uint32_t size);
28+
29+
#if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
30+
#include "esp_lcd_panel_io.h"
31+
#include "esp_lcd_panel_vendor.h"
2732
#include "esp_lcd_panel_interface.h"
2833
#include "esp_private/gdma.h"
2934
#include "esp_pm.h"
@@ -32,9 +37,6 @@
3237
#include "hal/lcd_hal.h"
3338
#include "hal/lcd_ll.h"
3439

35-
#include "esp32s3/rom/cache.h"
36-
// This function is located in ROM (also see esp_rom/${target}/ld/${target}.rom.ld)
37-
extern int Cache_WriteBack_Addr(uint32_t addr, uint32_t size);
3840

3941
// extract from esp-idf esp_lcd_rgb_panel.c
4042
struct esp_rgb_panel_t
@@ -67,6 +69,7 @@ struct esp_rgb_panel_t
6769
} flags;
6870
dma_descriptor_t dma_nodes[]; // DMA descriptor pool of size `num_dma_nodes`
6971
};
72+
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
7073

7174
class Arduino_ESP32RGBPanel
7275
{
@@ -107,60 +110,6 @@ class Arduino_ESP32RGBPanel
107110
uint16_t _pclk_idle_high;
108111

109112
esp_lcd_panel_handle_t _panel_handle = NULL;
110-
esp_rgb_panel_t *_rgb_panel;
111113
};
112114

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-
165-
#endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
166115
#endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)

0 commit comments

Comments
 (0)