Skip to content

Commit 5861bbd

Browse files
committed
Working on RGB Bus driver to improve performance and also provide rotation
1 parent 6391c16 commit 5861bbd

File tree

14 files changed

+453
-136
lines changed

14 files changed

+453
-136
lines changed

api_drivers/common_api_drivers/display/nv3041a/nv3041a.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,5 @@ def _flush_cb(self, _, area, color_p):
199199

200200
first_chunk = int(size / 10)
201201

202-
self._data_bus.tx_color(self.__ramwr, data_view[:first_chunk], x1, y1, x2, y2)
203-
self._data_bus.tx_color(self.__ramwrc, data_view[first_chunk:], x1, y1, x2, y2)
202+
self._data_bus.tx_color(self.__ramwr, data_view[:first_chunk], x1, y1, x2, y2, self._rotation, False)
203+
self._data_bus.tx_color(self.__ramwrc, data_view[first_chunk:], x1, y1, x2, y2, self._rotation, self._disp_drv.flush_is_last())

api_drivers/py_api_drivers/frozen/display/display_driver_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ def _flush_cb(self, _, area, color_p):
616616
# what converts from the C_Array object the binding passes into a
617617
# memoryview object that can be passed to the bus drivers
618618
data_view = color_p.__dereference__(size)
619-
self._data_bus.tx_color(cmd, data_view, x1, y1, x2, y2)
619+
self._data_bus.tx_color(cmd, data_view, x1, y1, x2, y2, self._rotation, self._disp_drv.flush_is_last())
620620

621621
# we always register this callback no matter what. This is what tells LVGL
622622
# that the buffer is able to be written to. If this callback doesn't get

ext_mod/lcd_bus/common_src/i80_bus.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
/* forward declarations */
7777
mp_lcd_err_t i80_rx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
7878
mp_lcd_err_t i80_tx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
79-
mp_lcd_err_t i80_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);
79+
mp_lcd_err_t i80_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);
8080
mp_lcd_err_t i80_del(mp_obj_t obj);
8181
mp_lcd_err_t i80_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);
8282
mp_lcd_err_t i80_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
@@ -343,12 +343,14 @@
343343
}
344344

345345

346-
mp_lcd_err_t i80_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)
346+
mp_lcd_err_t i80_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)
347347
{
348348
LCD_UNUSED(x_start);
349349
LCD_UNUSED(y_start);
350350
LCD_UNUSED(x_end);
351351
LCD_UNUSED(y_end);
352+
LCD_UNUSED(rotation);
353+
LCD_UNUSED(last_update);
352354

353355
mp_lcd_i80_bus_obj_t *self = MP_OBJ_TO_PTR(obj);
354356

ext_mod/lcd_bus/common_src/spi_bus.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
mp_lcd_err_t s_spi_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
8080
mp_lcd_err_t s_spi_rx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
8181
mp_lcd_err_t s_spi_tx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
82-
mp_lcd_err_t s_spi_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);
82+
mp_lcd_err_t s_spi_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);
8383

8484
void send_param_16(mp_lcd_spi_bus_obj_t *self, void *param, size_t param_size);
8585
void send_param_8(mp_lcd_spi_bus_obj_t *self, void *param, size_t param_size);
@@ -269,12 +269,14 @@
269269
}
270270

271271

272-
mp_lcd_err_t s_spi_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)
272+
mp_lcd_err_t s_spi_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)
273273
{
274274
LCD_UNUSED(x_start);
275275
LCD_UNUSED(y_start);
276276
LCD_UNUSED(x_end);
277277
LCD_UNUSED(y_end);
278+
LCD_UNUSED(rotation);
279+
LCD_UNUSED(last_update);
278280

279281
mp_lcd_spi_bus_obj_t *self = MP_OBJ_TO_PTR(obj);
280282

ext_mod/lcd_bus/esp32_include/rgb_bus.h

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,37 @@
1111
#include "esp_lcd_panel_io.h"
1212
#include "esp_lcd_panel_rgb.h"
1313

14+
#include "freertos/FreeRTOS.h"
15+
#include "freertos/task.h"
16+
#include "freertos/semphr.h"
17+
#include "freertos/event_groups.h"
18+
#include "freertos/idf_additions.h"
19+
1420
// micropython includes
1521
#include "mphalport.h"
1622
#include "py/obj.h"
1723
#include "py/objarray.h"
18-
#include "soc/soc_caps.h"
24+
25+
26+
typedef struct _rgb_bus_lock_t {
27+
SemaphoreHandle_t handle;
28+
StaticSemaphore_t buffer;
29+
} rgb_bus_lock_t;
30+
31+
typedef struct _rgb_bus_event_t {
32+
EventGroupHandle_t handle;
33+
StaticEventGroup_t buffer;
34+
} rgb_bus_event_t;
35+
1936

2037
typedef struct _mp_lcd_rgb_bus_obj_t {
2138
mp_obj_base_t base;
2239

2340
mp_obj_t callback;
2441

25-
void *buf1;
26-
void *buf2;
42+
mp_obj_array_t *view1;
43+
mp_obj_array_t *view2;
44+
2745
uint32_t buffer_flags;
2846

2947
bool trans_done;
@@ -36,13 +54,47 @@
3654

3755
esp_lcd_panel_handle_t panel_handle;
3856
uint32_t buffer_size;
39-
mp_obj_array_t *view1;
40-
mp_obj_array_t *view2;
4157

42-
void *last_buf;
58+
uint8_t *active_fb;
59+
uint8_t *idle_fb;
60+
uint8_t *partial_buf;
61+
62+
int x_start;
63+
int y_start;
64+
int x_end;
65+
int y_end;
66+
uint16_t width;
67+
uint16_t height;
68+
uint8_t rotation: 2;
69+
uint8_t bytes_per_pixel: 2;
70+
71+
rgb_bus_lock_t copy_lock;
72+
rgb_bus_event_t copy_task_exit;
73+
rgb_bus_event_t last_update;
74+
rgb_bus_event_t partial_copy;
75+
rgb_bus_event_t swap_bufs;
76+
rgb_bus_lock_t swap_lock;
77+
78+
TaskHandle_t copy_task_handle;
4379

4480
} mp_lcd_rgb_bus_obj_t;
4581

82+
void rgb_bus_event_init(rgb_bus_event_t *event);
83+
void rgb_bus_event_delete(rgb_bus_event_t *event);
84+
bool rgb_bus_event_isset(rgb_bus_event_t *event);
85+
void rgb_bus_event_set(rgb_bus_event_t *event);
86+
void rgb_bus_event_clear(rgb_bus_event_t *event);
87+
void rgb_bus_event_clear_from_isr(rgb_bus_event_t *event);
88+
bool rgb_bus_event_isset_from_isr(rgb_bus_event_t *event);
89+
void rgb_bus_event_set_from_isr(rgb_bus_event_t *event);
90+
91+
int rgb_bus_lock_acquire(thread_lock_t *lock, int32_t wait_ms);
92+
void rgb_bus_lock_release(rgb_bus_lock_t *lock);
93+
void rgb_bus_lock_init(rgb_bus_lock_t *lock);
94+
void rgb_bus_lock_delete(rgb_bus_lock_t *lock);
95+
void rgb_bus_lock_release_from_isr(rgb_bus_lock_t *lock);
96+
97+
void rgb_bus_copy_task(void *self_in);
4698

4799
extern const mp_obj_type_t mp_lcd_rgb_bus_type;
48100

ext_mod/lcd_bus/esp32_src/dsi_bus.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
mp_lcd_err_t dsi_del(mp_obj_t obj);
3838
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);
3939
mp_lcd_err_t dsi_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
40-
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);
40+
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);
4141
mp_obj_t dsi_allocate_framebuffer(mp_obj_t obj, uint32_t size, uint32_t caps);
4242
mp_obj_t dsi_free_framebuffer(mp_obj_t obj, mp_obj_t buf);
4343

@@ -383,11 +383,13 @@
383383
}
384384

385385

386-
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)
386+
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)
387387
{
388388
#if CONFIG_LCD_ENABLE_DEBUG_LOG
389389
printf("dsi_tx_color(self, lcd_cmd=%d, color, color_size=%d, x_start=%d, y_start=%d, x_end=%d, y_end=%d)\n", lcd_cmd, color_size, x_start, y_start, x_end, y_end);
390390
#endif
391+
LCD_UNUSED(rotation);
392+
LCD_UNUSED(last_update);
391393

392394
mp_lcd_dsi_bus_obj_t *self = (mp_lcd_dsi_bus_obj_t *)obj;
393395

ext_mod/lcd_bus/esp32_src/led_bus.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mp_lcd_err_t led_init(mp_obj_t obj, uint16_t width, uint16_t height, uint8_t bpp
7878
mp_lcd_err_t led_get_lane_count(mp_obj_t obj, uint8_t *lane_count);
7979
mp_lcd_err_t led_rx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
8080
mp_lcd_err_t led_tx_param(mp_obj_t obj, int lcd_cmd, void *param, size_t param_size);
81-
mp_lcd_err_t led_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);
81+
mp_lcd_err_t led_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);
8282
mp_obj_t led_allocate_framebuffer(mp_obj_t obj, uint32_t size, uint32_t caps);
8383
mp_obj_t led_free_framebuffer(mp_obj_t obj, mp_obj_t buf);
8484

@@ -486,13 +486,16 @@ mp_lcd_err_t led_get_lane_count(mp_obj_t obj, uint8_t *lane_count)
486486
}
487487

488488

489-
mp_lcd_err_t led_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)
489+
mp_lcd_err_t led_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)
490490
{
491491
LCD_UNUSED(lcd_cmd);
492492
LCD_UNUSED(x_start);
493493
LCD_UNUSED(y_start);
494494
LCD_UNUSED(x_end);
495495
LCD_UNUSED(y_end);
496+
LCD_UNUSED(rotation);
497+
LCD_UNUSED(last_update);
498+
496499
mp_lcd_led_bus_obj_t *self = (mp_lcd_led_bus_obj_t *)obj;
497500
mp_lcd_err_t err;
498501
uint8_t tmp_color[4];

0 commit comments

Comments
 (0)