Skip to content

Commit

Permalink
Some updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdschlosser committed Jan 15, 2025
1 parent 798b3e7 commit 8e3db46
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 58 deletions.
3 changes: 2 additions & 1 deletion api_drivers/common_api_drivers/display/nv3041a/nv3041a.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def _flush_cb(self, _, area, color_p):

data_view = color_p.__dereference__(size)

first_chunk = int(size / 10)
# Divide buffer in 2 chunks:
first_chunk = int(size / 2)

self._data_bus.tx_color(self.__ramwr, data_view[:first_chunk], x1, y1, x2, y2, self._rotation, False)
self._data_bus.tx_color(self.__ramwrc, data_view[first_chunk:], x1, y1, x2, y2, self._rotation, self._disp_drv.flush_is_last())
19 changes: 19 additions & 0 deletions ext_mod/lcd_bus/esp32_include/rgb565_dither.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef __RGB565_DITHER_H__
#define __RGB565_DITHER_H__

#define CALC_THRESHOLD(x, y) (uint8_t)((y & 7) << 3) + (x & 7);

extern uint8_t *red_thresh;
extern uint8_t *green_thresh;
extern uint8_t *blue_thresh;

bool rgb565_dither_init(void);

static inline rgb565_dither_pixel(uint8_t treshold_id, uint16_t *pixel)
{
*pixel = (((((pixel >> 8) & 0xF8) + red_thresh[treshold_id]) << 8) |
((((pixel >> 3) & 0xFC) + green_thresh[treshold_id]) << 3) |
((((pixel & 0x1F) << 3) + blue_thresh[treshold_id]) >> 3)) ;
}

#endif
1 change: 1 addition & 0 deletions ext_mod/lcd_bus/esp32_include/rgb_bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
uint8_t rotation: 2;
uint8_t bytes_per_pixel: 2;
uint8_t last_update: 1;
uint8_t rgb565_dither: 1;

rgb_bus_lock_t copy_lock;
rgb_bus_event_t copy_task_exit;
Expand Down
63 changes: 63 additions & 0 deletions ext_mod/lcd_bus/esp32_src/rgb565_dither.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@

#include "rgb565_dither.h"
#include <string.h>


bool rgb565_dither_init(void)
{
if (red_thresh == NULL) {
red_thresh = (uint8_t *)malloc(64);
if (red_thresh != NULL) {
memcpy(red_thresh,
(uint8_t []){
1, 7, 3, 5, 0, 8, 2, 6,
7, 1, 5, 3, 8, 0, 6, 2,
3, 5, 0, 8, 2, 6, 1, 7,
5, 3, 8, 0, 6, 2, 7, 1,
0, 8, 2, 6, 1, 7, 3, 5,
8, 0, 6, 2, 7, 1, 5, 3,
2, 6, 1, 7, 3, 5, 0, 8,
6, 2, 7, 1, 5, 3, 8, 0
}, 64);
}
}

if (green_thresh == NULL) {
green_thresh = (uint8_t *)malloc(64);
if (green_thresh != NULL) {
memcpy(green_thresh,
(uint8_t []){
1, 3, 2, 2, 3, 1, 2, 2,
2, 2, 0, 4, 2, 2, 4, 0,
3, 1, 2, 2, 1, 3, 2, 2,
2, 2, 4, 0, 2, 2, 0, 4,
1, 3, 2, 2, 3, 1, 2, 2,
2, 2, 0, 4, 2, 2, 4, 0,
3, 1, 2, 2, 1, 3, 2, 2,
2, 2, 4, 0, 2, 2, 0, 4
}, 64);
}
}
if (blue_thresh == NULL) {
blue_thresh = (uint8_t *)malloc(64);
if (blue_thresh != NULL) {
memcpy(blue_thresh,
(uint8_t []){
5, 3, 8, 0, 6, 2, 7, 1,
3, 5, 0, 8, 2, 6, 1, 7,
8, 0, 6, 2, 7, 1, 5, 3,
0, 8, 2, 6, 1, 7, 3, 5,
6, 2, 7, 1, 5, 3, 8, 0,
2, 6, 1, 7, 3, 5, 0, 8,
7, 1, 5, 3, 8, 0, 6, 2,
1, 7, 3, 5, 0, 8, 2, 6
}, 64);
}
}

if (red_thresh == NULL || blue_thresh == NULL || green_thresh == NULL) return false;
else return true;
}



8 changes: 8 additions & 0 deletions ext_mod/lcd_bus/esp32_src/rgb_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "py/objtype.h"
#include "py/objexcept.h"

#include "rgb565_dither.h"

// stdlib includes
#include <string.h>

Expand Down Expand Up @@ -101,6 +103,7 @@
ARG_pclk_idle_high,
ARG_pclk_active_low,
ARG_refresh_on_demand,
ARG_rgb565_dither
};

const mp_arg_t allowed_args[] = {
Expand Down Expand Up @@ -137,6 +140,7 @@
{ MP_QSTR_pclk_idle_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
{ MP_QSTR_pclk_active_low, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
{ MP_QSTR_refresh_on_demand, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
{ MP_QSTR_rgb565_dither, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
};

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

self->callback = mp_const_none;

self->rgb565_dither = (uint8_t)args[ARG_rgb565_dither].u_bool;

self->bus_config.pclk_hz = (uint32_t)args[ARG_freq].u_int;
self->bus_config.hsync_pulse_width = (uint32_t)args[ARG_hsync_pulse_width].u_int;
self->bus_config.hsync_back_porch = (uint32_t)args[ARG_hsync_back_porch].u_int;
Expand Down Expand Up @@ -345,6 +351,8 @@

mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)obj;

if (bpp != 16 && self->rgb565_dither) self->rgb565_dither = 0;

if (bpp == 16 && rgb565_byte_swap) {
/*
We change the pins aound when the bus width is 16 and wanting to
Expand Down
Loading

0 comments on commit 8e3db46

Please sign in to comment.