Skip to content

Commit 8c6c3a9

Browse files
authored
add preliminary support for Adafruit macropad (#3)
1 parent e5f1d30 commit 8c6c3a9

File tree

18 files changed

+144
-1
lines changed

18 files changed

+144
-1
lines changed

fw/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
### Check out the official project website [here](https://t9-library-generator.uk.r.appspot.com/)
12
# Firmware
23
This code _should_ run on any CircuitPython-enabled board, but is most useful when there is >= 4MB of flash.
34
As of May 2021, it's only been tested on various RP2040 dev boards.
@@ -11,6 +12,7 @@ Currently supported boards:
1112
* [Pimoroni Tiny2040](./tiny2040)
1213
* [Raspberry Pi Pico](./pico)
1314
* [Adafruit QT Py RP2040](./qtpy2040)
15+
* [Adafruit MacroPad RP2040](./ada-macropad)
1416

1517
There are also [`macos`](./macos)/[`win32`](./win32) folders, which contain mocked IO dependencies so that the firmware can be
1618
tested natively on desktop. *For key press detection on Mac, you'll need to give accessibility permissions to Python*.

fw/ada-macropad/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Required (Circuit/Micro)Python Libraries:
2+
**MUST BE VERSION 7.0.0 OR NEWER!!!**
3+
**Make sure the following files are in a folder called `lib`, on your microcontroller**
4+
* adafruit_display_text
5+
* `adafruit_display_text/__init__.mpy`
6+
* `adafruit_display_text/bitmap_label.mpy`
7+
* `adafruit_display_text/label.mpy`
8+
* adafruit_hid
9+
* `adafruit_hid/__init__.mpy`
10+
* `adafruit_hid/consumer_control_code.mpy`
11+
* `adafruit_hid/consumer_control.mpy`
12+
* `adafruit_hid/keyboard_layout_us.mpy`
13+
* `adafruit_hid/keyboard.mpy`
14+
* `adafruit_hid/keycode.mpy`
15+
* `adafruit_hid/mouse.mpy`
16+
* `adafruit_simple_text_display.mpy`
17+
* `neopixel.mpy`

fw/ada-macropad/keyboard.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import usb_hid
2+
import adafruit_hid.keyboard
3+
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
4+
import adafruit_hid.keycode
5+
6+
class Keyboard():
7+
def __init__(self):
8+
self.keyboard = adafruit_hid.keyboard.Keyboard(usb_hid.devices)
9+
self.keyboard_layout = KeyboardLayoutUS(self.keyboard)
10+
11+
def press(self, key):
12+
self.keyboard.press(key)
13+
14+
def release_all(self):
15+
self.keyboard.release_all()
16+
17+
def write(self, text):
18+
self.keyboard_layout.write(text)
19+
20+
Keycode = adafruit_hid.keycode.Keycode

fw/ada-macropad/led.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import board
2+
import neopixel
3+
4+
class Led():
5+
def __init__(self):
6+
self.pixel = neopixel.NeoPixel(board.NEOPIXEL, 12)
7+
8+
def show_red(self):
9+
self.pixel.fill((150, 0, 0))
10+
11+
def show_green(self):
12+
self.pixel.fill((0, 150, 0))
13+
14+
def show_blue(self):
15+
self.pixel.fill((0, 0, 150))

fw/ada-macropad/library.t9l

1.33 MB
Binary file not shown.

fw/ada-macropad/t9_display.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import board
2+
from adafruit_simple_text_display import SimpleTextDisplay
3+
4+
class Display():
5+
def __init__(self):
6+
title=None
7+
title_scale=1
8+
title_length=80
9+
text_scale=2
10+
font=None
11+
self._text_lines = SimpleTextDisplay(
12+
title=title,
13+
title_color=SimpleTextDisplay.WHITE,
14+
title_scale=title_scale,
15+
title_length=title_length,
16+
text_scale=text_scale,
17+
font=font,
18+
colors=(SimpleTextDisplay.WHITE,),
19+
display=board.DISPLAY,
20+
)
21+
22+
def display_results(self, result, index):
23+
arr = result.words if len(result.words) > 0 else result.pres
24+
word_count = len(arr)
25+
if word_count > 0:
26+
# display can only display 2.5 lines
27+
for i in range(0, max(3, word_count)):
28+
adj_i = (i + index) % word_count
29+
w = arr[adj_i]
30+
# highlight the first line
31+
self._text_lines[i].text = ">"+w+"<" if i == 0 else w
32+
self._text_lines.show()

fw/ada-macropad/t9_keypad.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import board
3+
import keypad
4+
5+
class Keypad():
6+
def __init__(self, keys):
7+
self._key_pins = [getattr(board, "KEY%d" % (num + 1)) for num in list(range(12))]
8+
self._keys = keypad.Keys(self._key_pins, value_when_pressed=False, pull=True)
9+
self._key_map = [item for sublist in list(keys) for item in sublist]
10+
self._held_keys = []
11+
12+
@property
13+
def pressed_keys(self):
14+
current = self._keys.events.get()
15+
while current is not None:
16+
k = self._key_map[current.key_number]
17+
if current.pressed and k not in self._held_keys:
18+
self._held_keys.append(k)
19+
elif current.released and k in self._held_keys:
20+
self._held_keys.remove(k)
21+
current = self._keys.events.get()
22+
return self._held_keys

fw/core/code.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import time
22
from led import Led
3-
from keypad import Keypad
3+
from t9_keypad import Keypad
44
from keyboard import Keyboard
55
from keyboard import Keycode
6+
from t9_display import Display
67

78
NO_WORD = 0
89
PARTIAL_WORD = 1
@@ -35,6 +36,8 @@
3536
keyboard = Keyboard()
3637
time.sleep(0.5)
3738

39+
display = Display()
40+
3841
# Alternate macropad mode - map key input to function keys
3942
def run_macro_mode():
4043
macro_map = {
@@ -338,6 +341,7 @@ def poll_keys():
338341
elif pres_count > 0:
339342
word_index = (word_index + 1) % pres_count
340343
submit(result.pres[word_index])
344+
display.display_results(result, word_index)
341345
continue
342346
# backspace, pop results stack
343347
if c == '1':
@@ -372,6 +376,7 @@ def poll_keys():
372376
# if we've run out of valid words/prefixes for a key sequence, just start appending the number
373377
elif c >= '2' and c <= '9':
374378
emit_raw_text(c, False)
379+
display.display_results(result, word_index)
375380
last_result = result
376381

377382

fw/macos/t9_display.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Display():
2+
def __init__(self):
3+
pass
4+
5+
def display_results(self, result, index):
6+
pass
File renamed without changes.

0 commit comments

Comments
 (0)