Skip to content

Commit be45172

Browse files
committed
Changes from pre-commit
1 parent 9a6fda8 commit be45172

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

adafruit_mcp2515/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
"""
2626

2727
from collections import namedtuple
28+
29+
try:
30+
from typing_extensions import Literal
31+
except ImportError:
32+
pass
2833
from struct import unpack_from, pack_into
2934
from time import sleep
3035
from micropython import const
@@ -241,7 +246,7 @@ def __init__(
241246
cs_pin,
242247
*,
243248
baudrate: int = 250000,
244-
xtal_frequency: int = 16000000,
249+
crystal_freq: Literal[8000000, 16000000] = 16000000,
245250
loopback: bool = False,
246251
silent: bool = False,
247252
auto_restart: bool = False,
@@ -253,7 +258,7 @@ def __init__(
253258
:param ~digitalio.DigitalInOut cs_pin: SPI bus enable pin
254259
:param int baudrate: The bit rate of the bus in Hz, using a 16Mhz crystal. All devices on\
255260
the bus must agree on this value. Defaults to 250000.
256-
:param bool xtal_frequency: MCP2515 crystal frequency. Valid values are:\
261+
:param Literal crystal_freq: MCP2515 crystal frequency. Valid values are:\
257262
16000000 and 8000000. Defaults to 16000000 (16MHz).\
258263
:param bool loopback: Receive only packets sent from this device, and send only to this\
259264
device. Requires that `silent` is also set to `True`, but only prevents transmission to\
@@ -289,7 +294,7 @@ def __init__(
289294
self._mode = None
290295
self._bus_state = BusState.ERROR_ACTIVE
291296
self._baudrate = baudrate
292-
self._xtal_frequency = xtal_frequency
297+
self._crystal_freq = crystal_freq
293298
self._loopback = loopback
294299
self._silent = silent
295300

@@ -632,10 +637,10 @@ def _get_tx_buffer(self):
632637

633638
def _set_baud_rate(self):
634639
# ******* set baud rate ***********
635-
if self._xtal_frequency not in (16000000, 8000000):
640+
if self._crystal_freq not in (16000000, 8000000):
636641
raise RuntimeError("Incorrect xtal frequency")
637642

638-
cnf1, cnf2, cnf3 = _BAUD_RATES[self._xtal_frequency][self.baudrate]
643+
cnf1, cnf2, cnf3 = _BAUD_RATES[self._crystal_freq][self.baudrate]
639644

640645
self._set_register(_CNF1, cnf1)
641646
self._set_register(_CNF2, cnf2)

0 commit comments

Comments
 (0)