3
3
#include " Arduino_ESP32RGBPanel.h"
4
4
5
5
#if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
6
- #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
7
-
8
6
Arduino_ESP32RGBPanel::Arduino_ESP32RGBPanel (
9
7
int8_t de, int8_t vsync, int8_t hsync, int8_t pclk,
10
8
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)
45
43
46
44
uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer (int16_t w, int16_t h)
47
45
{
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,
166
49
#else
167
- _speed = 12000000L ;
50
+ . clk_src = LCD_CLK_SRC_DEFAULT,
168
51
#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
52
.timings = {
186
53
.pclk_hz = (_prefer_speed == GFX_NOT_DEFINED) ? _speed : _prefer_speed,
187
54
.h_res = w,
@@ -198,33 +65,81 @@ uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
198
65
.de_idle_high = _de_idle_high,
199
66
.pclk_active_neg = _pclk_active_neg,
200
67
.pclk_idle_high = _pclk_idle_high,
201
- }},
68
+ },
69
+ },
202
70
.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
203
73
.bits_per_pixel = 16 ,
204
74
.num_fbs = 1 ,
205
-
75
+ # endif
206
76
.sram_trans_align = 8 ,
207
77
.psram_trans_align = 64 ,
208
78
.hsync_gpio_num = _hsync,
209
79
.vsync_gpio_num = _vsync,
210
80
.de_gpio_num = _de,
211
81
.pclk_gpio_num = _pclk,
212
82
.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
83
.flags = {
216
84
.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
+ }
218
126
219
127
ESP_ERROR_CHECK (esp_lcd_new_rgb_panel (&panel_config, &_panel_handle));
220
128
221
129
ESP_ERROR_CHECK (esp_lcd_panel_reset (_panel_handle));
222
130
ESP_ERROR_CHECK (esp_lcd_panel_init (_panel_handle));
223
131
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));
225
140
226
141
return ((uint16_t *)frame_buffer);
227
- } // getFrameBuffer
142
+ #endif
143
+ }
228
144
229
- #endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
230
145
#endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
0 commit comments