Skip to content

Commit f9024a1

Browse files
committed
Update firmware to support BHB v5
1 parent af81e0a commit f9024a1

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

firmware/noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
def blacken(session):
66
"""Run black code formater."""
77
session.install("black==19.3b0", "isort==4.3.21")
8-
files = ["noxfile.py", "code.py", "winterbloom_bhb"]
8+
files = ["noxfile.py", "winterbloom_bhb"]
99
session.run("isort", "--recursive", *files)
1010
session.run("black", *files)
1111

1212

1313
@nox.session(python="3")
1414
def lint(session):
1515
session.install("flake8==3.7.8", "black==19.3b0")
16-
files = ["noxfile.py", "code.py", "winterbloom_bhb"]
16+
files = ["noxfile.py", "winterbloom_bhb"]
1717
session.run("black", "--check", *files)
1818
session.run("flake8", *files)

firmware/winterbloom_bhb/bhb.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,60 @@
2222

2323
import time
2424

25-
import audioio
2625
import audiocore
26+
import audioio
2727
import board
2828
import digitalio
2929
import winterbloom_voltageio
3030

31+
try:
32+
import _bhb
33+
except ImportError:
34+
raise EnvironmentError("This BHB library requires CircuitPython >= 6.0.0")
35+
36+
37+
def _detect_board_revision():
38+
v5pin = digitalio.DigitalInOut(board.V5)
39+
v5pin.switch_to_input(pull=digitalio.Pull.UP)
40+
41+
# Pulled low on v5+, pull-up will make it true
42+
# on <=v4.
43+
if not v5pin.value:
44+
return 5
45+
else:
46+
return 4
47+
48+
49+
class _AnalogIn:
50+
def __init__(self):
51+
_bhb.init_adc()
52+
53+
@property
54+
def value(self):
55+
return _bhb.read_adc()
56+
3157

3258
class BigHonkingButton:
3359
def __init__(self):
60+
self.board_revision = _detect_board_revision()
3461
self.pitch_settle_time = 0.001
3562
self._button = digitalio.DigitalInOut(board.BUTTON)
3663
self._button.switch_to_input(pull=digitalio.Pull.UP)
3764
self._gate_in = digitalio.DigitalInOut(board.GATE_IN)
3865
self._gate_in.switch_to_input()
3966
self._gate_out = digitalio.DigitalInOut(board.GATE_OUT)
4067
self._gate_out.switch_to_output()
41-
self._pitch_in = winterbloom_voltageio.VoltageIn.from_pin(board.PITCH_IN)
42-
self._pitch_in.direct_calibration(
43-
{64736: -2.0, 48384: -1.0, 32048: 0, 15552: 1.0, 128: 2.0}
44-
)
68+
self._pitch_in = winterbloom_voltageio.VoltageIn(_AnalogIn())
69+
70+
if self.board_revision >= 5:
71+
self._pitch_in.direct_calibration(
72+
{4068: -5.0, 3049: -2.5, 2025: 0, 1001: 2.5, 8: 5.0}
73+
)
74+
else:
75+
self._pitch_in.direct_calibration(
76+
{4068: -2.0, 3049: -1.0, 2025: 0, 1001: 1.0, 8: 2.0}
77+
)
78+
4579
self.audio_out = audioio.AudioOut(board.HONK_OUT)
4680

4781
self._last_gate_value = False

0 commit comments

Comments
 (0)