Skip to content

Commit 6afb677

Browse files
authored
Add files via upload
1 parent a2c31b8 commit 6afb677

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
from collections import namedtuple
2+
import board
3+
from micropython import const
4+
from adafruit_seesaw.seesaw import Seesaw
5+
from adafruit_seesaw.pwmout import PWMOut
6+
import stage
7+
import displayio
8+
9+
BUTTON_RIGHT = const(7)
10+
BUTTON_DOWN = const(4)
11+
BUTTON_LEFT = const(3)
12+
BUTTON_UP = const(2)
13+
BUTTON_SEL = const(11)
14+
BUTTON_A = const(10)
15+
BUTTON_B = const(9)
16+
17+
Buttons = namedtuple("Buttons", "up down left right a b select")
18+
19+
button_mask = ((1 << BUTTON_RIGHT) |
20+
(1 << BUTTON_DOWN) |
21+
(1 << BUTTON_LEFT) |
22+
(1 << BUTTON_UP) |
23+
(1 << BUTTON_SEL) |
24+
(1 << BUTTON_A) |
25+
(1 << BUTTON_B))
26+
27+
_INIT_SEQUENCE = bytearray(
28+
b"\x01\x80\x96" # SWRESET and Delay 150ms
29+
b"\x11\x80\xff" # SLPOUT and Delay
30+
b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1
31+
b"\xb2\x03\x01\x2C\x2D" # _FRMCTR2
32+
b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" # _FRMCTR3
33+
b"\xb4\x01\x07" # _INVCTR line inversion
34+
b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA
35+
b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V
36+
b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency
37+
b"\xc3\x02\x8a\x2a"
38+
b"\xc4\x02\x8a\xee"
39+
b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V
40+
b"\x20\x00" # _INVOFF
41+
b"\x36\x01\x68" # _MADCTL bottom to top refresh
42+
# 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie,
43+
# fix on VTL
44+
b"\x3a\x01\x05" # COLMOD - 16bit color
45+
b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma
46+
b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1
47+
b"\x13\x80\x0a" # _NORON
48+
b"\x29\x80\x64" # _DISPON
49+
)
50+
51+
i2c = board.I2C()
52+
spi = board.SPI()
53+
ss = Seesaw(i2c, 0x5E)
54+
backlight = PWMOut(ss, 5)
55+
backlight.duty_cycle = int(255 * min(max(1 - 0.1, 0.0), 1.0))
56+
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)
57+
displayio.release_displays()
58+
while not spi.try_lock():
59+
pass
60+
spi.configure(baudrate=24000000)
61+
spi.unlock()
62+
ss.pin_mode(8, ss.OUTPUT)
63+
ss.digital_write(8, True) # Reset the Display via Seesaw
64+
display_bus = displayio.FourWire(spi,
65+
command=board.D10,
66+
chip_select=board.D9)
67+
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24)
68+
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)
69+
70+
def buttons():
71+
"""
72+
Return a set of buttons with current push values
73+
"""
74+
button_values = ss.digital_read_bulk(button_mask)
75+
return Buttons(*[not button_values & (1 << button) for button in
76+
(BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT,
77+
BUTTON_A, BUTTON_B, BUTTON_SEL)])

0 commit comments

Comments
 (0)