|
26 | 26 |
|
27 | 27 | void rgb_bus_event_init(rgb_bus_event_t *event) |
28 | 28 | { |
29 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
30 | | - mp_printf(&mp_plat_print, "rgb_bus_event_init\n"); |
31 | | - #endif |
32 | 29 | event->handle = xEventGroupCreateStatic(&event->buffer); |
33 | 30 | } |
34 | 31 |
|
35 | 32 | void rgb_bus_event_delete(rgb_bus_event_t *event) |
36 | 33 | { |
37 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
38 | | - mp_printf(&mp_plat_print, "rgb_bus_event_delete\n"); |
39 | | - #endif |
40 | 34 | xEventGroupSetBits(event->handle, RGB_BIT_0); |
41 | 35 | vEventGroupDelete(event->handle); |
42 | 36 |
|
|
45 | 39 |
|
46 | 40 | bool rgb_bus_event_isset(rgb_bus_event_t *event) |
47 | 41 | { |
48 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
49 | | - mp_printf(&mp_plat_print, "rgb_bus_event_isset\n"); |
50 | | - #endif |
51 | 42 | return (bool)(xEventGroupGetBits(event->handle) & RGB_BIT_0); |
52 | 43 | } |
53 | 44 |
|
|
60 | 51 |
|
61 | 52 | void rgb_bus_event_set(rgb_bus_event_t *event) |
62 | 53 | { |
63 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
64 | | - mp_printf(&mp_plat_print, "rgb_bus_event_set\n"); |
65 | | - #endif |
66 | 54 | xEventGroupSetBits(event->handle, RGB_BIT_0); |
67 | 55 | } |
68 | 56 |
|
69 | 57 |
|
70 | 58 | void rgb_bus_event_clear(rgb_bus_event_t *event) |
71 | 59 | { |
72 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
73 | | - mp_printf(&mp_plat_print, "rgb_bus_event_clear\n"); |
74 | | - #endif |
75 | 60 | xEventGroupClearBits(event->handle, RGB_BIT_0); |
76 | 61 | } |
77 | 62 |
|
|
88 | 73 |
|
89 | 74 | int rgb_bus_lock_acquire(rgb_bus_lock_t *lock, int32_t wait_ms) |
90 | 75 | { |
91 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
92 | | - mp_printf(&mp_plat_print, "rgb_bus_lock_acquire\n"); |
93 | | - #endif |
94 | 76 | return pdTRUE == xSemaphoreTake(lock->handle, wait_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS((uint16_t)wait_ms)); |
95 | 77 | } |
96 | 78 |
|
97 | 79 |
|
98 | 80 | void rgb_bus_lock_release(rgb_bus_lock_t *lock) |
99 | 81 | { |
100 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
101 | | - mp_printf(&mp_plat_print, "rgb_bus_lock_release\n"); |
102 | | - #endif |
103 | 82 | xSemaphoreGive(lock->handle); |
104 | 83 | } |
105 | 84 |
|
|
112 | 91 |
|
113 | 92 | void rgb_bus_lock_init(rgb_bus_lock_t *lock) |
114 | 93 | { |
115 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
116 | | - mp_printf(&mp_plat_print, "rgb_bus_lock_init\n"); |
117 | | - #endif |
118 | 94 | lock->handle = xSemaphoreCreateBinaryStatic(&lock->buffer); |
119 | 95 | xSemaphoreGive(lock->handle); |
120 | 96 | } |
121 | 97 |
|
122 | 98 |
|
123 | 99 | void rgb_bus_lock_delete(rgb_bus_lock_t *lock) |
124 | 100 | { |
125 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
126 | | - mp_printf(&mp_plat_print, "rgb_bus_lock_delete\n"); |
127 | | - #endif |
128 | 101 | vSemaphoreDelete(lock->handle); |
129 | 102 | } |
130 | 103 |
|
|
169 | 142 |
|
170 | 143 | mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)self_in; |
171 | 144 |
|
| 145 | + uint8_t *idle_fb; |
172 | 146 | copy_func_cb_t func; |
173 | 147 | uint8_t bytes_per_pixel = self->bytes_per_pixel; |
174 | 148 |
|
|
198 | 172 |
|
199 | 173 | while (!exit) { |
200 | 174 | rgb_bus_lock_acquire(&self->copy_lock, -1); |
201 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
202 | | - mp_printf(&mp_plat_print, "!rgb_bus_event_isset(&self->copy_task_exit)\n"); |
203 | | - #endif |
204 | 175 |
|
205 | 176 | if (self->partial_buf == NULL) break; |
206 | 177 |
|
| 178 | + idle_fb = self->idle_fb; |
| 179 | + |
207 | 180 | copy_pixels( |
208 | | - self->idle_fb, self->partial_buf, |
| 181 | + idle_fb, self->partial_buf, |
209 | 182 | self->x_start, self->y_start, |
210 | 183 | self->x_end, self->y_end, |
211 | 184 | self->width, self->height, |
|
241 | 214 | mp_thread_set_state(old_state); |
242 | 215 | } |
243 | 216 |
|
244 | | - if (rgb_bus_event_isset(&self->last_update)) { |
245 | | - rgb_bus_event_clear(&self->last_update); |
| 217 | + if (self->last_update) { |
246 | 218 | // the reason why this locked is released this way is to ensure that the partial |
247 | 219 | // buffer has been copied correctly before another one gets into the queue |
248 | 220 | // it is places here after the partial check to ensure the setting of the partial doesn't overlap |
249 | 221 | // with the wrong partial buffer |
250 | 222 | rgb_bus_lock_release(&self->tx_color_lock); |
251 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
252 | | - mp_printf(&mp_plat_print, "rgb_bus_event_isset(&self->last_update)\n"); |
253 | | - #endif |
254 | | - |
255 | | - uint8_t *idle_fb = self->idle_fb; |
256 | | - rgb_bus_event_set(&self->swap_bufs); |
257 | 223 |
|
258 | 224 | mp_lcd_err_t ret = esp_lcd_panel_draw_bitmap( |
259 | 225 | self->panel_handle, |
|
267 | 233 | if (ret != 0) { |
268 | 234 | mp_printf(&mp_plat_print, "esp_lcd_panel_draw_bitmap error (%d)\n", ret); |
269 | 235 | } else { |
| 236 | + rgb_bus_event_set(&self->swap_bufs); |
270 | 237 | rgb_bus_lock_acquire(&self->swap_lock, -1); |
271 | | - memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel); |
| 238 | + memcpy( self->active_fb, self->idle_fb, self->width * self->height * bytes_per_pixel); |
272 | 239 | } |
273 | 240 | } else { |
274 | 241 | rgb_bus_lock_release(&self->tx_color_lock); |
|
283 | 250 | } |
284 | 251 |
|
285 | 252 |
|
286 | | - void copy_pixels( |
287 | | - uint8_t *to, |
288 | | - uint8_t *from, |
289 | | - uint32_t x_start, |
290 | | - uint32_t y_start, |
291 | | - uint32_t x_end, |
292 | | - uint32_t y_end, |
293 | | - uint32_t h_res, |
294 | | - uint32_t v_res, |
295 | | - uint32_t bytes_per_pixel, |
296 | | - copy_func_cb_t func, |
297 | | - uint8_t rotate |
298 | | - ) { |
299 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
300 | | - mp_printf(&mp_plat_print, "copy_pixels(to, from, x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, h_res=%lu, v_res=%lu, bytes_per_pixel=%lu, func, rotate=%u)\n", |
301 | | - x_start, y_start, x_end, y_end, h_res, v_res, bytes_per_pixel, rotate); |
302 | | - #endif |
| 253 | + void copy_pixels(uint8_t *to, uint8_t *from, uint32_t x_start, uint32_t y_start, |
| 254 | + uint32_t x_end, uint32_t y_end, uint32_t h_res, uint32_t v_res, |
| 255 | + uint32_t bytes_per_pixel, copy_func_cb_t func, uint8_t rotate) |
| 256 | + { |
303 | 257 | if (rotate == RGB_BUS_ROTATION_90 || rotate == RGB_BUS_ROTATION_270) { |
304 | 258 | x_start = MIN(x_start, v_res); |
305 | 259 | x_end = MIN(x_end, v_res); |
|
317 | 271 | uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line; |
318 | 272 | size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel; |
319 | 273 |
|
320 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
321 | | - mp_printf(&mp_plat_print, "x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%hu, bytes_per_line=%lu, offset=%d\n", |
322 | | - x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, offset); |
323 | | - #endif |
| 274 | + // mp_printf(&mp_plat_print, "x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%u, bytes_per_line=%lu, %lu\n", |
| 275 | + // x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, (uint32_t)((y_start * h_res + x_start) * bytes_per_pixel)); |
324 | 276 |
|
325 | 277 | switch (rotate) { |
326 | 278 | case RGB_BUS_ROTATION_0: |
327 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
328 | | - mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_0\n"); |
329 | | - #endif |
330 | | - uint8_t *fb = to + (y_start * h_res + x_start) * bytes_per_pixel; |
| 279 | + uint8_t *fb = to + ((y_start * h_res + x_start) * bytes_per_pixel); |
331 | 280 |
|
332 | 281 | if (x_start == 0 && x_end == (h_res - 1)) { |
333 | 282 | memcpy(fb, from, bytes_per_line * (y_end - y_start + 1)); |
334 | 283 | } else { |
335 | 284 | for (int y = y_start; y < y_end; y++) { |
336 | | - memcpy(fb, from, bytes_per_line); |
| 285 | + memcpy(fb, from, copy_bytes_per_line); |
337 | 286 | fb += bytes_per_line; |
338 | 287 | from += copy_bytes_per_line; |
339 | 288 | } |
340 | 289 | } |
341 | 290 |
|
342 | 291 | break; |
| 292 | + |
343 | 293 | case RGB_BUS_ROTATION_180: |
344 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
345 | | - mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_180\n"); |
346 | | - #endif |
347 | 294 | uint32_t index; |
348 | 295 | for (int y = y_start; y < y_end; y++) { |
349 | 296 | index = ((v_res - 1 - y) * h_res + (h_res - 1 - x_start)) * bytes_per_pixel; |
|
356 | 303 | break; |
357 | 304 |
|
358 | 305 | case RGB_BUS_ROTATION_90: |
359 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
360 | | - mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_90\n"); |
361 | | - #endif |
362 | 306 | uint32_t j; |
363 | 307 | uint32_t i; |
364 | 308 |
|
|
371 | 315 | } |
372 | 316 | break; |
373 | 317 |
|
374 | | - |
375 | | - |
376 | 318 | case RGB_BUS_ROTATION_270: |
377 | | - #if CONFIG_LCD_ENABLE_DEBUG_LOG |
378 | | - mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_270\n"); |
379 | | - #endif |
380 | 319 | uint32_t jj; |
381 | 320 | uint32_t ii; |
382 | 321 |
|
|
0 commit comments