41
41
#include "supervisor/shared/translate.h"
42
42
43
43
44
- //|class SPI:
45
- //|""".. currentmodule:: busio
44
+ //| class SPI:
45
+ //| """.. currentmodule:: busio
46
46
//|
47
- //|`SPI` -- a 3-4 wire serial protocol
48
- //|-----------------------------------------------
47
+ //| `SPI` -- a 3-4 wire serial protocol
48
+ //| -----------------------------------------------
49
49
//|
50
- //|SPI is a serial protocol that has exclusive pins for data in and out of the
51
- //|master. It is typically faster than :py:class:`~busio.I2C` because a
52
- //|separate pin is used to control the active slave rather than a transitted
53
- //|address. This class only manages three of the four SPI lines: `!clock`,
54
- //|`!MOSI`, `!MISO`. Its up to the client to manage the appropriate slave
55
- //|select line. (This is common because multiple slaves can share the `!clock`,
56
- //|`!MOSI` and `!MISO` lines and therefore the hardware.)"""
50
+ //| SPI is a serial protocol that has exclusive pins for data in and out of the
51
+ //| master. It is typically faster than :py:class:`~busio.I2C` because a
52
+ //| separate pin is used to control the active slave rather than a transitted
53
+ //| address. This class only manages three of the four SPI lines: `!clock`,
54
+ //| `!MOSI`, `!MISO`. Its up to the client to manage the appropriate slave
55
+ //| select line. (This is common because multiple slaves can share the `!clock`,
56
+ //| `!MOSI` and `!MISO` lines and therefore the hardware.)"""
57
57
//|
58
- //|def __init__(self, clock: microcontroller.Pin, MOSI: microcontroller.Pin = None, MISO: microcontroller.Pin = None):
58
+ //| def __init__(self, clock: microcontroller.Pin, MOSI: microcontroller.Pin = None, MISO: microcontroller.Pin = None):
59
59
//|
60
- //|"""Construct an SPI object on the given pins.
60
+ //| """Construct an SPI object on the given pins.
61
61
//|
62
- //|..note:: The SPI peripherals allocated in order of desirability, if possible,
63
- //|such as highest speed and not shared use first. For instance, on the nRF52840,
64
- //|there is a single 32MHz SPI peripheral, and multiple 8MHz peripherals,
65
- //|some of which may also be used for I2C. The 32MHz SPI peripheral is returned
66
- //|first, then the exclusive 8MHz SPI peripheral, and finally the shared 8MHz
67
- //|peripherals.
62
+ //| ..note:: The SPI peripherals allocated in order of desirability, if possible,
63
+ //| such as highest speed and not shared use first. For instance, on the nRF52840,
64
+ //| there is a single 32MHz SPI peripheral, and multiple 8MHz peripherals,
65
+ //| some of which may also be used for I2C. The 32MHz SPI peripheral is returned
66
+ //| first, then the exclusive 8MHz SPI peripheral, and finally the shared 8MHz
67
+ //| peripherals.
68
68
//|
69
- //|.. seealso:: Using this class directly requires careful lock management.
70
- //|Instead, use :class:`~adafruit_bus_device.spi_device.SPIDevice` to
71
- //|manage locks.
69
+ //| .. seealso:: Using this class directly requires careful lock management.
70
+ //| Instead, use :class:`~adafruit_bus_device.spi_device.SPIDevice` to
71
+ //| manage locks.
72
72
//|
73
- //|.. seealso:: Using this class to directly read registers requires manual
74
- //|bit unpacking. Instead, use an existing driver or make one with
75
- //|:ref:`Register <register-module-reference>` data descriptors.
73
+ //| .. seealso:: Using this class to directly read registers requires manual
74
+ //| bit unpacking. Instead, use an existing driver or make one with
75
+ //| :ref:`Register <register-module-reference>` data descriptors.
76
76
//|
77
- //|:param ~microcontroller.Pin clock: the pin to use for the clock.
78
- //|:param ~microcontroller.Pin MOSI: the Master Out Slave In pin.
79
- //|:param ~microcontroller.Pin MISO: the Master In Slave Out pin."""
80
- //|...
77
+ //| :param ~microcontroller.Pin clock: the pin to use for the clock.
78
+ //| :param ~microcontroller.Pin MOSI: the Master Out Slave In pin.
79
+ //| :param ~microcontroller.Pin MISO: the Master In Slave Out pin."""
80
+ //| ...
81
81
82
82
83
83
// TODO(tannewt): Support LSB SPI.
@@ -101,25 +101,25 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con
101
101
return MP_OBJ_FROM_PTR (self );
102
102
}
103
103
104
- //|def deinit(self, ) -> Any:
105
- //|"""Turn off the SPI bus."""
106
- //|...
104
+ //| def deinit(self, ) -> Any:
105
+ //| """Turn off the SPI bus."""
106
+ //| ...
107
107
STATIC mp_obj_t busio_spi_obj_deinit (mp_obj_t self_in ) {
108
108
busio_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
109
109
common_hal_busio_spi_deinit (self );
110
110
return mp_const_none ;
111
111
}
112
112
MP_DEFINE_CONST_FUN_OBJ_1 (busio_spi_deinit_obj , busio_spi_obj_deinit );
113
113
114
- //|def __enter__(self, ) -> Any:
115
- //|"""No-op used by Context Managers.
116
- //|Provided by context manager helper."""
117
- //|...
114
+ //| def __enter__(self, ) -> Any:
115
+ //| """No-op used by Context Managers.
116
+ //| Provided by context manager helper."""
117
+ //| ...
118
118
119
- //|def __exit__(self, ) -> Any:
120
- //|"""Automatically deinitializes the hardware when exiting a context. See
121
- //|:ref:`lifetime-and-contextmanagers` for more info."""
122
- //|...
119
+ //| def __exit__(self, ) -> Any:
120
+ //| """Automatically deinitializes the hardware when exiting a context. See
121
+ //| :ref:`lifetime-and-contextmanagers` for more info."""
122
+ //| ...
123
123
STATIC mp_obj_t busio_spi_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
124
124
(void )n_args ;
125
125
common_hal_busio_spi_deinit (args [0 ]);
@@ -140,28 +140,28 @@ STATIC void check_for_deinit(busio_spi_obj_t *self) {
140
140
}
141
141
}
142
142
143
- //|def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
144
- //|"""Configures the SPI bus. The SPI object must be locked.
143
+ //| def configure(self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8) -> Any:
144
+ //| """Configures the SPI bus. The SPI object must be locked.
145
145
//|
146
- //|:param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
147
- //|due to the granularity of available clock settings.
148
- //|Check the `frequency` attribute for the actual clock rate.
149
- //|:param int polarity: the base state of the clock line (0 or 1)
150
- //|:param int phase: the edge of the clock that data is captured. First (0)
151
- //|or second (1). Rising or falling depends on clock polarity.
152
- //|:param int bits: the number of bits per word
146
+ //| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
147
+ //| due to the granularity of available clock settings.
148
+ //| Check the `frequency` attribute for the actual clock rate.
149
+ //| :param int polarity: the base state of the clock line (0 or 1)
150
+ //| :param int phase: the edge of the clock that data is captured. First (0)
151
+ //| or second (1). Rising or falling depends on clock polarity.
152
+ //| :param int bits: the number of bits per word
153
153
//|
154
- //|.. note:: On the SAMD21, it is possible to set the baudrate to 24 MHz, but that
155
- //|speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
156
- //|within spec for the SAMD21.
154
+ //| .. note:: On the SAMD21, it is possible to set the baudrate to 24 MHz, but that
155
+ //| speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
156
+ //| within spec for the SAMD21.
157
157
//|
158
- //|.. note:: On the nRF52840, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz,
159
- //|and 8MHz.
160
- //|If you pick a a baudrate other than one of these, the nearest lower
161
- //|baudrate will be chosen, with a minimum of 125kHz.
162
- //|Two SPI objects may be created, except on the Circuit Playground Bluefruit,
163
- //|which allows only one (to allow for an additional I2C object)."""
164
- //|...
158
+ //| .. note:: On the nRF52840, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz,
159
+ //| and 8MHz.
160
+ //| If you pick a a baudrate other than one of these, the nearest lower
161
+ //| baudrate will be chosen, with a minimum of 125kHz.
162
+ //| Two SPI objects may be created, except on the Circuit Playground Bluefruit,
163
+ //| which allows only one (to allow for an additional I2C object)."""
164
+ //| ...
165
165
166
166
STATIC mp_obj_t busio_spi_configure (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
167
167
enum { ARG_baudrate , ARG_polarity , ARG_phase , ARG_bits };
@@ -198,22 +198,22 @@ STATIC mp_obj_t busio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_
198
198
}
199
199
MP_DEFINE_CONST_FUN_OBJ_KW (busio_spi_configure_obj , 1 , busio_spi_configure );
200
200
201
- //|def try_lock(self, ) -> Any:
202
- //|"""Attempts to grab the SPI lock. Returns True on success.
201
+ //| def try_lock(self, ) -> Any:
202
+ //| """Attempts to grab the SPI lock. Returns True on success.
203
203
//|
204
- //|:return: True when lock has been grabbed
205
- //|:rtype: bool"""
206
- //|...
204
+ //| :return: True when lock has been grabbed
205
+ //| :rtype: bool"""
206
+ //| ...
207
207
208
208
STATIC mp_obj_t busio_spi_obj_try_lock (mp_obj_t self_in ) {
209
209
busio_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
210
210
return mp_obj_new_bool (common_hal_busio_spi_try_lock (self ));
211
211
}
212
212
MP_DEFINE_CONST_FUN_OBJ_1 (busio_spi_try_lock_obj , busio_spi_obj_try_lock );
213
213
214
- //|unlock(self, ) -> Any:
215
- //|"""Releases the SPI lock."""
216
- //|...
214
+ //| def unlock(self, ) -> Any:
215
+ //| """Releases the SPI lock."""
216
+ //| ...
217
217
218
218
STATIC mp_obj_t busio_spi_obj_unlock (mp_obj_t self_in ) {
219
219
busio_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
@@ -223,14 +223,14 @@ STATIC mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) {
223
223
}
224
224
MP_DEFINE_CONST_FUN_OBJ_1 (busio_spi_unlock_obj , busio_spi_obj_unlock );
225
225
226
- //|def write(self, buffer: bytearray, *, start: Any = 0, end: int = None) -> Any: ...
227
- //|"""Write the data contained in ``buffer``. The SPI object must be locked.
228
- //|If the buffer is empty, nothing happens.
226
+ //| def write(self, buffer: bytearray, *, start: Any = 0, end: int = None) -> Any:
227
+ //| """Write the data contained in ``buffer``. The SPI object must be locked.
228
+ //| If the buffer is empty, nothing happens.
229
229
//|
230
- //|:param bytearray buffer: Write out the data in this buffer
231
- //|:param int start: Start of the slice of ``buffer`` to write out: ``buffer[start:end]``
232
- //|:param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``"""
233
- //|...
230
+ //| :param bytearray buffer: Write out the data in this buffer
231
+ //| :param int start: Start of the slice of ``buffer`` to write out: ``buffer[start:end]``
232
+ //| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``"""
233
+ //| ...
234
234
235
235
STATIC mp_obj_t busio_spi_write (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
236
236
enum { ARG_buffer , ARG_start , ARG_end };
@@ -264,16 +264,16 @@ STATIC mp_obj_t busio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_
264
264
MP_DEFINE_CONST_FUN_OBJ_KW (busio_spi_write_obj , 2 , busio_spi_write );
265
265
266
266
267
- //|def readinto(self, buffer: bytearray, *, start: Any = 0, end: int = None, write_value: int = 0) -> Any:
268
- //|"""Read into ``buffer`` while writing ``write_value`` for each byte read.
269
- //|The SPI object must be locked.
270
- //|If the number of bytes to read is 0, nothing happens.
267
+ //| def readinto(self, buffer: bytearray, *, start: Any = 0, end: int = None, write_value: int = 0) -> Any:
268
+ //| """Read into ``buffer`` while writing ``write_value`` for each byte read.
269
+ //| The SPI object must be locked.
270
+ //| If the number of bytes to read is 0, nothing happens.
271
271
//|
272
- //|:param bytearray buffer: Read data into this buffer
273
- //|:param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]``
274
- //|:param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
275
- //|:param int write_value: Value to write while reading. (Usually ignored.)"""
276
- //|...
272
+ //| :param bytearray buffer: Read data into this buffer
273
+ //| :param int start: Start of the slice of ``buffer`` to read into: ``buffer[start:end]``
274
+ //| :param int end: End of the slice; this index is not included. Defaults to ``len(buffer)``
275
+ //| :param int write_value: Value to write while reading. (Usually ignored.)"""
276
+ //| ...
277
277
278
278
STATIC mp_obj_t busio_spi_readinto (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
279
279
enum { ARG_buffer , ARG_start , ARG_end , ARG_write_value };
@@ -307,20 +307,20 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m
307
307
}
308
308
MP_DEFINE_CONST_FUN_OBJ_KW (busio_spi_readinto_obj , 2 , busio_spi_readinto );
309
309
310
- //|def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
311
- //|"""Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
312
- //|The SPI object must be locked.
313
- //|The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
314
- //|must be equal.
315
- //|If buffer slice lengths are both 0, nothing happens.
310
+ //| def write_readinto(self, buffer_out: bytearray, buffer_in: bytearray, *, out_start: Any = 0, out_end: int = None, in_start: Any = 0, in_end: int = None) -> Any:
311
+ //| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``.
312
+ //| The SPI object must be locked.
313
+ //| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]``
314
+ //| must be equal.
315
+ //| If buffer slice lengths are both 0, nothing happens.
316
316
//|
317
- //|:param bytearray buffer_out: Write out the data in this buffer
318
- //|:param bytearray buffer_in: Read data into this buffer
319
- //|:param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
320
- //|:param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
321
- //|:param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
322
- //|:param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``"""
323
- //|...
317
+ //| :param bytearray buffer_out: Write out the data in this buffer
318
+ //| :param bytearray buffer_in: Read data into this buffer
319
+ //| :param int out_start: Start of the slice of buffer_out to write out: ``buffer_out[out_start:out_end]``
320
+ //| :param int out_end: End of the slice; this index is not included. Defaults to ``len(buffer_out)``
321
+ //| :param int in_start: Start of the slice of ``buffer_in`` to read into: ``buffer_in[in_start:in_end]``
322
+ //| :param int in_end: End of the slice; this index is not included. Defaults to ``len(buffer_in)``"""
323
+ //| ...
324
324
325
325
STATIC mp_obj_t busio_spi_write_readinto (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
326
326
enum { ARG_buffer_out , ARG_buffer_in , ARG_out_start , ARG_out_end , ARG_in_start , ARG_in_end };
@@ -369,10 +369,10 @@ STATIC mp_obj_t busio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args
369
369
}
370
370
MP_DEFINE_CONST_FUN_OBJ_KW (busio_spi_write_readinto_obj , 2 , busio_spi_write_readinto );
371
371
372
- //|frequency: Any =
373
- //|"""The actual SPI bus frequency. This may not match the frequency requested
374
- //|due to internal limitations."""
375
- //|...
372
+ //| frequency: Any = ...
373
+ //| """The actual SPI bus frequency. This may not match the frequency requested
374
+ //| due to internal limitations."""
375
+ //|
376
376
377
377
STATIC mp_obj_t busio_spi_obj_get_frequency (mp_obj_t self_in ) {
378
378
busio_spi_obj_t * self = MP_OBJ_TO_PTR (self_in );
0 commit comments