32
32
import time
33
33
34
34
from micropython import const
35
+
35
36
try :
36
37
import struct
37
38
except ImportError :
44
45
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SI4713.git"
45
46
46
47
47
- #pylint: disable=bad-whitespace
48
+ # pylint: disable=bad-whitespace
48
49
# Internal constants:
49
- _SI4710_ADDR0 = const (0x11 ) # if SEN is = const(low)
50
- _SI4710_ADDR1 = const (0x63 ) # if SEN is high, default
51
- _SI4710_STATUS_CTS = const (0x80 )
52
- _SI4710_CMD_POWER_UP = const (0x01 )
53
- _SI4710_CMD_GET_REV = const (0x10 )
54
- _SI4710_CMD_POWER_DOWN = const (0x11 )
55
- _SI4710_CMD_SET_PROPERTY = const (0x12 )
56
- _SI4710_CMD_GET_PROPERTY = const (0x13 )
57
- _SI4710_CMD_GET_INT_STATUS = const (0x14 )
58
- _SI4710_CMD_PATCH_ARGS = const (0x15 )
59
- _SI4710_CMD_PATCH_DATA = const (0x16 )
60
- _SI4710_CMD_TX_TUNE_FREQ = const (0x30 )
61
- _SI4710_CMD_TX_TUNE_POWER = const (0x31 )
62
- _SI4710_CMD_TX_TUNE_MEASURE = const (0x32 )
63
- _SI4710_CMD_TX_TUNE_STATUS = const (0x33 )
64
- _SI4710_CMD_TX_ASQ_STATUS = const (0x34 )
65
- _SI4710_CMD_TX_RDS_BUFF = const (0x35 )
66
- _SI4710_CMD_TX_RDS_PS = const (0x36 )
67
- _SI4710_CMD_TX_AGC_OVERRIDE = const (0x48 )
68
- _SI4710_CMD_GPO_CTL = const (0x80 )
69
- _SI4710_CMD_GPO_SET = const (0x81 )
70
- _SI4713_PROP_GPO_IEN = const (0x0001 )
71
- _SI4713_PROP_DIGITAL_INPUT_FORMAT = const (0x0101 )
72
- _SI4713_PROP_DIGITAL_INPUT_SAMPLE_RATE = const (0x0103 )
73
- _SI4713_PROP_REFCLK_FREQ = const (0x0201 )
74
- _SI4713_PROP_REFCLK_PRESCALE = const (0x0202 )
75
- _SI4713_PROP_TX_COMPONENT_ENABLE = const (0x2100 )
76
- _SI4713_PROP_TX_AUDIO_DEVIATION = const (0x2101 )
77
- _SI4713_PROP_TX_PILOT_DEVIATION = const (0x2102 )
78
- _SI4713_PROP_TX_RDS_DEVIATION = const (0x2103 )
79
- _SI4713_PROP_TX_LINE_LEVEL_INPUT_LEVEL = const (0x2104 )
80
- _SI4713_PROP_TX_LINE_INPUT_MUTE = const (0x2105 )
81
- _SI4713_PROP_TX_PREEMPHASIS = const (0x2106 )
82
- _SI4713_PROP_TX_PILOT_FREQUENCY = const (0x2107 )
83
- _SI4713_PROP_TX_ACOMP_ENABLE = const (0x2200 )
84
- _SI4713_PROP_TX_ACOMP_THRESHOLD = const (0x2201 )
85
- _SI4713_PROP_TX_ATTACK_TIME = const (0x2202 )
86
- _SI4713_PROP_TX_RELEASE_TIME = const (0x2203 )
87
- _SI4713_PROP_TX_ACOMP_GAIN = const (0x2204 )
88
- _SI4713_PROP_TX_LIMITER_RELEASE_TIME = const (0x2205 )
89
- _SI4713_PROP_TX_ASQ_INTERRUPT_SOURCE = const (0x2300 )
90
- _SI4713_PROP_TX_ASQ_LEVEL_LOW = const (0x2301 )
91
- _SI4713_PROP_TX_ASQ_DURATION_LOW = const (0x2302 )
92
- _SI4713_PROP_TX_AQS_LEVEL_HIGH = const (0x2303 )
93
- _SI4713_PROP_TX_AQS_DURATION_HIGH = const (0x2304 )
94
- _SI4713_PROP_TX_RDS_INTERRUPT_SOURCE = const (0x2C00 )
95
- _SI4713_PROP_TX_RDS_PI = const (0x2C01 )
96
- _SI4713_PROP_TX_RDS_PS_MIX = const (0x2C02 )
97
- _SI4713_PROP_TX_RDS_PS_MISC = const (0x2C03 )
98
- _SI4713_PROP_TX_RDS_PS_REPEAT_COUNT = const (0x2C04 )
99
- _SI4713_PROP_TX_RDS_MESSAGE_COUNT = const (0x2C05 )
100
- _SI4713_PROP_TX_RDS_PS_AF = const (0x2C06 )
101
- _SI4713_PROP_TX_RDS_FIFO_SIZE = const (0x2C07 )
102
- #pylint: enable=bad-whitespace
50
+ _SI4710_ADDR0 = const (0x11 ) # if SEN is = const(low)
51
+ _SI4710_ADDR1 = const (0x63 ) # if SEN is high, default
52
+ _SI4710_STATUS_CTS = const (0x80 )
53
+ _SI4710_CMD_POWER_UP = const (0x01 )
54
+ _SI4710_CMD_GET_REV = const (0x10 )
55
+ _SI4710_CMD_POWER_DOWN = const (0x11 )
56
+ _SI4710_CMD_SET_PROPERTY = const (0x12 )
57
+ _SI4710_CMD_GET_PROPERTY = const (0x13 )
58
+ _SI4710_CMD_GET_INT_STATUS = const (0x14 )
59
+ _SI4710_CMD_PATCH_ARGS = const (0x15 )
60
+ _SI4710_CMD_PATCH_DATA = const (0x16 )
61
+ _SI4710_CMD_TX_TUNE_FREQ = const (0x30 )
62
+ _SI4710_CMD_TX_TUNE_POWER = const (0x31 )
63
+ _SI4710_CMD_TX_TUNE_MEASURE = const (0x32 )
64
+ _SI4710_CMD_TX_TUNE_STATUS = const (0x33 )
65
+ _SI4710_CMD_TX_ASQ_STATUS = const (0x34 )
66
+ _SI4710_CMD_TX_RDS_BUFF = const (0x35 )
67
+ _SI4710_CMD_TX_RDS_PS = const (0x36 )
68
+ _SI4710_CMD_TX_AGC_OVERRIDE = const (0x48 )
69
+ _SI4710_CMD_GPO_CTL = const (0x80 )
70
+ _SI4710_CMD_GPO_SET = const (0x81 )
71
+ _SI4713_PROP_GPO_IEN = const (0x0001 )
72
+ _SI4713_PROP_DIGITAL_INPUT_FORMAT = const (0x0101 )
73
+ _SI4713_PROP_DIGITAL_INPUT_SAMPLE_RATE = const (0x0103 )
74
+ _SI4713_PROP_REFCLK_FREQ = const (0x0201 )
75
+ _SI4713_PROP_REFCLK_PRESCALE = const (0x0202 )
76
+ _SI4713_PROP_TX_COMPONENT_ENABLE = const (0x2100 )
77
+ _SI4713_PROP_TX_AUDIO_DEVIATION = const (0x2101 )
78
+ _SI4713_PROP_TX_PILOT_DEVIATION = const (0x2102 )
79
+ _SI4713_PROP_TX_RDS_DEVIATION = const (0x2103 )
80
+ _SI4713_PROP_TX_LINE_LEVEL_INPUT_LEVEL = const (0x2104 )
81
+ _SI4713_PROP_TX_LINE_INPUT_MUTE = const (0x2105 )
82
+ _SI4713_PROP_TX_PREEMPHASIS = const (0x2106 )
83
+ _SI4713_PROP_TX_PILOT_FREQUENCY = const (0x2107 )
84
+ _SI4713_PROP_TX_ACOMP_ENABLE = const (0x2200 )
85
+ _SI4713_PROP_TX_ACOMP_THRESHOLD = const (0x2201 )
86
+ _SI4713_PROP_TX_ATTACK_TIME = const (0x2202 )
87
+ _SI4713_PROP_TX_RELEASE_TIME = const (0x2203 )
88
+ _SI4713_PROP_TX_ACOMP_GAIN = const (0x2204 )
89
+ _SI4713_PROP_TX_LIMITER_RELEASE_TIME = const (0x2205 )
90
+ _SI4713_PROP_TX_ASQ_INTERRUPT_SOURCE = const (0x2300 )
91
+ _SI4713_PROP_TX_ASQ_LEVEL_LOW = const (0x2301 )
92
+ _SI4713_PROP_TX_ASQ_DURATION_LOW = const (0x2302 )
93
+ _SI4713_PROP_TX_AQS_LEVEL_HIGH = const (0x2303 )
94
+ _SI4713_PROP_TX_AQS_DURATION_HIGH = const (0x2304 )
95
+ _SI4713_PROP_TX_RDS_INTERRUPT_SOURCE = const (0x2C00 )
96
+ _SI4713_PROP_TX_RDS_PI = const (0x2C01 )
97
+ _SI4713_PROP_TX_RDS_PS_MIX = const (0x2C02 )
98
+ _SI4713_PROP_TX_RDS_PS_MISC = const (0x2C03 )
99
+ _SI4713_PROP_TX_RDS_PS_REPEAT_COUNT = const (0x2C04 )
100
+ _SI4713_PROP_TX_RDS_MESSAGE_COUNT = const (0x2C05 )
101
+ _SI4713_PROP_TX_RDS_PS_AF = const (0x2C06 )
102
+ _SI4713_PROP_TX_RDS_FIFO_SIZE = const (0x2C07 )
103
+ # pylint: enable=bad-whitespace
103
104
104
105
105
106
class SI4713 :
@@ -141,7 +142,7 @@ def __init__(self, i2c, *, address=_SI4710_ADDR1, reset=None, timeout_s=0.1):
141
142
self .reset ()
142
143
# Check product ID.
143
144
if self ._get_product_number () != 13 :
144
- raise RuntimeError (' Failed to find SI4713, check wiring!' )
145
+ raise RuntimeError (" Failed to find SI4713, check wiring!" )
145
146
146
147
def _read_u8 (self , address ):
147
148
# Read an 8-bit unsigned value from the specified 8-bit address.
@@ -182,7 +183,7 @@ def _write_from(self, buf, count=None):
182
183
if self ._BUFFER [0 ] & _SI4710_STATUS_CTS > 0 :
183
184
return
184
185
if time .monotonic () - start > self ._timeout_s :
185
- raise RuntimeError (' Timeout waiting for SI4723 response, check wiring!' )
186
+ raise RuntimeError (" Timeout waiting for SI4723 response, check wiring!" )
186
187
187
188
def _set_property (self , prop , val ):
188
189
# Set a property of the SI4713 chip. These are both 16-bit values.
@@ -205,10 +206,10 @@ def _get_product_number(self):
205
206
i2c .readinto (self ._BUFFER , end = 9 )
206
207
return self ._BUFFER [1 ]
207
208
# Other potentially useful but unused data:
208
- #fw = (self._BUFFER[2] << 8) | self._BUFFER[3]
209
- #patch = (self._BUFFER[4] << 8) | self._BUFFER[5]
210
- #cmp = (self._BUFFER[6] << 8) | self._BUFFER[7]
211
- #rev = (self._BUFFER[8])
209
+ # fw = (self._BUFFER[2] << 8) | self._BUFFER[3]
210
+ # patch = (self._BUFFER[4] << 8) | self._BUFFER[5]
211
+ # cmp = (self._BUFFER[6] << 8) | self._BUFFER[7]
212
+ # rev = (self._BUFFER[8])
212
213
213
214
def reset (self ):
214
215
"""Perform a reset of the chip using the reset line. Will also
@@ -258,7 +259,7 @@ def _poll_interrupt_status(self, expected):
258
259
while self .interrupt_status != expected :
259
260
time .sleep (0.01 ) # Short delay for other processing.
260
261
if time .monotonic () - start > self ._timeout_s :
261
- raise RuntimeError (' Timeout waiting for SI4713 to respond!' )
262
+ raise RuntimeError (" Timeout waiting for SI4713 to respond!" )
262
263
263
264
def _tune_status (self ):
264
265
# Retrieve the tune status command values from the radio. Will store
@@ -372,8 +373,7 @@ def received_noise_level(self, frequency_khz, antenna_capacitance=0):
372
373
# Validate frequency and capacitance.
373
374
assert 76000 <= frequency_khz <= 108000
374
375
assert (frequency_khz % 50 ) == 0
375
- assert antenna_capacitance == 0 or \
376
- (0.25 <= antenna_capacitance <= 47.75 )
376
+ assert antenna_capacitance == 0 or (0.25 <= antenna_capacitance <= 47.75 )
377
377
# Convert frequency and capacitance to units used by the chip.
378
378
frequency_khz = (frequency_khz // 10 ) & 0xFFFF
379
379
antenna_capacitance = int (antenna_capacitance / 0.25 )
@@ -398,7 +398,8 @@ def input_level(self):
398
398
"""
399
399
# Perform ASQ request, then parse out 8 bit _signed_ input level value.
400
400
self ._asq_status ()
401
- return struct .unpack ('bbbbb' , self ._BUFFER [0 :5 ])[4 ]
401
+ return struct .unpack ("bbbbb" , self ._BUFFER [0 :5 ])[4 ]
402
+
402
403
@property
403
404
def audio_signal_status (self ):
404
405
"""Retrieve the ASQ or audio signal quality status value from the chip.
@@ -461,9 +462,9 @@ def _set_rds_station(self, station):
461
462
self ._BUFFER [0 ] = _SI4710_CMD_TX_RDS_PS
462
463
self ._BUFFER [1 ] = i // 4
463
464
self ._BUFFER [2 ] = station [i ] if i < station_length else 0x00
464
- self ._BUFFER [3 ] = station [i + 1 ] if i + 1 < station_length else 0x00
465
- self ._BUFFER [4 ] = station [i + 2 ] if i + 2 < station_length else 0x00
466
- self ._BUFFER [5 ] = station [i + 3 ] if i + 3 < station_length else 0x00
465
+ self ._BUFFER [3 ] = station [i + 1 ] if i + 1 < station_length else 0x00
466
+ self ._BUFFER [4 ] = station [i + 2 ] if i + 2 < station_length else 0x00
467
+ self ._BUFFER [5 ] = station [i + 3 ] if i + 3 < station_length else 0x00
467
468
self ._write_from (self ._BUFFER , count = 6 )
468
469
469
470
def _set_rds_buffer (self , rds_buffer ):
@@ -478,22 +479,30 @@ def _set_rds_buffer(self, rds_buffer):
478
479
self ._BUFFER [2 ] = 0x20
479
480
self ._BUFFER [3 ] = i // 4
480
481
self ._BUFFER [4 ] = rds_buffer [i ] if i < buf_length else 0x00
481
- self ._BUFFER [5 ] = rds_buffer [i + 1 ] if i + 1 < buf_length else 0x00
482
- self ._BUFFER [6 ] = rds_buffer [i + 2 ] if i + 2 < buf_length else 0x00
483
- self ._BUFFER [7 ] = rds_buffer [i + 3 ] if i + 3 < buf_length else 0x00
482
+ self ._BUFFER [5 ] = rds_buffer [i + 1 ] if i + 1 < buf_length else 0x00
483
+ self ._BUFFER [6 ] = rds_buffer [i + 2 ] if i + 2 < buf_length else 0x00
484
+ self ._BUFFER [7 ] = rds_buffer [i + 3 ] if i + 3 < buf_length else 0x00
484
485
self ._write_from (self ._BUFFER , count = 8 )
485
486
486
- rds_station = property (None , _set_rds_station , None ,
487
- """Set the RDS broadcast station to the specified
487
+ rds_station = property (
488
+ None ,
489
+ _set_rds_station ,
490
+ None ,
491
+ """Set the RDS broadcast station to the specified
488
492
byte string. Can be at most 96 bytes long and will
489
493
be padded with blank spaces if less.
490
- """ )
491
-
492
- rds_buffer = property (None , _set_rds_buffer , None ,
493
- """Set the RDS broadcast buffer to the specified byte
494
+ """ ,
495
+ )
496
+
497
+ rds_buffer = property (
498
+ None ,
499
+ _set_rds_buffer ,
500
+ None ,
501
+ """Set the RDS broadcast buffer to the specified byte
494
502
string. Can be at most 106 bytes long and will be
495
503
padded with blank spaces if less.
496
- """ )
504
+ """ ,
505
+ )
497
506
498
507
def configure_rds (self , program_id , station = None , rds_buffer = None ):
499
508
"""Configure and enable the RDS broadcast of the specified program ID.
0 commit comments