blob: 3dfb82889efb4891ccc3068f1474ffd573f32976 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# Describe the layout used in the keyboard
#
import board
from digitalio import Pull
from kmk.scanners import DiodeOrientation
col_pins = (board.GP26,board.GP27,board.GP28,board.GP29)
row_pins = (board.GP22,board.GP20,board.GP23,board.GP21)
diode_orientation = DiodeOrientation.ROW2COL
from digitalio import DigitalInOut, Direction, Pull
def check_key():
""" Check if a key is pressed and return True if so.
Scan all the keys only once, and return False if nothing where pressed.
"""
if DiodeOrientation == DiodeOrientation.ROW2COL:
inputs = row_pins
outputs = col_pins
else:
inputs = col_pins
outputs = row_pins
for in_pin in inputs:
with DigitalInOut(in_pin) as in_io:
in_io.direction = Direction.INPUT
in_io.pull = Pull.DOWN
for out_pin in outputs:
with DigitalInOut(out_pin) as out_io:
out_io.direction = Direction.OUTPUT
out_io.value = True
result = in_io.value
if result:
return result
return False
def set_keyboard(keyboard):
""" Initialize the kmk keyboard with the values defined here.
"""
keyboard.row_pins = row_pins
keyboard.col_pins = col_pins
keyboard.diode_orientation = diode_orientation
|