Skip to content

Commit 0547ef6

Browse files
committed
Update dotclock for IDF 5.0
1 parent 4087960 commit 0547ef6

File tree

8 files changed

+27
-47
lines changed

8 files changed

+27
-47
lines changed

ports/espressif/bindings/espidf/__init__.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "py/mpconfig.h"
3232
#include "py/obj.h"
3333

34+
#include "common-hal/espidf/__init__.h"
35+
3436
extern const mp_obj_type_t mp_type_espidf_IDFError;
3537
extern const mp_obj_type_t mp_type_espidf_MemoryError;
3638

ports/espressif/boards/adafruit_esp32s3_camera/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ CIRCUITPY_ONEWIREIO = 0
2323
CIRCUITPY_PARALLELDISPLAY = 0
2424
CIRCUITPY_RGBMATRIX = 0
2525
CIRCUITPY_ROTARYIO = 0
26+
27+
OPTIMIZATION_FLAGS = -Os

ports/espressif/boards/adafruit_qualia_s3_rgb666/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ USB_MANUFACTURER = "Adafruit"
66
IDF_TARGET = esp32s3
77

88
CIRCUITPY_ESP_FLASH_SIZE = 16MB
9-
CIRCUITPY_ESP_FLASH_MODE = dio
9+
CIRCUITPY_ESP_FLASH_MODE = qio
1010
CIRCUITPY_ESP_FLASH_FREQ = 80m
1111

1212
CIRCUITPY_ESP_PSRAM_SIZE = 8MB

ports/espressif/common-hal/dotclockframebuffer/DotClockFramebuffer.c

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,19 @@
3636
#include "hal/lcd_ll.h"
3737
#include "soc/lcd_periph.h"
3838

39-
// extract from esp-idf esp_lcd_rgb_panel.c
40-
typedef struct
41-
{
42-
esp_lcd_panel_t base; // Base class of generic lcd panel
43-
int panel_id; // LCD panel ID
44-
lcd_hal_context_t hal; // Hal layer object
45-
size_t data_width; // Number of data lines (e.g. for RGB565, the data width is 16)
46-
size_t sram_trans_align; // Alignment for framebuffer that allocated in SRAM
47-
size_t psram_trans_align; // Alignment for framebuffer that allocated in PSRAM
48-
int disp_gpio_num; // Display control GPIO, which is used to perform action like "disp_off"
49-
intr_handle_t intr; // LCD peripheral interrupt handle
50-
esp_pm_lock_handle_t pm_lock; // Power management lock
51-
size_t num_dma_nodes; // Number of DMA descriptors that used to carry the frame buffer
52-
uint8_t *fb; // Frame buffer
53-
size_t fb_size; // Size of frame buffer
54-
int data_gpio_nums[SOC_LCD_RGB_DATA_WIDTH]; // GPIOs used for data lines, we keep these GPIOs for action like "invert_color"
55-
size_t resolution_hz; // Peripheral clock resolution
56-
esp_lcd_rgb_timing_t timings; // RGB timing parameters (e.g. pclk, sync pulse, porch width)
57-
gdma_channel_handle_t dma_chan; // DMA channel handle
58-
esp_lcd_rgb_panel_frame_trans_done_cb_t on_frame_trans_done; // Callback, invoked after frame trans done
59-
void *user_ctx; // Reserved user's data of callback functions
60-
int x_gap; // Extra gap in x coordinate, it's used when calculate the flush window
61-
int y_gap; // Extra gap in y coordinate, it's used when calculate the flush window
62-
struct
63-
{
64-
unsigned int disp_en_level : 1; // The level which can turn on the screen by `disp_gpio_num`
65-
unsigned int stream_mode : 1; // If set, the LCD transfers data continuously, otherwise, it stops refreshing the LCD when transaction done
66-
unsigned int fb_in_psram : 1; // Whether the frame buffer is in PSRAM
67-
} flags;
68-
dma_descriptor_t dma_nodes[]; // DMA descriptor pool of size `num_dma_nodes`
69-
} esp_rgb_panel_t;
70-
71-
7239
#include "esp_log.h"
7340
#define TAG "LCD"
7441

7542
#include "components/esp_rom/include/esp_rom_sys.h"
7643

77-
44+
#include "bindings/espidf/__init__.h"
7845
#include "py/objarray.h"
7946
#include "shared-bindings/dotclockframebuffer/DotClockFramebuffer.h"
8047
#include "common-hal/dotclockframebuffer/DotClockFramebuffer.h"
81-
#include "bindings/espidf/__init__.h"
48+
#include "common-hal/espidf/__init__.h"
8249
#include "shared-bindings/microcontroller/Pin.h"
8350
#include "py/runtime.h"
8451
#include "components/driver/include/driver/gpio.h"
85-
#include "components/driver/include/driver/periph_ctrl.h"
86-
#include "components/driver/include/esp_private/gdma.h"
8752
#include "components/esp_rom/include/esp_rom_gpio.h"
8853
#include "components/hal/esp32s3/include/hal/lcd_ll.h"
8954
#include "components/hal/include/hal/gpio_hal.h"
@@ -170,6 +135,7 @@ void common_hal_dotclockframebuffer_framebuffer_construct(dotclockframebuffer_fr
170135
cfg->vsync_gpio_num = valid_pin(vsync, MP_QSTR_vsync);
171136
cfg->de_gpio_num = valid_pin(de, MP_QSTR_de);
172137
cfg->pclk_gpio_num = valid_pin(dclk, MP_QSTR_dclk);
138+
cfg->clk_src = LCD_CLK_SRC_DEFAULT;
173139

174140
cfg->data_gpio_nums[0] = valid_pin(blue[0], MP_QSTR_blue);
175141
cfg->data_gpio_nums[1] = valid_pin(blue[1], MP_QSTR_blue);
@@ -193,22 +159,24 @@ void common_hal_dotclockframebuffer_framebuffer_construct(dotclockframebuffer_fr
193159
cfg->disp_gpio_num = GPIO_NUM_NC;
194160

195161
cfg->flags.disp_active_low = 0;
196-
cfg->flags.relax_on_idle = 0;
162+
cfg->flags.refresh_on_demand = 0;
197163
cfg->flags.fb_in_psram = 1; // allocate frame buffer in PSRAM
198164

199-
ESP_ERROR_CHECK(esp_lcd_new_rgb_panel(&self->panel_config, &self->panel_handle));
200-
ESP_ERROR_CHECK(esp_lcd_panel_reset(self->panel_handle));
201-
ESP_ERROR_CHECK(esp_lcd_panel_init(self->panel_handle));
165+
esp_err_t ret = esp_lcd_new_rgb_panel(&self->panel_config, &self->panel_handle);
166+
cp_check_esp_error(ret);
167+
cp_check_esp_error(esp_lcd_panel_reset(self->panel_handle));
168+
cp_check_esp_error(esp_lcd_panel_init(self->panel_handle));
202169

203170
uint16_t color = 0;
204-
ESP_ERROR_CHECK(self->panel_handle->draw_bitmap(self->panel_handle, 0, 0, 1, 1, &color));
171+
cp_check_esp_error(self->panel_handle->draw_bitmap(self->panel_handle, 0, 0, 1, 1, &color));
205172

206-
esp_rgb_panel_t *_rgb_panel = __containerof(self->panel_handle, esp_rgb_panel_t, base);
173+
void *fb;
174+
cp_check_esp_error(esp_lcd_rgb_panel_get_frame_buffer(self->panel_handle, 1, &fb));
207175

208176
self->frequency = frequency;
209177
self->row_stride = 2 * (width + overscan_left);
210178
self->refresh_rate = frequency / (width + hsync_front_porch + hsync_back_porch) / (height + vsync_front_porch + vsync_back_porch);
211-
self->bufinfo.buf = (uint8_t *)_rgb_panel->fb + 2 * overscan_left; // first line starts ater overscan_left pixels
179+
self->bufinfo.buf = (uint8_t *)fb + 2 * overscan_left; // first line starts after overscan_left pixels
212180
self->bufinfo.len = 2 * (cfg->timings.h_res * cfg->timings.v_res - overscan_left); // no overscan after last line
213181
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
214182

ports/espressif/common-hal/espidf/__init__.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,11 @@ void raise_esp_error(esp_err_t err) {
188188
mp_raise_msg_varg(exception_type, translate("%s error 0x%x"), group, err);
189189
}
190190

191+
void cp_check_esp_error(esp_err_t err) {
192+
if (err == ESP_OK) {
193+
return;
194+
}
195+
raise_esp_error(err);
196+
}
197+
191198
MP_REGISTER_MODULE(MP_QSTR_espidf, espidf_module);

ports/espressif/common-hal/espidf/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626

2727
#pragma once
2828

29-
#include "bindings/espidf/__init__.h"
29+
void cp_check_esp_error(esp_err_t err);

ports/espressif/esp-idf

ports/espressif/supervisor/port.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ safe_mode_t port_init(void) {
284284
#endif
285285

286286
#if ENABLE_JTAG
287+
ESP_LOGI(TAG, "Marking JTAG pins never_reset")
287288
// JTAG
288289
#ifdef CONFIG_IDF_TARGET_ESP32C3
289290
common_hal_never_reset_pin(&pin_GPIO4);

0 commit comments

Comments
 (0)