36
36
#include "hal/lcd_ll.h"
37
37
#include "soc/lcd_periph.h"
38
38
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
-
72
39
#include "esp_log.h"
73
40
#define TAG "LCD"
74
41
75
42
#include "components/esp_rom/include/esp_rom_sys.h"
76
43
77
-
44
+ #include "bindings/espidf/__init__.h"
78
45
#include "py/objarray.h"
79
46
#include "shared-bindings/dotclockframebuffer/DotClockFramebuffer.h"
80
47
#include "common-hal/dotclockframebuffer/DotClockFramebuffer.h"
81
- #include "bindings /espidf/__init__.h"
48
+ #include "common-hal /espidf/__init__.h"
82
49
#include "shared-bindings/microcontroller/Pin.h"
83
50
#include "py/runtime.h"
84
51
#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"
87
52
#include "components/esp_rom/include/esp_rom_gpio.h"
88
53
#include "components/hal/esp32s3/include/hal/lcd_ll.h"
89
54
#include "components/hal/include/hal/gpio_hal.h"
@@ -170,6 +135,7 @@ void common_hal_dotclockframebuffer_framebuffer_construct(dotclockframebuffer_fr
170
135
cfg -> vsync_gpio_num = valid_pin (vsync , MP_QSTR_vsync );
171
136
cfg -> de_gpio_num = valid_pin (de , MP_QSTR_de );
172
137
cfg -> pclk_gpio_num = valid_pin (dclk , MP_QSTR_dclk );
138
+ cfg -> clk_src = LCD_CLK_SRC_DEFAULT ;
173
139
174
140
cfg -> data_gpio_nums [0 ] = valid_pin (blue [0 ], MP_QSTR_blue );
175
141
cfg -> data_gpio_nums [1 ] = valid_pin (blue [1 ], MP_QSTR_blue );
@@ -193,22 +159,24 @@ void common_hal_dotclockframebuffer_framebuffer_construct(dotclockframebuffer_fr
193
159
cfg -> disp_gpio_num = GPIO_NUM_NC ;
194
160
195
161
cfg -> flags .disp_active_low = 0 ;
196
- cfg -> flags .relax_on_idle = 0 ;
162
+ cfg -> flags .refresh_on_demand = 0 ;
197
163
cfg -> flags .fb_in_psram = 1 ; // allocate frame buffer in PSRAM
198
164
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 ));
202
169
203
170
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 ));
205
172
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 ));
207
175
208
176
self -> frequency = frequency ;
209
177
self -> row_stride = 2 * (width + overscan_left );
210
178
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
212
180
self -> bufinfo .len = 2 * (cfg -> timings .h_res * cfg -> timings .v_res - overscan_left ); // no overscan after last line
213
181
self -> bufinfo .typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW ;
214
182
0 commit comments