Skip to content

Commit 641dec3

Browse files
committed
improves performance on the i80 bus.
1 parent ff2381e commit 641dec3

File tree

4 files changed

+79
-18
lines changed

4 files changed

+79
-18
lines changed

api_drivers/common_api_drivers/display/st7789/_st7789_init.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from micropython import const # NOQA
33

44
import lvgl as lv # NOQA
5+
import lcd_bus
56

67

78
_SWRESET = const(0x01)
89
_SLPOUT = const(0x11)
910
_MADCTL = const(0x36)
1011
_COLMOD = const(0x3A)
11-
_IFMODE = const(0xB0)
1212
_PORCTRL = const(0xB2)
1313
_GCTRL = const(0xB7)
1414
_VCOMS = const(0xBB)
@@ -26,6 +26,9 @@
2626
_DISPON = const(0x29)
2727
_NORON = const(0x13)
2828

29+
_RAMCTRL = const(0xB0)
30+
_RGB565SWAP = const(0x08)
31+
2932

3033
def init(self):
3134
param_buf = bytearray(14)
@@ -53,9 +56,16 @@ def init(self):
5356
param_buf[1] = 0x82
5457
self.set_params(0xB6, param_mv[:2])
5558

56-
# param_buf[0] = 0x00
57-
# param_buf[1] = 0xE0
58-
# self.set_params(_IFMODE, param_mv[:2])
59+
# sets swapping the bytes at the hardware level.
60+
61+
if (
62+
self._rgb565_byte_swap and
63+
isinstance(self._data_bus, lcd_bus.I80Bus) and
64+
self._data_bus.get_lane_count() == 8
65+
):
66+
param_buf[0] = 0x00
67+
param_buf[1] = 0xF0 | _RGB565SWAP
68+
self.set_params(_RAMCTRL, param_mv[:2])
5969

6070
color_size = lv.color_format_get_size(self._color_space)
6171
if color_size == 2: # NOQA

api_drivers/common_api_drivers/display/st7789/st7789.py

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from micropython import const # NOQA
22
import display_driver_framework
3+
import lcd_bus
34

45

56
STATE_HIGH = display_driver_framework.STATE_HIGH
@@ -20,7 +21,62 @@
2021
class ST7789(display_driver_framework.DisplayDriver):
2122
_ORIENTATION_TABLE = (
2223
0x0,
23-
_MADCTL_MV | _MADCTL_MY,
24+
_MADCTL_MV | _MADCTL_MX,
2425
_MADCTL_MY | _MADCTL_MX,
25-
_MADCTL_MV | _MADCTL_MX
26+
_MADCTL_MV | _MADCTL_MY
2627
)
28+
29+
def __init__(
30+
self,
31+
data_bus,
32+
display_width,
33+
display_height,
34+
frame_buffer1=None,
35+
frame_buffer2=None,
36+
reset_pin=None,
37+
reset_state=STATE_HIGH,
38+
power_pin=None,
39+
power_on_state=STATE_HIGH,
40+
backlight_pin=None,
41+
backlight_on_state=STATE_HIGH,
42+
offset_x=0,
43+
offset_y=0,
44+
color_byte_order=BYTE_ORDER_RGB,
45+
color_space=lv.COLOR_FORMAT.RGB888, # NOQA
46+
rgb565_byte_swap=False,
47+
):
48+
49+
if color_space != lv.COLOR_FORMAT.RGB565:
50+
rgb565_byte_swap = False
51+
52+
self._rgb565_byte_swap = rgb565_byte_swap
53+
54+
if (
55+
isinstance(data_bus, lcd_bus.I80Bus) and
56+
data_bus.get_lane_count() == 8
57+
):
58+
rgb565_byte_swap = False
59+
60+
super().__init__(
61+
data_bus=data_bus,
62+
display_width=display_width,
63+
display_height=display_height,
64+
frame_buffer1=frame_buffer1,
65+
frame_buffer2=frame_buffer2,
66+
reset_pin=reset_pin,
67+
reset_state=reset_state,
68+
power_pin=power_pin,
69+
power_on_state=power_on_state,
70+
backlight_pin=backlight_pin,
71+
backlight_on_state=backlight_on_state,
72+
offset_x=offset_x,
73+
offset_y=offset_y,
74+
color_byte_order=color_byte_order,
75+
color_space=color_space, # NOQA
76+
rgb565_byte_swap=rgb565_byte_swap,
77+
_cmd_bits=8,
78+
_param_bits=8,
79+
_init_bus=True
80+
)
81+
82+

api_drivers/common_api_drivers/display/st7796/st7796.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ class ST7796(display_driver_framework.DisplayDriver):
4040
# We just have to tell lvgl that we want to use
4141

4242
_ORIENTATION_TABLE = (
43-
_MADCTL_MX,
44-
_MADCTL_MV | _MADCTL_MY | _MADCTL_MX,
45-
_MADCTL_MY,
46-
_MADCTL_MV
43+
0x0,
44+
_MADCTL_MV | _MADCTL_MX,
45+
_MADCTL_MY | _MADCTL_MX,
46+
_MADCTL_MV | _MADCTL_MY
4747
)

ext_mod/lcd_bus/esp32_src/i80_bus.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
ARG_dc_data_high,
5656
ARG_cs_active_high,
5757
ARG_reverse_color_bits,
58-
ARG_swap_color_bytes,
5958
ARG_pclk_active_low,
6059
ARG_pclk_idle_low,
6160
};
@@ -87,7 +86,6 @@
8786
{ MP_QSTR_dc_data_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } },
8887
{ MP_QSTR_cs_active_high, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
8988
{ MP_QSTR_reverse_color_bits, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
90-
{ MP_QSTR_swap_color_bytes, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
9189
{ MP_QSTR_pclk_active_low, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } },
9290
{ MP_QSTR_pclk_idle_low, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = false } }
9391
};
@@ -148,7 +146,6 @@
148146
self->panel_io_config.dc_levels.dc_data_level = (unsigned int)args[ARG_dc_data_high].u_bool;
149147
self->panel_io_config.flags.cs_active_high = (unsigned int)args[ARG_cs_active_high].u_bool;
150148
self->panel_io_config.flags.reverse_color_bits = (unsigned int)args[ARG_reverse_color_bits].u_bool;
151-
self->panel_io_config.flags.swap_color_bytes = (unsigned int)args[ARG_swap_color_bytes].u_bool;
152149
self->panel_io_config.flags.pclk_active_neg = (unsigned int)args[ARG_pclk_active_low].u_bool;
153150
self->panel_io_config.flags.pclk_idle_low = (unsigned int)args[ARG_pclk_idle_low].u_bool;
154151

@@ -182,7 +179,6 @@
182179
printf("dc_data_level=%d\n", self->panel_io_config.dc_levels.dc_data_level);
183180
printf("cs_active_high=%d\n", self->panel_io_config.flags.cs_active_high);
184181
printf("reverse_color_bits=%d\n", self->panel_io_config.flags.reverse_color_bits);
185-
printf("swap_color_bytes=%d\n", self->panel_io_config.flags.swap_color_bytes);
186182
printf("pclk_active_neg=%d\n", self->panel_io_config.flags.pclk_active_neg);
187183
printf("pclk_idle_low=%d\n", self->panel_io_config.flags.pclk_idle_low);
188184
#endif
@@ -202,11 +198,10 @@
202198
#endif
203199

204200
mp_lcd_i80_bus_obj_t *self = (mp_lcd_i80_bus_obj_t *)obj;
201+
self->rgb565_byte_swap = false;
205202

206-
if (bpp == 16) {
207-
self->rgb565_byte_swap = rgb565_byte_swap;
208-
} else {
209-
self->rgb565_byte_swap = false;
203+
if (rgb565_byte_swap && bpp == 16) {
204+
self->panel_io_config.flags.swap_color_bytes = 1;
210205
}
211206

212207
self->panel_io_config.lcd_cmd_bits = (int)cmd_bits;

0 commit comments

Comments
 (0)