Skip to content

Commit 8e3db46

Browse files
committed
Some updates.
1 parent 798b3e7 commit 8e3db46

File tree

7 files changed

+211
-58
lines changed

7 files changed

+211
-58
lines changed

api_drivers/common_api_drivers/display/nv3041a/nv3041a.py

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

200200
data_view = color_p.__dereference__(size)
201201

202-
first_chunk = int(size / 10)
202+
# Divide buffer in 2 chunks:
203+
first_chunk = int(size / 2)
203204

204205
self._data_bus.tx_color(self.__ramwr, data_view[:first_chunk], x1, y1, x2, y2, self._rotation, False)
205206
self._data_bus.tx_color(self.__ramwrc, data_view[first_chunk:], x1, y1, x2, y2, self._rotation, self._disp_drv.flush_is_last())
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef __RGB565_DITHER_H__
2+
#define __RGB565_DITHER_H__
3+
4+
#define CALC_THRESHOLD(x, y) (uint8_t)((y & 7) << 3) + (x & 7);
5+
6+
extern uint8_t *red_thresh;
7+
extern uint8_t *green_thresh;
8+
extern uint8_t *blue_thresh;
9+
10+
bool rgb565_dither_init(void);
11+
12+
static inline rgb565_dither_pixel(uint8_t treshold_id, uint16_t *pixel)
13+
{
14+
*pixel = (((((pixel >> 8) & 0xF8) + red_thresh[treshold_id]) << 8) |
15+
((((pixel >> 3) & 0xFC) + green_thresh[treshold_id]) << 3) |
16+
((((pixel & 0x1F) << 3) + blue_thresh[treshold_id]) >> 3)) ;
17+
}
18+
19+
#endif

ext_mod/lcd_bus/esp32_include/rgb_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
uint8_t rotation: 2;
105105
uint8_t bytes_per_pixel: 2;
106106
uint8_t last_update: 1;
107+
uint8_t rgb565_dither: 1;
107108

108109
rgb_bus_lock_t copy_lock;
109110
rgb_bus_event_t copy_task_exit;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
#include "rgb565_dither.h"
3+
#include <string.h>
4+
5+
6+
bool rgb565_dither_init(void)
7+
{
8+
if (red_thresh == NULL) {
9+
red_thresh = (uint8_t *)malloc(64);
10+
if (red_thresh != NULL) {
11+
memcpy(red_thresh,
12+
(uint8_t []){
13+
1, 7, 3, 5, 0, 8, 2, 6,
14+
7, 1, 5, 3, 8, 0, 6, 2,
15+
3, 5, 0, 8, 2, 6, 1, 7,
16+
5, 3, 8, 0, 6, 2, 7, 1,
17+
0, 8, 2, 6, 1, 7, 3, 5,
18+
8, 0, 6, 2, 7, 1, 5, 3,
19+
2, 6, 1, 7, 3, 5, 0, 8,
20+
6, 2, 7, 1, 5, 3, 8, 0
21+
}, 64);
22+
}
23+
}
24+
25+
if (green_thresh == NULL) {
26+
green_thresh = (uint8_t *)malloc(64);
27+
if (green_thresh != NULL) {
28+
memcpy(green_thresh,
29+
(uint8_t []){
30+
1, 3, 2, 2, 3, 1, 2, 2,
31+
2, 2, 0, 4, 2, 2, 4, 0,
32+
3, 1, 2, 2, 1, 3, 2, 2,
33+
2, 2, 4, 0, 2, 2, 0, 4,
34+
1, 3, 2, 2, 3, 1, 2, 2,
35+
2, 2, 0, 4, 2, 2, 4, 0,
36+
3, 1, 2, 2, 1, 3, 2, 2,
37+
2, 2, 4, 0, 2, 2, 0, 4
38+
}, 64);
39+
}
40+
}
41+
if (blue_thresh == NULL) {
42+
blue_thresh = (uint8_t *)malloc(64);
43+
if (blue_thresh != NULL) {
44+
memcpy(blue_thresh,
45+
(uint8_t []){
46+
5, 3, 8, 0, 6, 2, 7, 1,
47+
3, 5, 0, 8, 2, 6, 1, 7,
48+
8, 0, 6, 2, 7, 1, 5, 3,
49+
0, 8, 2, 6, 1, 7, 3, 5,
50+
6, 2, 7, 1, 5, 3, 8, 0,
51+
2, 6, 1, 7, 3, 5, 0, 8,
52+
7, 1, 5, 3, 8, 0, 6, 2,
53+
1, 7, 3, 5, 0, 8, 2, 6
54+
}, 64);
55+
}
56+
}
57+
58+
if (red_thresh == NULL || blue_thresh == NULL || green_thresh == NULL) return false;
59+
else return true;
60+
}
61+
62+
63+

ext_mod/lcd_bus/esp32_src/rgb_bus.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "py/objtype.h"
3434
#include "py/objexcept.h"
3535

36+
#include "rgb565_dither.h"
37+
3638
// stdlib includes
3739
#include <string.h>
3840

@@ -101,6 +103,7 @@
101103
ARG_pclk_idle_high,
102104
ARG_pclk_active_low,
103105
ARG_refresh_on_demand,
106+
ARG_rgb565_dither
104107
};
105108

106109
const mp_arg_t allowed_args[] = {
@@ -137,6 +140,7 @@
137140
{ MP_QSTR_pclk_idle_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
138141
{ MP_QSTR_pclk_active_low, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
139142
{ MP_QSTR_refresh_on_demand, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
143+
{ MP_QSTR_rgb565_dither, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
140144
};
141145

142146
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
@@ -148,6 +152,8 @@
148152

149153
self->callback = mp_const_none;
150154

155+
self->rgb565_dither = (uint8_t)args[ARG_rgb565_dither].u_bool;
156+
151157
self->bus_config.pclk_hz = (uint32_t)args[ARG_freq].u_int;
152158
self->bus_config.hsync_pulse_width = (uint32_t)args[ARG_hsync_pulse_width].u_int;
153159
self->bus_config.hsync_back_porch = (uint32_t)args[ARG_hsync_back_porch].u_int;
@@ -345,6 +351,8 @@
345351

346352
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)obj;
347353

354+
if (bpp != 16 && self->rgb565_dither) self->rgb565_dither = 0;
355+
348356
if (bpp == 16 && rgb565_byte_swap) {
349357
/*
350358
We change the pins aound when the bus width is 16 and wanting to

0 commit comments

Comments
 (0)