Skip to content

Commit dc4b58e

Browse files
committed
refactor keyboard_featherwing to use TFTFeatherWing superclass
1 parent 4748599 commit dc4b58e

File tree

2 files changed

+18
-32
lines changed

2 files changed

+18
-32
lines changed

adafruit_featherwing/keyboard_featherwing.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@
2020
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing.git"
2121

2222
import board
23-
import digitalio
24-
import displayio
2523
import adafruit_ili9341
26-
from adafruit_stmpe610 import Adafruit_STMPE610_SPI
27-
import sdcardio
28-
import storage
2924
from bbq10keyboard import BBQ10Keyboard
3025
import neopixel
3126

3227

3328
# pylint: disable-msg=too-few-public-methods
3429
# pylint: disable-msg=too-many-arguments
35-
class KeyboardFeatherwing:
30+
from adafruit_featherwing.tft_featherwing import TFTFeatherWing
31+
32+
33+
class KeyboardFeatherwing(TFTFeatherWing):
3634
"""Class representing a `Keyboard Featherwing`
3735
<https://www.tindie.com/products/arturo182/keyboard-featherwing-qwerty-keyboard-26-lcd/>`_.
3836
@@ -48,32 +46,15 @@ def __init__(
4846
sd_cs=None,
4947
neopixel_pin=None,
5048
):
51-
displayio.release_displays()
52-
if spi is None:
53-
spi = board.SPI()
54-
if cs is None:
55-
cs = board.D9
56-
if dc is None:
57-
dc = board.D10
49+
super().__init__(spi, cs, dc, ts_cs, sd_cs)
50+
5851
if i2c is None:
5952
i2c = board.I2C()
60-
if ts_cs is None:
61-
ts_cs = board.D6
62-
if sd_cs is None:
63-
sd_cs = board.D5
6453
if neopixel_pin is None:
6554
neopixel_pin = board.D11
6655

67-
self.touchscreen = Adafruit_STMPE610_SPI(spi, digitalio.DigitalInOut(ts_cs))
68-
69-
display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
70-
self.display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
56+
self.display = adafruit_ili9341.ILI9341(
57+
self._display_bus, width=320, height=240
58+
)
7159
self.neopixel = neopixel.NeoPixel(neopixel_pin, 1)
7260
self.keyboard = BBQ10Keyboard(i2c)
73-
self._sdcard = None
74-
try:
75-
self._sdcard = sdcardio.SDCard(spi, sd_cs)
76-
vfs = storage.VfsFat(self._sdcard)
77-
storage.mount(vfs, "/sd")
78-
except OSError as error:
79-
print("No SD card found:", error)

adafruit_featherwing/tft_featherwing.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
import sdcardio
2323
import storage
2424

25-
# pylint: disable-msg=too-few-public-methods
25+
26+
# pylint: disable-msg=too-few-public-methods, too-many-arguments
2627
class TFTFeatherWing:
2728
"""Class representing an `TFT FeatherWing 2.4
2829
<https://www.adafruit.com/product/3315>`_.
2930
3031
"""
3132

32-
def __init__(self, spi=None, cs=None, dc=None):
33+
def __init__(self, spi=None, cs=None, dc=None, ts_cs=None, sd_cs=None):
3334
displayio.release_displays()
3435
if spi is None:
3536
spi = board.SPI()
@@ -38,12 +39,16 @@ def __init__(self, spi=None, cs=None, dc=None):
3839
if dc is None:
3940
dc = board.D10
4041

41-
ts_cs = digitalio.DigitalInOut(board.D6)
42+
if ts_cs is None:
43+
ts_cs = board.D6
44+
if sd_cs is None:
45+
sd_cs = board.D5
46+
47+
ts_cs = digitalio.DigitalInOut(ts_cs)
4248
self.touchscreen = Adafruit_STMPE610_SPI(spi, ts_cs)
4349

4450
self._display_bus = displayio.FourWire(spi, command=dc, chip_select=cs)
4551

46-
sd_cs = board.D5
4752
self._sdcard = None
4853
try:
4954
self._sdcard = sdcardio.SDCard(spi, sd_cs)

0 commit comments

Comments
 (0)