25
25
"""
26
26
27
27
from collections import namedtuple
28
+
29
+ try :
30
+ from typing_extensions import Literal
31
+ except ImportError :
32
+ pass
28
33
from struct import unpack_from , pack_into
29
34
from time import sleep
30
35
from micropython import const
@@ -241,7 +246,7 @@ def __init__(
241
246
cs_pin ,
242
247
* ,
243
248
baudrate : int = 250000 ,
244
- xtal_frequency : int = 16000000 ,
249
+ crystal_freq : Literal [ 8000000 , 16000000 ] = 16000000 ,
245
250
loopback : bool = False ,
246
251
silent : bool = False ,
247
252
auto_restart : bool = False ,
@@ -253,7 +258,7 @@ def __init__(
253
258
:param ~digitalio.DigitalInOut cs_pin: SPI bus enable pin
254
259
:param int baudrate: The bit rate of the bus in Hz, using a 16Mhz crystal. All devices on\
255
260
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:\
257
262
16000000 and 8000000. Defaults to 16000000 (16MHz).\
258
263
:param bool loopback: Receive only packets sent from this device, and send only to this\
259
264
device. Requires that `silent` is also set to `True`, but only prevents transmission to\
@@ -289,7 +294,7 @@ def __init__(
289
294
self ._mode = None
290
295
self ._bus_state = BusState .ERROR_ACTIVE
291
296
self ._baudrate = baudrate
292
- self ._xtal_frequency = xtal_frequency
297
+ self ._crystal_freq = crystal_freq
293
298
self ._loopback = loopback
294
299
self ._silent = silent
295
300
@@ -632,10 +637,10 @@ def _get_tx_buffer(self):
632
637
633
638
def _set_baud_rate (self ):
634
639
# ******* set baud rate ***********
635
- if self ._xtal_frequency not in (16000000 , 8000000 ):
640
+ if self ._crystal_freq not in (16000000 , 8000000 ):
636
641
raise RuntimeError ("Incorrect xtal frequency" )
637
642
638
- cnf1 , cnf2 , cnf3 = _BAUD_RATES [self ._xtal_frequency ][self .baudrate ]
643
+ cnf1 , cnf2 , cnf3 = _BAUD_RATES [self ._crystal_freq ][self .baudrate ]
639
644
640
645
self ._set_register (_CNF1 , cnf1 )
641
646
self ._set_register (_CNF2 , cnf2 )
0 commit comments