|
26 | 26 |
|
27 | 27 | void rgb_bus_event_init(rgb_bus_event_t *event) |
28 | 28 | { |
| 29 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 30 | + printf("rgb_bus_event_init\n"); |
| 31 | + #endif |
29 | 32 | event->handle = xEventGroupCreateStatic(&event->buffer); |
30 | 33 | } |
31 | 34 |
|
32 | 35 |
|
33 | 36 | void rgb_bus_event_delete(rgb_bus_event_t *event) |
34 | 37 | { |
| 38 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 39 | + printf("rgb_bus_event_delete\n"); |
| 40 | + #endif |
35 | 41 | xEventGroupSetBits(event->handle, RGB_BIT_0); |
36 | 42 | vEventGroupDelete(event->handle); |
| 43 | + |
37 | 44 | } |
38 | 45 |
|
39 | 46 |
|
40 | 47 | bool rgb_bus_event_isset(rgb_bus_event_t *event) |
41 | 48 | { |
42 | | - return (bool)(xEventGroupGetBits(event->handle) == RGB_BIT_0); |
| 49 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 50 | + printf("rgb_bus_event_isset\n"); |
| 51 | + #endif |
| 52 | + return (bool)(xEventGroupGetBits(event->handle) & RGB_BIT_0); |
43 | 53 | } |
44 | 54 |
|
45 | 55 |
|
46 | 56 | bool rgb_bus_event_isset_from_isr(rgb_bus_event_t *event) |
47 | 57 | { |
48 | | - return (bool)(xEventGroupGetBitsFromISR(event->handle) == RGB_BIT_0); |
| 58 | + return (bool)(xEventGroupGetBitsFromISR(event->handle) & RGB_BIT_0); |
49 | 59 | } |
50 | 60 |
|
51 | 61 |
|
52 | 62 | void rgb_bus_event_set(rgb_bus_event_t *event) |
53 | 63 | { |
| 64 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 65 | + printf("rgb_bus_event_set\n"); |
| 66 | + #endif |
54 | 67 | xEventGroupSetBits(event->handle, RGB_BIT_0); |
55 | 68 | } |
56 | 69 |
|
57 | 70 |
|
58 | 71 | void rgb_bus_event_clear(rgb_bus_event_t *event) |
59 | 72 | { |
| 73 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 74 | + printf("rgb_bus_event_clear\n"); |
| 75 | + #endif |
60 | 76 | xEventGroupClearBits(event->handle, RGB_BIT_0); |
61 | 77 | } |
62 | 78 |
|
|
73 | 89 |
|
74 | 90 | int rgb_bus_lock_acquire(rgb_bus_lock_t *lock, int32_t wait_ms) |
75 | 91 | { |
| 92 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 93 | + printf("rgb_bus_lock_acquire\n"); |
| 94 | + #endif |
76 | 95 | return pdTRUE == xSemaphoreTake(lock->handle, wait_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS((uint16_t)wait_ms)); |
77 | 96 | } |
78 | 97 |
|
79 | 98 |
|
80 | 99 | void rgb_bus_lock_release(rgb_bus_lock_t *lock) |
81 | 100 | { |
| 101 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 102 | + printf("rgb_bus_lock_release\n"); |
| 103 | + #endif |
82 | 104 | xSemaphoreGive(lock->handle); |
83 | 105 | } |
84 | 106 |
|
|
91 | 113 |
|
92 | 114 | void rgb_bus_lock_init(rgb_bus_lock_t *lock) |
93 | 115 | { |
| 116 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 117 | + printf("rgb_bus_lock_init\n"); |
| 118 | + #endif |
94 | 119 | lock->handle = xSemaphoreCreateBinaryStatic(&lock->buffer); |
95 | 120 | xSemaphoreGive(lock->handle); |
96 | 121 | } |
97 | 122 |
|
98 | 123 |
|
99 | 124 | void rgb_bus_lock_delete(rgb_bus_lock_t *lock) |
100 | 125 | { |
| 126 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 127 | + printf("rgb_bus_lock_delete\n"); |
| 128 | + #endif |
101 | 129 | vSemaphoreDelete(lock->handle); |
102 | 130 | } |
103 | 131 |
|
|
136 | 164 | } |
137 | 165 |
|
138 | 166 | void rgb_bus_copy_task(void *self_in) { |
| 167 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
139 | 168 | printf("rgb_bus_copy_task - STARTED\n"); |
| 169 | + #endif |
140 | 170 |
|
141 | 171 | mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)self_in; |
142 | 172 |
|
|
160 | 190 |
|
161 | 191 | rgb_bus_lock_acquire(&self->copy_lock, -1); |
162 | 192 |
|
163 | | - while (!rgb_bus_event_isset(&self->copy_task_exit)) { |
| 193 | + bool exit = rgb_bus_event_isset(&self->copy_task_exit); |
| 194 | + |
| 195 | + while (!exit) { |
164 | 196 | rgb_bus_lock_acquire(&self->copy_lock, -1); |
| 197 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 198 | + printf("!rgb_bus_event_isset(&self->copy_task_exit)\n"); |
| 199 | + #endif |
165 | 200 |
|
166 | 201 | if (rgb_bus_event_isset(&self->partial_copy)) { |
167 | 202 | rgb_bus_event_clear(&self->partial_copy); |
168 | | - printf("rgb_bus_copy_task - partial_copy\n"); |
| 203 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 204 | + printf("rgb_bus_event_isset(&self->partial_copy)\n"); |
| 205 | + #endif |
169 | 206 |
|
170 | 207 |
|
171 | 208 | copy_pixels( |
|
192 | 229 |
|
193 | 230 | nlr_buf_t nlr; |
194 | 231 | if (nlr_push(&nlr) == 0) { |
| 232 | + |
| 233 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 234 | + printf("mp_call_function_n_kw(1)\n"); |
| 235 | + #endif |
| 236 | + |
195 | 237 | mp_call_function_n_kw(self->callback, 0, 0, NULL); |
| 238 | + |
| 239 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 240 | + printf("mp_call_function_n_kw(2)\n"); |
| 241 | + #endif |
| 242 | + |
196 | 243 | nlr_pop(); |
197 | 244 | } else { |
198 | 245 | ets_printf("Uncaught exception in IRQ callback handler!\n"); |
|
208 | 255 |
|
209 | 256 | if (rgb_bus_event_isset(&self->last_update)) { |
210 | 257 | rgb_bus_event_clear(&self->last_update); |
211 | | - printf("rgb_bus_copy_task - last_update\n"); |
| 258 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 259 | + printf("rgb_bus_event_isset(&self->last_update)\n"); |
| 260 | + #endif |
212 | 261 |
|
213 | 262 | uint8_t *idle_fb = self->idle_fb; |
214 | 263 | rgb_bus_event_set(&self->swap_bufs); |
215 | 264 |
|
216 | | - esp_lcd_panel_draw_bitmap( |
| 265 | + mp_lcd_err_t ret = esp_lcd_panel_draw_bitmap( |
217 | 266 | self->panel_handle, |
218 | 267 | 0, |
219 | 268 | 0, |
|
222 | 271 | idle_fb |
223 | 272 | ); |
224 | 273 |
|
225 | | - rgb_bus_lock_acquire(&self->swap_lock, -1); |
226 | | - memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel); |
| 274 | + if (ret != 0) { |
| 275 | + printf("esp_lcd_panel_draw_bitmap error (%d)\n", ret); |
| 276 | + } else { |
| 277 | + rgb_bus_lock_acquire(&self->swap_lock, -1); |
| 278 | + memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel); |
| 279 | + } |
227 | 280 | } |
| 281 | + |
| 282 | + exit = rgb_bus_event_isset(&self->copy_task_exit); |
228 | 283 | } |
229 | 284 | } |
230 | 285 |
|
|
242 | 297 | copy_func_cb_t func, |
243 | 298 | uint8_t rotate |
244 | 299 | ) { |
245 | | - |
| 300 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 301 | + printf("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", |
| 302 | + x_start, y_start, x_end, y_end, h_res, v_res, bytes_per_pixel, rotate); |
| 303 | + #endif |
246 | 304 | if (rotate == RGB_BUS_ROTATION_90 || rotate == RGB_BUS_ROTATION_270) { |
247 | 305 | x_start = MIN(x_start, v_res); |
248 | 306 | x_end = MIN(x_end, v_res); |
|
255 | 313 | y_end = MIN(y_end, v_res); |
256 | 314 | } |
257 | 315 |
|
258 | | - uint16_t copy_bytes_per_line = (x_end - x_start) * (uint16_t)bytes_per_pixel; |
| 316 | + uint16_t copy_bytes_per_line = (x_end - x_start + 1) * (uint16_t)bytes_per_pixel; |
259 | 317 | int pixels_per_line = h_res; |
260 | 318 | uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line; |
261 | 319 | size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel; |
262 | 320 |
|
| 321 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 322 | + printf("x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%hu, bytes_per_line=%lu, offset=%d\n", |
| 323 | + x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, offset); |
| 324 | + #endif |
| 325 | + |
263 | 326 | switch (rotate) { |
264 | 327 | case RGB_BUS_ROTATION_0: |
| 328 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 329 | + printf("RGB_BUS_ROTATION_0\n"); |
| 330 | + #endif |
265 | 331 | uint8_t *fb = to + (y_start * h_res + x_start) * bytes_per_pixel; |
266 | | - for (int y = y_start; y < y_end; y++) { |
267 | | - memcpy(fb, from, copy_bytes_per_line); |
268 | | - fb += bytes_per_line; |
269 | | - from += copy_bytes_per_line; |
| 332 | + |
| 333 | + if (x_start == 0 && x_end == (h_res - 1)) { |
| 334 | + memcpy(fb, from, bytes_per_line * (y_end - y_start + 1)); |
| 335 | + } else { |
| 336 | + for (int y = y_start; y < y_end; y++) { |
| 337 | + memcpy(fb, from, bytes_per_line); |
| 338 | + fb += bytes_per_line; |
| 339 | + from += copy_bytes_per_line; |
| 340 | + } |
270 | 341 | } |
271 | | - break; |
272 | 342 |
|
| 343 | + break; |
273 | 344 | case RGB_BUS_ROTATION_180: |
| 345 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 346 | + printf("RGB_BUS_ROTATION_180\n"); |
| 347 | + #endif |
274 | 348 | uint32_t index; |
275 | 349 | for (int y = y_start; y < y_end; y++) { |
276 | 350 | index = ((v_res - 1 - y) * h_res + (h_res - 1 - x_start)) * bytes_per_pixel; |
|
284 | 358 | break; |
285 | 359 |
|
286 | 360 | case RGB_BUS_ROTATION_90: |
| 361 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 362 | + printf("RGB_BUS_ROTATION_90\n"); |
| 363 | + #endif |
287 | 364 | uint32_t j; |
288 | 365 | uint32_t i; |
289 | 366 |
|
|
297 | 374 | break; |
298 | 375 |
|
299 | 376 | case RGB_BUS_ROTATION_270: |
| 377 | + #if CONFIG_LCD_ENABLE_DEBUG_LOG |
| 378 | + printf("RGB_BUS_ROTATION_270\n"); |
| 379 | + #endif |
300 | 380 | uint32_t jj; |
301 | 381 | uint32_t ii; |
302 | 382 |
|
|
0 commit comments