@@ -84,7 +84,9 @@ def deinit(self) -> None:
84
84
class I2C (_BitBangIO ):
85
85
"""Software-based implementation of the I2C protocol over GPIO pins."""
86
86
87
- def __init__ (self , scl : Pin , sda : Pin , * , frequency : int = 400000 , timeout : float = 1 ) -> None :
87
+ def __init__ (
88
+ self , scl : Pin , sda : Pin , * , frequency : int = 400000 , timeout : float = 1
89
+ ) -> None :
88
90
"""Initialize bitbang (or software) based I2C. Must provide the I2C
89
91
clock, and data pin numbers.
90
92
"""
@@ -122,14 +124,28 @@ def scan(self) -> List[int]:
122
124
found .append (address )
123
125
return found
124
126
125
- def writeto (self , address : int , buffer : ReadableBuffer , * , start : int = 0 , end : Optional [int ] = None ) -> None :
127
+ def writeto (
128
+ self ,
129
+ address : int ,
130
+ buffer : ReadableBuffer ,
131
+ * ,
132
+ start : int = 0 ,
133
+ end : Optional [int ] = None
134
+ ) -> None :
126
135
"""Write data from the buffer to an address"""
127
136
if end is None :
128
137
end = len (buffer )
129
138
if self ._check_lock ():
130
139
self ._write (address , buffer [start :end ], True )
131
140
132
- def readfrom_into (self , address : int , buffer : WriteableBuffer , * , start : int = 0 , end : Optional [int ] = None ) -> None :
141
+ def readfrom_into (
142
+ self ,
143
+ address : int ,
144
+ buffer : WriteableBuffer ,
145
+ * ,
146
+ start : int = 0 ,
147
+ end : Optional [int ] = None
148
+ ) -> None :
133
149
"""Read data from an address and into the buffer"""
134
150
if end is None :
135
151
end = len (buffer )
@@ -204,7 +220,7 @@ def _repeated_start(self) -> None:
204
220
self ._sda_low ()
205
221
self ._wait ()
206
222
207
- def _write_byte (self , byte : int ) -> bool :
223
+ def _write_byte (self , byte : int ) -> bool :
208
224
for bit_position in range (8 ):
209
225
self ._scl_low ()
210
226
@@ -283,7 +299,9 @@ def _read(self, address: int, length: int) -> bytearray:
283
299
class SPI (_BitBangIO ):
284
300
"""Software-based implementation of the SPI protocol over GPIO pins."""
285
301
286
- def __init__ (self , clock : Pin , MOSI : Optional [Pin ] = None , MISO : Optional [Pin ] = None ) -> None :
302
+ def __init__ (
303
+ self , clock : Pin , MOSI : Optional [Pin ] = None , MISO : Optional [Pin ] = None
304
+ ) -> None :
287
305
"""Initialize bit bang (or software) based SPI. Must provide the SPI
288
306
clock, and optionally MOSI and MISO pin numbers. If MOSI is set to None
289
307
then writes will be disabled and fail with an error, likewise for MISO
@@ -320,7 +338,14 @@ def deinit(self) -> None:
320
338
if self ._mosi :
321
339
self ._mosi .deinit ()
322
340
323
- def configure (self , * , baudrate : int = 100000 , polarity : Literal [0 , 1 ] = 0 , phase : Literal [0 , 1 ] = 0 , bits : int = 8 ) -> None :
341
+ def configure (
342
+ self ,
343
+ * ,
344
+ baudrate : int = 100000 ,
345
+ polarity : Literal [0 , 1 ] = 0 ,
346
+ phase : Literal [0 , 1 ] = 0 ,
347
+ bits : int = 8
348
+ ) -> None :
324
349
"""Configures the SPI bus. Only valid when locked."""
325
350
if self ._check_lock ():
326
351
if not isinstance (baudrate , int ):
@@ -345,7 +370,9 @@ def _wait(self, start: Optional[int] = None) -> float:
345
370
pass
346
371
return monotonic () # Return current time
347
372
348
- def write (self , buffer : ReadableBuffer , start : int = 0 , end : Optional [int ] = None ) -> None :
373
+ def write (
374
+ self , buffer : ReadableBuffer , start : int = 0 , end : Optional [int ] = None
375
+ ) -> None :
349
376
"""Write the data contained in buf. Requires the SPI being locked.
350
377
If the buffer is empty, nothing happens.
351
378
"""
@@ -377,7 +404,13 @@ def write(self, buffer: ReadableBuffer, start: int = 0, end: Optional[int] = Non
377
404
self ._sclk .value = self ._polarity
378
405
379
406
# pylint: disable=too-many-branches
380
- def readinto (self , buffer : WriteableBuffer , start : int = 0 , end : Optional [int ] = None , write_value : int = 0 ) -> None :
407
+ def readinto (
408
+ self ,
409
+ buffer : WriteableBuffer ,
410
+ start : int = 0 ,
411
+ end : Optional [int ] = None ,
412
+ write_value : int = 0 ,
413
+ ) -> None :
381
414
"""Read into the buffer specified by buf while writing zeroes. Requires the SPI being
382
415
locked. If the number of bytes to read is 0, nothing happens.
383
416
"""
0 commit comments