|
| 1 | +// ESP_LCD_Panel implementation for esp32s3. |
| 2 | + |
1 | 3 | #include "Arduino_ESP32RGBPanel.h"
|
2 | 4 |
|
3 | 5 | #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
|
@@ -129,5 +131,100 @@ uint16_t *Arduino_ESP32RGBPanel::getFrameBuffer(int16_t w, int16_t h)
|
129 | 131 |
|
130 | 132 | return (uint16_t *)_rgb_panel->fb;
|
131 | 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; |
| 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 | + |
132 | 229 | #endif // #if (!defined(ESP_ARDUINO_VERSION_MAJOR)) || (ESP_ARDUINO_VERSION_MAJOR < 3)
|
133 | 230 | #endif // #if defined(ESP32) && (CONFIG_IDF_TARGET_ESP32S3)
|
0 commit comments