|
9 | 9 | #include "mphalport.h" |
10 | 10 | #include "py/obj.h" |
11 | 11 | #include "py/runtime.h" |
| 12 | +#include "py/binary.h" |
12 | 13 |
|
13 | 14 | // stdlib includes |
14 | 15 | #include <string.h> |
|
23 | 24 | #include "esp_lcd_panel_io.h" |
24 | 25 | #include "esp_heap_caps.h" |
25 | 26 | #include "hal/lcd_types.h" |
26 | | - #include "esp_lcd_mipi_dsi.h" |
27 | 27 |
|
28 | | - |
29 | 28 | typedef struct { |
30 | 29 | esp_lcd_panel_t base; // Base class of generic lcd panel |
31 | 30 | esp_lcd_dsi_bus_handle_t bus; // DSI bus handle |
|
39 | 38 | mp_lcd_err_t dsi_del(mp_obj_t obj); |
40 | 39 | mp_lcd_err_t dsi_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp, uint32_t buffer_size, bool rgb565_byte_swap, uint8_t cmd_bits, uint8_t param_bits); |
41 | 40 | mp_lcd_err_t dsi_get_lane_count(mp_obj_t obj, uint8_t *lane_count); |
42 | | - mp_lcd_err_t dsi_tx_color(mp_obj_t obj, int lcd_cmd, void *color, size_t color_size, int x_start, int y_start, int x_end, int y_end, , uint8_t rotation, bool last_update); |
| 41 | + mp_lcd_err_t dsi_tx_color(mp_obj_t obj, int lcd_cmd, void *color, size_t color_size, int x_start, int y_start, int x_end, int y_end, uint8_t rotation, bool last_update); |
43 | 42 | mp_obj_t dsi_allocate_framebuffer(mp_obj_t obj, uint32_t size, uint32_t caps); |
44 | 43 | mp_obj_t dsi_free_framebuffer(mp_obj_t obj, mp_obj_t buf); |
45 | 44 |
|
|
67 | 66 | enum { |
68 | 67 | ARG_bus_id, |
69 | 68 | ARG_data_lanes, |
70 | | - ARG_freq, |
| 69 | + ARG_lane_bitrate, |
| 70 | + ARG_clock_freq, |
71 | 71 | ARG_virtual_channel, |
72 | 72 | ARG_hsync_front_porch, |
73 | 73 | ARG_hsync_back_porch, |
|
80 | 80 | const mp_arg_t make_new_args[] = { |
81 | 81 | { MP_QSTR_bus_id, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, |
82 | 82 | { MP_QSTR_data_lanes, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, |
83 | | - { MP_QSTR_freq, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, |
| 83 | + { MP_QSTR_lane_bitrate, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, |
| 84 | + { MP_QSTR_clock_freq, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, |
84 | 85 | { MP_QSTR_virtual_channel, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, |
85 | 86 | { MP_QSTR_hsync_front_porch, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } }, |
86 | 87 | { MP_QSTR_hsync_back_porch, MP_ARG_INT | MP_ARG_KW_ONLY, { .u_int = 0 } }, |
|
108 | 109 |
|
109 | 110 | self->bus_config.bus_id = (int)args[ARG_bus_id].u_int; |
110 | 111 | self->bus_config.num_data_lanes = (uint8_t)args[ARG_data_lanes].u_int; |
111 | | - self->bus_config.lane_bit_rate_mbps = (uint32_t)args[ARG_freq].u_int; |
| 112 | + self->bus_config.lane_bit_rate_mbps = (uint32_t)args[ARG_lane_bitrate].u_int; |
112 | 113 | self->bus_config.phy_clk_src = MIPI_DSI_PHY_CLK_SRC_DEFAULT; |
113 | 114 |
|
114 | 115 | self->panel_io_config.virtual_channel = (uint8_t)args[ARG_virtual_channel].u_int; |
115 | 116 |
|
116 | 117 | self->panel_config.virtual_channel = (uint8_t)args[ARG_virtual_channel].u_int; |
117 | 118 | self->panel_config.dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT; |
118 | 119 |
|
119 | | - self->panel_config.dpi_clock_freq_mhz = (uint32_t)args[ARG_freq].u_int; |
| 120 | + self->panel_config.dpi_clock_freq_mhz = (uint8_t)args[ARG_clock_freq].u_int; |
120 | 121 |
|
121 | 122 | self->panel_config.video_timing.hsync_back_porch = (uint32_t)args[ARG_hsync_back_porch].u_int; |
122 | 123 | self->panel_config.video_timing.hsync_pulse_width = (uint32_t)args[ARG_hsync_pulse_width].u_int; |
|
127 | 128 |
|
128 | 129 | self->panel_config.num_fbs = 0; |
129 | 130 |
|
130 | | - self->bus_config.pclk_hz = (uint32_t)args[ARG_freq].u_int; |
131 | | - |
132 | 131 | LCD_DEBUG_PRINT("bus_id=%d\n", self->bus_config.bus_id) |
133 | 132 | LCD_DEBUG_PRINT("num_data_lanes=%d\n", self->bus_config.num_data_lanes) |
134 | 133 | LCD_DEBUG_PRINT("lane_bit_rate_mbps=%d\n",self->bus_config.lane_bit_rate_mbps) |
|
142 | 141 | LCD_DEBUG_PRINT("vsync_front_porch=%d\n", self->panel_config.video_timing.vsync_front_porch) |
143 | 142 | LCD_DEBUG_PRINT("vsync_back_porch=%d\n", self->panel_config.video_timing.vsync_back_porch) |
144 | 143 | LCD_DEBUG_PRINT("vsync_pulse_width=%d\n", self->panel_config.video_timing.vsync_pulse_width) |
145 | | - LCD_DEBUG_PRINT("pclk_hz[10]=%d\n", self->bus_config.pclk_hz) |
146 | 144 |
|
147 | 145 | self->panel_io_handle.get_lane_count = &dsi_get_lane_count; |
148 | 146 | self->panel_io_handle.del = &dsi_del; |
|
175 | 173 | self->rgb565_byte_swap = false; |
176 | 174 | break; |
177 | 175 | default: |
178 | | - mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unsopported bits per pixel.(%d)"), bpp); |
| 176 | + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("unsupported bits per pixel.(%d)"), bpp); |
179 | 177 | return LCD_ERR_INVALID_ARG; |
180 | 178 | } |
181 | 179 |
|
|
198 | 196 | return ret; |
199 | 197 | } |
200 | 198 |
|
201 | | - ret = esp_lcd_new_panel_io_dsi(self->bus_handle, &self->panel_io_config, &self->panel_io_handle.panel_io); |
| 199 | + ret = esp_lcd_new_panel_io_dbi(self->bus_handle, &self->panel_io_config, &self->panel_io_handle.panel_io); |
202 | 200 |
|
203 | 201 | if (ret != 0) { |
204 | | - mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_new_panel_io_dsi)"), ret); |
| 202 | + mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_new_panel_io_dbi)"), ret); |
205 | 203 | return ret; |
206 | 204 | } |
207 | 205 |
|
|
261 | 259 | } |
262 | 260 |
|
263 | 261 |
|
264 | | - mp_lcd_err_t ret = esp_lcd_panel_io_del(self->panel_io_handle.panel_io); |
| 262 | + ret = esp_lcd_panel_io_del(self->panel_io_handle.panel_io); |
265 | 263 | if (ret != 0) { |
266 | 264 | mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("%d(esp_lcd_panel_io_del)"), ret); |
267 | 265 | return ret; |
|
329 | 327 | #endif |
330 | 328 | } |
331 | 329 |
|
332 | | - void *buf = heap_caps_calloc(1, 1, MALLOC_CAP_INTERNAL); |
| 330 | + void *buf = heap_caps_calloc(1, size, caps); |
333 | 331 |
|
334 | | - mp_obj_array_t *view = MP_OBJ_TO_PTR(mp_obj_new_memoryview(BYTEARRAY_TYPECODE, 1, buf)); |
| 332 | + mp_obj_array_t *view = MP_OBJ_TO_PTR(mp_obj_new_memoryview(BYTEARRAY_TYPECODE, size, buf)); |
335 | 333 | view->typecode |= 0x80; // used to indicate writable buffer |
336 | 334 |
|
337 | 335 | uint32_t available = (uint32_t)heap_caps_get_largest_free_block(caps); |
|
0 commit comments