|
12 | 12 | #include "freertos/event_groups.h" |
13 | 13 | #include "freertos/idf_additions.h" |
14 | 14 |
|
| 15 | + #include "esp_lcd_panel_ops.h" |
| 16 | + |
15 | 17 | #include "rgb_bus.h" |
16 | 18 |
|
| 19 | + #include <string.h> |
17 | 20 |
|
18 | | - #define RGB_BIT_0 ( 1 << 0 ) |
| 21 | + #define RGB_BIT_0 (1 << 0) |
19 | 22 |
|
20 | 23 |
|
21 | 24 | void rgb_bus_event_init(rgb_bus_event_t *event) |
|
61 | 64 |
|
62 | 65 | void rgb_bus_event_set_from_isr(rgb_bus_event_t *event) |
63 | 66 | { |
64 | | - xEventGroupSetBitsFromISR(event->handle, RGB_BIT_0, pdFALSE) |
| 67 | + xEventGroupSetBitsFromISR(event->handle, RGB_BIT_0, pdFALSE); |
65 | 68 | } |
66 | 69 |
|
67 | 70 |
|
68 | | - int rgb_bus_lock_acquire(thread_lock_t *lock, int32_t wait_ms) |
| 71 | + int rgb_bus_lock_acquire(rgb_bus_lock_t *lock, int32_t wait_ms) |
69 | 72 | { |
70 | 73 | return pdTRUE == xSemaphoreTake(lock->handle, wait_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS((uint16_t)wait_ms)); |
71 | 74 | } |
|
79 | 82 |
|
80 | 83 | void rgb_bus_lock_release_from_isr(rgb_bus_lock_t *lock) |
81 | 84 | { |
82 | | - xSemaphoreGiveFromISR(lock->handle, pdFALSE) |
| 85 | + xSemaphoreGiveFromISR(lock->handle, pdFALSE); |
83 | 86 | } |
84 | 87 |
|
85 | 88 |
|
|
103 | 106 | typedef void (* copy_func_cb_t)(uint8_t *to, const uint8_t *from); |
104 | 107 |
|
105 | 108 | static void copy_pixels( |
106 | | - uint8_t *to, uint8_t *from, uint16_t x_start, uint16_t y_start, |
107 | | - uint16_t x_end, uint16_t y_end, uint16_t h_res, uint16_t v_res, |
108 | | - uint8_t bytes_per_pixel, copy_func_cb_t func, uint8_t rotate, |
109 | | - uint8_t bytes_per_pixel); |
| 109 | + uint8_t *to, uint8_t *from, uint32_t x_start, uint32_t y_start, |
| 110 | + uint32_t x_end, uint32_t y_end, uint32_t h_res, uint32_t v_res, |
| 111 | + uint32_t bytes_per_pixel, copy_func_cb_t func, uint8_t rotate); |
110 | 112 |
|
111 | 113 |
|
112 | 114 | __attribute__((always_inline)) |
|
134 | 136 | mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)self_in; |
135 | 137 |
|
136 | 138 | copy_func_cb_t func; |
137 | | - uint8_t bytes_per_pixel; |
138 | | - uint32_t copy_bytes_per_line; |
139 | | - uint8_t *from; |
140 | | - size_t offset; |
141 | | - uint8_t *to; |
142 | | - |
143 | | - switch (self->bpp) { |
144 | | - case 8: |
| 139 | + uint8_t bytes_per_pixel = self->bytes_per_pixel; |
| 140 | + |
| 141 | + switch (bytes_per_pixel) { |
| 142 | + case 1: |
145 | 143 | func = copy_8bpp; |
146 | | - bytes_per_pixel = 1; |
147 | | - case 16: |
| 144 | + break; |
| 145 | + case 2: |
148 | 146 | func = copy_16bpp; |
149 | | - bytes_per_pixel = 2; |
150 | | - case 24: |
| 147 | + break; |
| 148 | + case 3: |
151 | 149 | func = copy_24bpp; |
152 | | - bytes_per_pixel = 3; |
| 150 | + break; |
153 | 151 | default: |
154 | 152 | // raise error |
155 | 153 | return; |
156 | 154 | } |
157 | 155 |
|
158 | | - uint8_t *partial_buf; |
159 | | - |
160 | 156 | rgb_bus_lock_acquire(&self->copy_lock, -1); |
161 | | - rgb_bus_event_clear(&self->full_copy); |
162 | 157 |
|
163 | 158 | while (!rgb_bus_event_isset(&self->copy_task_exit)) { |
164 | 159 | rgb_bus_lock_acquire(&self->copy_lock, -1); |
|
167 | 162 | rgb_bus_event_clear(&self->partial_copy); |
168 | 163 |
|
169 | 164 | copy_pixels( |
170 | | - self->idle_buf, self->partial_buf, |
171 | | - self->start_x, self->start_y, |
172 | | - self->end_x, self->end_y, |
| 165 | + self->idle_fb, self->partial_buf, |
| 166 | + self->x_start, self->y_start, |
| 167 | + self->x_end, self->y_end, |
173 | 168 | self->width, self->height, |
174 | 169 | bytes_per_pixel, func, self->rotation); |
175 | 170 |
|
|
178 | 173 |
|
179 | 174 | if (rgb_bus_event_isset(&self->last_update)) { |
180 | 175 | rgb_bus_event_clear(&self->last_update); |
181 | | - uint8_t *idle_buf = self->idle_buf; |
| 176 | + uint8_t *idle_fb = self->idle_fb; |
182 | 177 | rgb_bus_event_set(&self->swap_bufs); |
183 | 178 |
|
184 | 179 | esp_lcd_panel_draw_bitmap( |
|
187 | 182 | 0, |
188 | 183 | self->width, |
189 | 184 | self->height, |
190 | | - idle_buf; |
| 185 | + idle_fb |
191 | 186 | ); |
192 | 187 |
|
193 | 188 | rgb_bus_lock_acquire(&self->swap_lock, -1); |
194 | | - memcpy(self->idle_buf, self.->active_buf, self->width * self->height * bytes_per_pixel); |
| 189 | + memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel); |
195 | 190 | } |
196 | 191 | } |
197 | 192 | } |
|
208 | 203 | uint32_t v_res, |
209 | 204 | uint32_t bytes_per_pixel, |
210 | 205 | copy_func_cb_t func, |
211 | | - uint8_t rotate, |
| 206 | + uint8_t rotate |
212 | 207 | ) { |
213 | 208 |
|
214 | 209 | if (rotate == RGB_BUS_ROTATION_90 || rotate == RGB_BUS_ROTATION_270) { |
|
223 | 218 | y_end = MIN(y_end, v_res); |
224 | 219 | } |
225 | 220 |
|
226 | | - uint16_t copy_bytes_per_line = (self->x_end - self->x_start) * (uint16_t)bytes_per_pixel; |
| 221 | + uint16_t copy_bytes_per_line = (x_end - x_start) * (uint16_t)bytes_per_pixel; |
| 222 | + int pixels_per_line = h_res; |
| 223 | + uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line; |
227 | 224 | size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel; |
228 | 225 |
|
229 | 226 | switch (rotate) { |
|
234 | 231 | fb += bytes_per_line; |
235 | 232 | from += copy_bytes_per_line; |
236 | 233 | } |
237 | | - bytes_to_flush = (y_end - y_start) * bytes_per_line; |
238 | | - flush_ptr = to + y_start * bytes_per_line; |
239 | 234 | break; |
240 | 235 |
|
241 | 236 | case RGB_BUS_ROTATION_180: |
|
249 | 244 | from += bytes_per_pixel; |
250 | 245 | } |
251 | 246 | } |
252 | | - bytes_to_flush = (y_end - y_start) * bytes_per_line; |
253 | | - flush_ptr = to + (v_res - y_end) * bytes_per_line; |
254 | 247 | break; |
255 | 248 |
|
256 | 249 | case RGB_BUS_ROTATION_90: |
|
264 | 257 | func(to + i, from + j); |
265 | 258 | } |
266 | 259 | } |
267 | | - bytes_to_flush = (x_end - x_start) * bytes_per_line; |
268 | | - flush_ptr = to + x_start * bytes_per_line; |
269 | 260 | break; |
270 | 261 |
|
271 | | - case ROTATE_MASK_SWAP_XY | ROTATE_MASK_MIRROR_X | ROTATE_MASK_MIRROR_Y: |
272 | | - uint32_t jj |
273 | | - uint32_t ii |
| 262 | + case RGB_BUS_ROTATION_270: |
| 263 | + uint32_t jj; |
| 264 | + uint32_t ii; |
274 | 265 |
|
275 | 266 | for (int y = y_start; y < y_end; y++) { |
276 | 267 | for (int x = x_start; x < x_end; x++) { |
|
279 | 270 | func(to + ii, from + jj); |
280 | 271 | } |
281 | 272 | } |
282 | | - bytes_to_flush = (x_end - x_start) * bytes_per_line; |
283 | | - flush_ptr = to + (v_res - x_end) * bytes_per_line; |
284 | 273 | break; |
285 | 274 |
|
286 | 275 | default: |
|
0 commit comments