Skip to content

Commit 01702bb

Browse files
committed
adds rm67162 display driver
1 parent 197798c commit 01702bb

File tree

2 files changed

+271
-0
lines changed

2 files changed

+271
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
from micropython import const # NOQA
2+
import lvgl as lv
3+
import time
4+
5+
6+
_SLPOUT = const(0x11)
7+
_SWRESET = const(0x01)
8+
_INVON = const(0x21)
9+
_INVOFF = const(0x20)
10+
11+
_DISPOFF = const(0x28)
12+
_DISPON = const(0x29)
13+
14+
15+
_CASET = const(0x2A)
16+
_RASET = const(0x2B)
17+
18+
_RAMWR = const(0x2C)
19+
_TEOFF = const(0x34)
20+
_MADCTL = const(0x36)
21+
22+
# Set Color Enhance
23+
_IMGEHCCTR = const(0x58)
24+
25+
# Set Color Enhance 1
26+
_CESLRCTR_L = const(0x5A)
27+
_CESLRCTR_H = const(0x5B)
28+
29+
_COLMOD = const(0x3A)
30+
_RGB565 = const(0x75) # 16bit/pixel (65,536 colors)
31+
_RGB888 = const(0x77) # 24bit/pixel (16.7M colors)
32+
33+
# Write Display Brightness
34+
# 0 to 255
35+
_WRDISBV = const(0x51)
36+
37+
# Write Display Control
38+
_WRCTRLD = const(0x53)
39+
_BCTRL = const(0x20)
40+
_DD = const(0x08)
41+
42+
# Set Dual SPI Mode
43+
_SetDSPIMode = const(0xC4)
44+
_DSPI_EN = const(0x21)
45+
46+
# CMD Mode Switch
47+
# 0x00 == user mode
48+
_CMDMode = const(0xFE)
49+
50+
# High Brightness Mode
51+
# 0x00 disable
52+
# 0x02 enable
53+
_SETHBM = const(0xB0)
54+
55+
56+
def init(self):
57+
self._br_val = 0
58+
59+
buf = self._param_buf
60+
mv = self._param_mv
61+
62+
time.sleep_ms(120) # NOQA
63+
self.set_params(_SWRESET)
64+
time.sleep_ms(120) # NOQA
65+
66+
num_lanes = self._data_bus.get_lane_count()
67+
if num_lanes == 2:
68+
buf[0] = _DSPI_EN
69+
self.set_params(_SetDSPIMode, mv[:1])
70+
elif num_lanes not in (1, 8):
71+
raise RuntimeError('display only supports I8080 8 lane, SPI and DUAL SPI')
72+
73+
self.set_params(_SLPOUT)
74+
time.sleep_ms(120) # NOQA
75+
76+
buf[0] = 0x05
77+
self.set_params(_CMDMode, mv[:1])
78+
79+
self.set_params(0x05, mv[:1])
80+
81+
buf[0] = 0x01
82+
self.set_params(_CMDMode, mv[:1])
83+
84+
buf[0] = 0x25
85+
self.set_params(0x73, mv[:1])
86+
87+
buf[0] = 0x00
88+
self.set_params(_CMDMode, mv[:1])
89+
90+
self.set_params(_TEOFF)
91+
92+
buf[0] = (
93+
self._madctl(
94+
self._color_byte_order,
95+
self._ORIENTATION_TABLE # NOQA
96+
)
97+
)
98+
self.set_params(_MADCTL, mv[:1])
99+
100+
color_size = lv.color_format_get_size(self._color_space)
101+
if color_size == 2: # NOQA
102+
buf[0] = _RGB565
103+
elif color_size == 3:
104+
buf[0] = _RGB888
105+
else:
106+
raise RuntimeError(
107+
f'{self.__class__.__name__} IC only supports '
108+
'RGB565 and RGB888'
109+
)
110+
111+
self.set_params(_COLMOD, mv[:1])
112+
113+
buf[0] = _BCTRL | _DD
114+
self.set_params(_WRCTRLD, mv[:1])
115+
116+
buf[0] = 0x7F
117+
self.set_params(_CESLRCTR_H, mv[:1])
118+
119+
buf[0] = 0xFF
120+
self.set_params(_CESLRCTR_L, mv[:1])
121+
122+
buf[0] = 0x00
123+
self.set_params(_IMGEHCCTR, mv[:1])
124+
self.set_params(_WRDISBV, mv[:1])
125+
self.set_params(_SETHBM, mv[:1])
126+
self.set_params(_DISPON)
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
from micropython import const # NOQA
2+
import display_driver_framework
3+
import lvgl as lv
4+
5+
6+
STATE_HIGH = display_driver_framework.STATE_HIGH
7+
STATE_LOW = display_driver_framework.STATE_LOW
8+
STATE_PWM = display_driver_framework.STATE_PWM
9+
10+
BYTE_ORDER_RGB = display_driver_framework.BYTE_ORDER_RGB
11+
BYTE_ORDER_BGR = display_driver_framework.BYTE_ORDER_BGR
12+
13+
14+
_MADCTL_MY = const(0x01) # mirror y
15+
_MADCTL_MX = const(0x02) # mirror x
16+
_MADCTL_MV = const(0x20) # x, y = y, x
17+
18+
19+
# Write Display Brightness
20+
# 0 to 255
21+
_WRDISBV = const(0x51)
22+
23+
# Set Color Enhance
24+
_IMGEHCCTR = const(0x58)
25+
_SLR_EN = const(0x04) # Sunlight Readable
26+
# Sunlight Readable Level values are 0, 1, and 3
27+
28+
# Set Color Enhance 1
29+
_CESLRCTR_L = const(0x5A)
30+
_CESLRCTR_H = const(0x5B)
31+
32+
# High Brightness Mode
33+
# 0x00 disable
34+
# 0x02 enable
35+
_SETHBM = const(0xB0)
36+
_HBM_EN = const(0x02)
37+
38+
39+
class RM67162(display_driver_framework.DisplayDriver):
40+
_ORIENTATION_TABLE = (
41+
0x00,
42+
_MADCTL_MV,
43+
_MADCTL_MY | _MADCTL_MX,
44+
_MADCTL_MY | _MADCTL_MX | _MADCTL_MV
45+
)
46+
47+
def __init__(
48+
self,
49+
data_bus,
50+
display_width,
51+
display_height,
52+
frame_buffer1=None,
53+
frame_buffer2=None,
54+
reset_pin=None,
55+
reset_state=STATE_HIGH,
56+
power_pin=None,
57+
power_on_state=STATE_HIGH,
58+
backlight_pin=None,
59+
backlight_on_state=STATE_HIGH,
60+
offset_x=0,
61+
offset_y=0,
62+
color_byte_order=BYTE_ORDER_RGB,
63+
color_space=lv.COLOR_FORMAT.RGB888, # NOQA
64+
rgb565_byte_swap=False
65+
):
66+
67+
self.__brightness = 0
68+
self.__sunlight = 0
69+
self.__ambient = 0x7FFF
70+
self.__high_brightness = 0x00
71+
72+
super().__init__(
73+
data_bus=data_bus,
74+
display_width=display_width,
75+
display_height=display_height,
76+
frame_buffer1=frame_buffer1,
77+
frame_buffer2=frame_buffer2,
78+
reset_pin=reset_pin,
79+
reset_state=reset_state,
80+
power_pin=power_pin,
81+
power_on_state=power_on_state,
82+
backlight_pin=backlight_pin,
83+
backlight_on_state=backlight_on_state,
84+
offset_x=offset_x,
85+
offset_y=offset_y,
86+
color_byte_order=color_byte_order,
87+
color_space=color_space,
88+
rgb565_byte_swap=rgb565_byte_swap
89+
)
90+
91+
def set_brightness(self, val):
92+
# convert the value from a 0.0 - 100.0 scale to a 0 - 255 scale
93+
val = int(val * 255 / 100)
94+
# clamp the balue so it is 0 - 255
95+
val = max(min(val, 255), 0)
96+
97+
self.__brightness = val
98+
self._param_buf[0] = val
99+
100+
self.set_params(_WRDISBV, self._param_mv[:1])
101+
102+
def get_brightness(self):
103+
return round(self.__brightness / 255.0 * 100.0, 2)
104+
105+
def set_ambient_light_level(self, val):
106+
val = int(val * 65535 / 100)
107+
val = max(min(val, 65535), 0)
108+
109+
self.__ambient = val
110+
self._param_buf[0] = val >> 8
111+
self.set_params(_CESLRCTR_H, self._param_mv[:1])
112+
113+
self._param_buf[0] = val & 0xFF
114+
self.set_params(_CESLRCTR_L, self._param_mv[:1])
115+
116+
def get_amblent_light_level(self):
117+
return round(self.__ambient / 65535.0 * 100.0, 2)
118+
119+
def set_sunlight_enhance(self, val):
120+
if val == -1:
121+
self.__sunlight &= ~_SLR_EN
122+
else:
123+
val = min(val, 3)
124+
self.__sunlight = _SLR_EN | val
125+
126+
self._param_buf[0] = self.__sunlight
127+
self.set_params(_IMGEHCCTR, self._param_mv[:1])
128+
129+
def get_sunlight_enhance(self):
130+
if self.__sunlight & _SLR_EN:
131+
return self.__sunlight & ~_SLR_EN
132+
133+
return -1
134+
135+
def set_high_brightness(self, val):
136+
if val:
137+
self.__high_brightness |= _HBM_EN
138+
else:
139+
self.__high_brightness &= ~_HBM_EN
140+
141+
self._param_buf[0] = self.__high_brightness
142+
self.set_params(_SETHBM, self._param_mv[:1])
143+
144+
def get_high_brightness(self):
145+
return bool(self.__high_brightness & _HBM_EN)

0 commit comments

Comments
 (0)