Skip to content

Commit b2ffb2e

Browse files
committed
Clean up and add missing parts for minitft featherwing
1 parent 575818b commit b2ffb2e

File tree

3 files changed

+55
-55
lines changed

3 files changed

+55
-55
lines changed

feather_m4_minitft_featherwing/stage.py

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../stage.py
Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
1-
from collections import namedtuple
21
import board
32
from micropython import const
43
from adafruit_seesaw.seesaw import Seesaw
54
from adafruit_seesaw.pwmout import PWMOut
65
import stage
76
import displayio
87

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)
168

17-
Buttons = namedtuple("Buttons", "up down left right a b select")
9+
K_UP = const(4)
10+
K_LEFT = const(8)
11+
K_DOWN = const(16)
12+
K_RIGHT = const(128)
13+
K_X = const(512)
14+
K_O = const(1024)
15+
K_SELECT = const(2048)
16+
K_START = const(0)
1817

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(
18+
_INIT_SEQUENCE = (
2819
b"\x01\x80\x96" # SWRESET and Delay 150ms
2920
b"\x11\x80\xff" # SLPOUT and Delay
3021
b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1
@@ -48,33 +39,44 @@
4839
b"\x29\x80\x64" # _DISPON
4940
)
5041

42+
43+
class GamePadSeesaw:
44+
mask = K_RIGHT | K_DOWN | K_LEFT | K_UP | K_SELECT | K_O | K_X
45+
46+
def __init__(self, ss):
47+
ss.pin_mode_bulk(self.mask, ss.INPUT_PULLUP)
48+
self.ss = ss
49+
50+
def get_pressed(self):
51+
return self.ss.digital_read_bulk(self.mask)
52+
53+
54+
class DummyAudio:
55+
def play(self, f, loop=False):
56+
pass
57+
58+
def stop(self):
59+
pass
60+
61+
def mute(self, mute):
62+
pass
63+
64+
5165
i2c = board.I2C()
52-
spi = board.SPI()
5366
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)
67+
spi = board.SPI()
5868
displayio.release_displays()
5969
while not spi.try_lock():
6070
pass
6171
spi.configure(baudrate=24000000)
6272
spi.unlock()
6373
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)])
74+
ss.digital_write(8, True) # reset display
75+
display_bus = displayio.FourWire(spi, command=board.D6, chip_select=board.D5)
76+
display = displayio.Display(display_bus, _INIT_SEQUENCE, width=160, height=80,
77+
rowstart=24)
78+
del _INIT_SEQUENCE
79+
buttons = GamePadSeesaw(ss)
80+
audio = DummyAudio()
81+
backlight = PWMOut(ss, 5)
82+
backlight.duty_cycle = 0

itsybitsy_m4_express/ugame.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
b"\x29\x80\x64" # _DISPON
4646
)
4747

48+
49+
class DummyAudio:
50+
def play(self, f, loop=False):
51+
pass
52+
53+
def stop(self):
54+
pass
55+
56+
def mute(self, mute):
57+
pass
58+
59+
4860
displayio.release_displays()
4961
_tft_spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI)
5062
_tft_spi.try_lock()
@@ -55,7 +67,6 @@
5567
display = displayio.Display(_fourwire, _INIT_SEQUENCE, width=160, height=128,
5668
rotation=0, backlight_pin=board.A5)
5769
display.auto_brightness = True
58-
5970
buttons = gamepad.GamePad(
6071
digitalio.DigitalInOut(board.SCL),
6172
digitalio.DigitalInOut(board.D12),
@@ -65,17 +76,4 @@
6576
digitalio.DigitalInOut(board.D7),
6677
digitalio.DigitalInOut(board.SDA),
6778
)
68-
69-
70-
class DummyAudio:
71-
def play(self, f, loop=False):
72-
pass
73-
74-
def stop(self):
75-
pass
76-
77-
def mute(self, mute):
78-
pass
79-
80-
8179
audio = DummyAudio()

0 commit comments

Comments
 (0)