Skip to content

Commit 575818b

Browse files
authored
Merge pull request #3 from hexthat/patch-1
feather_m4_express with miniTFT joypad featherwing
2 parents 3c7cac6 + 8fa98d1 commit 575818b

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../stage.py
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
brightness = 1 # 0 full off, 1 full on, 0.5 half
56+
backlight.duty_cycle = int(255 * min(max(1 - brightness, 0.0), 1.0))
57+
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)
58+
displayio.release_displays()
59+
while not spi.try_lock():
60+
pass
61+
spi.configure(baudrate=24000000)
62+
spi.unlock()
63+
ss.pin_mode(8, ss.OUTPUT)
64+
ss.digital_write(8, True) # Reset the Display via Seesaw
65+
display_bus = displayio.FourWire(spi,
66+
command=board.D6,
67+
chip_select=board.D5)
68+
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80, rowstart=24)
69+
ss.pin_mode_bulk(button_mask, ss.INPUT_PULLUP)
70+
# clean up some RAM
71+
del _INIT_SEQUENCE, brightness
72+
73+
def buttons():
74+
"""
75+
Return a set of buttons with current push values
76+
"""
77+
button_values = ss.digital_read_bulk(button_mask)
78+
return Buttons(*[not button_values & (1 << button) for button in
79+
(BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT,
80+
BUTTON_A, BUTTON_B, BUTTON_SEL)])

0 commit comments

Comments
 (0)