Skip to content

Commit a5864a1

Browse files
committed
Fix undefined reference to 'busio_wiznet_pio_spi_type' and clean up code
1 parent 56ffd4e commit a5864a1

File tree

8 files changed

+32
-215
lines changed

8 files changed

+32
-215
lines changed

ports/raspberrypi/boards/wiznet_w55rp20_evb_pico/mpconfigboard.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
1111
CIRCUITPY_WIZNET_PIO_SPI = 1
1212
CIRCUITPY__EVE = 1
1313
CIRCUITPY_SSL = 1
14-
CIRCUITPY_USB_HOST = 0
14+
CIRCUITPY_USB_HOST = 0

ports/raspberrypi/common-hal/busio/WIZNET_PIO_SPI.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ bool common_hal_wiznet_pio_spi_try_lock(wiznet_pio_spi_obj_t *self) {
8989
if (common_hal_wiznet_pio_spi_deinited(self)) {
9090
return false;
9191
}
92-
92+
9393
bool grabbed_lock = false;
9494
if (!self->has_lock) {
9595
grabbed_lock = true;
@@ -120,4 +120,4 @@ bool common_hal_wiznet_pio_spi_read(wiznet_pio_spi_obj_t *self,
120120

121121
bool common_hal_wiznet_pio_spi_transfer(wiznet_pio_spi_obj_t *self, const uint8_t *data_out, uint8_t *data_in, size_t len) {
122122
return wiznet_pio_spi_transfer(data_out, len, data_in, len);
123-
}
123+
}

ports/raspberrypi/common-hal/busio/WIZNET_PIO_SPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ typedef struct {
2222
const mcu_pin_obj_t *MISO;
2323
} wiznet_pio_spi_obj_t;
2424

25-
void reset_spi(void);
25+
void reset_spi(void);

ports/raspberrypi/wiznet_pio_spi/wizchip_pio_spi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void wiznet_pio_spi_write_buffer(const uint8_t *pBuf, uint16_t len) {
351351
assert(active_state->spi_header_count == 0);
352352
if (!wiznet_pio_spi_transfer(pBuf, len, NULL, 0)) {
353353
panic("spi failed writing buffer");
354-
}
354+
}
355355
}
356356
}
357357

ports/raspberrypi/wiznet_pio_spi/wizchip_pio_spi.pio

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ read_bits:
2121
jmp x-- read_bits side 1
2222
in pins, 1 side 0
2323
jmp y-- read_byte side 0
24-
public read_end:
24+
public read_end:

py/circuitpy_defns.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ ifeq ($(CIRCUITPY_WIFI),1)
460460
SRC_PATTERNS += wifi/%
461461
endif
462462
ifeq ($(CIRCUITPY_WIZNET_PIO_SPI),1)
463-
SRC_PATTERNS += busio/WIZNET_PIO_SPI.c busio/WIZNET_PIO_SPI.h
463+
SRC_PATTERNS += busio/WIZNET_PIO_SPI.c
464464
endif
465465
ifeq ($(CIRCUITPY_ZLIB),1)
466466
SRC_PATTERNS += zlib/%
@@ -849,6 +849,10 @@ SRC_SHARED_MODULE_ALL += \
849849
ssl/SSLSocket.c
850850
endif
851851

852+
ifeq ($(CIRCUITPY_WIZNET_PIO_SPI),1)
853+
SRC_COMMON_HAL_ALL += busio/WIZNET_PIO_SPI.c
854+
endif
855+
852856
ifeq ($(CIRCUITPY_KEYPAD_DEMUX),1)
853857
SRC_SHARED_MODULE_ALL += \
854858
keypad_demux/__init__.c \

shared-bindings/busio/WIZNET_PIO_SPI.c

Lines changed: 19 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
//
55
// SPDX-License-Identifier: MIT
66

7+
//TODO: busio.WIZNET_PIO_SPI class.
78
// This file contains all of the Python API definitions for the
8-
// busio.SPI class.
9+
// busio.WIZNET_PIO_SPI class.
910

1011
#include <string.h>
1112

@@ -20,73 +21,10 @@
2021
#include "py/objproperty.h"
2122
#include "py/runtime.h"
2223

23-
#include <stdio.h>
24-
25-
26-
//| class SPI:
27-
//| """A 3-4 wire serial protocol
28-
//|
29-
//| SPI is a serial protocol that has exclusive pins for data in and out of the
30-
//| main device. It is typically faster than :py:class:`~bitbangio.I2C` because a
31-
//| separate pin is used to select a device rather than a transmitted
32-
//| address. This class only manages three of the four SPI lines: `!clock`,
33-
//| `!MOSI`, `!MISO`. It is up to the client to manage the appropriate
34-
//| select line, often abbreviated `!CS` or `!SS`. (This is common because
35-
//| multiple secondaries can share the `!clock`, `!MOSI` and `!MISO` lines
36-
//| and therefore the hardware.)
37-
//|
38-
//| .. raw:: html
39-
//|
40-
//| <p>
41-
//| <details>
42-
//| <summary>Available on these boards</summary>
43-
//| <ul>
44-
//| {% for board in support_matrix_reverse["busio.SPI"] %}
45-
//| <li> {{ board }}
46-
//| {% endfor %}
47-
//| </ul>
48-
//| </details>
49-
//| </p>
50-
//|
51-
//| .. seealso:: This class acts as an SPI main (controller).
52-
//| To act as an SPI secondary (target), use `spitarget.SPITarget`.
53-
//| """
54-
//|
55-
//| def __init__(
56-
//| self,
57-
//| clock: microcontroller.Pin,
58-
//| MOSI: Optional[microcontroller.Pin] = None,
59-
//| MISO: Optional[microcontroller.Pin] = None,
60-
//| half_duplex: bool = False,
61-
//| ) -> None:
62-
//| """Construct an SPI object on the given pins.
63-
//|
64-
//| .. note:: The SPI peripherals allocated in order of desirability, if possible,
65-
//| such as highest speed and not shared use first. For instance, on the nRF52840,
66-
//| there is a single 32MHz SPI peripheral, and multiple 8MHz peripherals,
67-
//| some of which may also be used for I2C. The 32MHz SPI peripheral is returned
68-
//| first, then the exclusive 8MHz SPI peripheral, and finally the shared 8MHz
69-
//| peripherals.
70-
//|
71-
//| .. seealso:: Using this class directly requires careful lock management.
72-
//| Instead, use :class:`~adafruit_bus_device.SPIDevice` to
73-
//| manage locks.
74-
//|
75-
//| .. seealso:: Using this class to directly read registers requires manual
76-
//| bit unpacking. Instead, use an existing driver or make one with
77-
//| :ref:`Register <register-module-reference>` data descriptors.
78-
//|
79-
//| :param ~microcontroller.Pin clock: the pin to use for the clock.
80-
//| :param ~microcontroller.Pin MOSI: the Main Out Selected In pin.
81-
//| :param ~microcontroller.Pin MISO: the Main In Selected Out pin.
82-
//| :param bool half_duplex: True when MOSI is used for bidirectional data. False when SPI is full-duplex or simplex.
83-
//|
84-
//| **Limitations:** ``half_duplex`` is available only on STM; other chips do not have the hardware support.
85-
//| """
86-
//| ...
87-
//|
88-
89-
// TODO(tannewt): Support LSB SPI.
24+
25+
//TODO: class WIZNET_PIO_SPI
26+
27+
9028
static mp_obj_t wiznet_pio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
9129
#if CIRCUITPY_WIZNET_PIO_SPI
9230
wiznet_pio_spi_obj_t *self = mp_obj_malloc(wiznet_pio_spi_obj_t, &busio_wiznet_pio_spi_type);
@@ -116,29 +54,19 @@ static mp_obj_t wiznet_pio_spi_make_new(const mp_obj_type_t *type, size_t n_args
11654
}
11755

11856
#if CIRCUITPY_WIZNET_PIO_SPI
119-
//| def deinit(self) -> None:
120-
//| """Turn off the SPI bus."""
121-
//| ...
122-
//|
57+
58+
// TODO: def deinit
59+
12360
static mp_obj_t wiznet_pio_spi_obj_deinit(mp_obj_t self_in) {
12461
wiznet_pio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
12562
common_hal_wiznet_pio_spi_deinit(self);
12663
return mp_const_none;
12764
}
12865
MP_DEFINE_CONST_FUN_OBJ_1(wiznet_pio_spi_deinit_obj, wiznet_pio_spi_obj_deinit);
12966

130-
//| def __enter__(self) -> SPI:
131-
//| """No-op used by Context Managers.
132-
//| Provided by context manager helper."""
133-
//| ...
134-
//|
67+
// TODO: def __enter__
13568

136-
//| def __exit__(self) -> None:
137-
//| """Automatically deinitializes the hardware when exiting a context. See
138-
//| :ref:`lifetime-and-contextmanagers` for more info."""
139-
//| ...
140-
//|
141-
// Provided by context manager helper.
69+
// TODO: def __exit__
14270

14371
static void check_lock(wiznet_pio_spi_obj_t *self) {
14472
asm ("");
@@ -153,31 +81,7 @@ static void check_for_deinit(wiznet_pio_spi_obj_t *self) {
15381
}
15482
}
15583

156-
//| def configure(
157-
//| self, *, baudrate: int = 100000, polarity: int = 0, phase: int = 0, bits: int = 8
158-
//| ) -> None:
159-
//| """Configures the SPI bus. The SPI object must be locked.
160-
//|
161-
//| :param int baudrate: the desired clock rate in Hertz. The actual clock rate may be higher or lower
162-
//| due to the granularity of available clock settings.
163-
//| Check the `frequency` attribute for the actual clock rate.
164-
//| :param int polarity: the base state of the clock line (0 or 1)
165-
//| :param int phase: the edge of the clock that data is captured. First (0)
166-
//| or second (1). Rising or falling depends on clock polarity.
167-
//| :param int bits: the number of bits per word
168-
//|
169-
//| .. note:: On the SAMD21, it is possible to set the baudrate to 24 MHz, but that
170-
//| speed is not guaranteed to work. 12 MHz is the next available lower speed, and is
171-
//| within spec for the SAMD21.
172-
//|
173-
//| .. note:: On the nRF52840, these baudrates are available: 125kHz, 250kHz, 1MHz, 2MHz, 4MHz,
174-
//| and 8MHz.
175-
//| If you pick a a baudrate other than one of these, the nearest lower
176-
//| baudrate will be chosen, with a minimum of 125kHz.
177-
//| Two SPI objects may be created, except on the Circuit Playground Bluefruit,
178-
//| which allows only one (to allow for an additional I2C object)."""
179-
//| ...
180-
//|
84+
// TODO: def configure
18185

18286
static mp_obj_t wiznet_pio_spi_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
18387
enum { ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits };
@@ -205,24 +109,15 @@ static mp_obj_t wiznet_pio_spi_configure(size_t n_args, const mp_obj_t *pos_args
205109
}
206110
MP_DEFINE_CONST_FUN_OBJ_KW(wiznet_pio_spi_configure_obj, 1, wiznet_pio_spi_configure);
207111

208-
//| def try_lock(self) -> bool:
209-
//| """Attempts to grab the SPI lock. Returns True on success.
210-
//|
211-
//| :return: True when lock has been grabbed
212-
//| :rtype: bool"""
213-
//| ...
214-
//|
112+
// TODO: def try_lock
215113

216114
static mp_obj_t wiznet_pio_spi_obj_try_lock(mp_obj_t self_in) {
217115
wiznet_pio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
218116
return mp_obj_new_bool(common_hal_wiznet_pio_spi_try_lock(self));
219117
}
220118
MP_DEFINE_CONST_FUN_OBJ_1(wiznet_pio_spi_try_lock_obj, wiznet_pio_spi_obj_try_lock);
221119

222-
//| def unlock(self) -> None:
223-
//| """Releases the SPI lock."""
224-
//| ...
225-
//|
120+
// TODO: def unlock
226121

227122
static mp_obj_t wiznet_pio_spi_obj_unlock(mp_obj_t self_in) {
228123
wiznet_pio_spi_obj_t *self = MP_OBJ_TO_PTR(self_in);
@@ -232,22 +127,7 @@ static mp_obj_t wiznet_pio_spi_obj_unlock(mp_obj_t self_in) {
232127
}
233128
MP_DEFINE_CONST_FUN_OBJ_1(wiznet_pio_spi_unlock_obj, wiznet_pio_spi_obj_unlock);
234129

235-
//| import sys
236-
//|
237-
//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = sys.maxsize) -> None:
238-
//| """Write the data contained in ``buffer``. The SPI object must be locked.
239-
//| If the buffer is empty, nothing happens.
240-
//|
241-
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
242-
//| as if ``buffer[start:end]`` were passed, but without copying the data.
243-
//| The number of bytes written will be the length of ``buffer[start:end]``.
244-
//|
245-
//| :param ReadableBuffer buffer: write out bytes from this buffer
246-
//| :param int start: beginning of buffer slice
247-
//| :param int end: end of buffer slice; if not specified, use ``len(buffer)``
248-
//| """
249-
//| ...
250-
//|
130+
// TODO: def write
251131

252132
static mp_obj_t wiznet_pio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
253133
enum { ARG_buffer, ARG_start, ARG_end };
@@ -280,42 +160,15 @@ static mp_obj_t wiznet_pio_spi_write(size_t n_args, const mp_obj_t *pos_args, mp
280160
}
281161

282162
bool ok = common_hal_wiznet_pio_spi_write(self, ((uint8_t *)bufinfo.buf) + start, length);
283-
163+
284164
if (!ok) {
285165
mp_raise_OSError(MP_EIO);
286166
}
287167
return mp_const_none;
288168
}
289169
MP_DEFINE_CONST_FUN_OBJ_KW(wiznet_pio_spi_write_obj, 1, wiznet_pio_spi_write);
290170

291-
292-
//| import sys
293-
//|
294-
//| def readinto(
295-
//| self,
296-
//| buffer: WriteableBuffer,
297-
//| *,
298-
//| start: int = 0,
299-
//| end: int = sys.maxsize,
300-
//| write_value: int = 0,
301-
//| ) -> None:
302-
//| """Read into ``buffer`` while writing ``write_value`` for each byte read.
303-
//| The SPI object must be locked.
304-
//| If the number of bytes to read is 0, nothing happens.
305-
//|
306-
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
307-
//| as if ``buffer[start:end]`` were passed.
308-
//| The number of bytes read will be the length of ``buffer[start:end]``.
309-
//|
310-
//| :param WriteableBuffer buffer: read bytes into this buffer
311-
//| :param int start: beginning of buffer slice
312-
//| :param int end: end of buffer slice; if not specified, it will be the equivalent value
313-
//| of ``len(buffer)`` and for any value provided it will take the value of
314-
//| ``min(end, len(buffer))``
315-
//| :param int write_value: value to write while reading
316-
//| """
317-
//| ...
318-
//|
171+
// TODO: def readinto
319172

320173
static mp_obj_t wiznet_pio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
321174
enum { ARG_buffer, ARG_start, ARG_end, ARG_write_value };
@@ -355,42 +208,8 @@ static mp_obj_t wiznet_pio_spi_readinto(size_t n_args, const mp_obj_t *pos_args,
355208
}
356209
MP_DEFINE_CONST_FUN_OBJ_KW(wiznet_pio_spi_readinto_obj, 1, wiznet_pio_spi_readinto);
357210

358-
//| import sys
359-
//|
360-
//| def write_readinto(
361-
//| self,
362-
//| out_buffer: ReadableBuffer,
363-
//| in_buffer: WriteableBuffer,
364-
//| *,
365-
//| out_start: int = 0,
366-
//| out_end: int = sys.maxsize,
367-
//| in_start: int = 0,
368-
//| in_end: int = sys.maxsize,
369-
//| ) -> None:
370-
//| """Write out the data in ``out_buffer`` while simultaneously reading data into ``in_buffer``.
371-
//| The SPI object must be locked.
372-
//|
373-
//| If ``out_start`` or ``out_end`` is provided, then the buffer will be sliced
374-
//| as if ``out_buffer[out_start:out_end]`` were passed, but without copying the data.
375-
//| The number of bytes written will be the length of ``out_buffer[out_start:out_end]``.
376-
//|
377-
//| If ``in_start`` or ``in_end`` is provided, then the input buffer will be sliced
378-
//| as if ``in_buffer[in_start:in_end]`` were passed,
379-
//| The number of bytes read will be the length of ``out_buffer[in_start:in_end]``.
380-
//|
381-
//| The lengths of the slices defined by ``out_buffer[out_start:out_end]``
382-
//| and ``in_buffer[in_start:in_end]`` must be equal.
383-
//| If buffer slice lengths are both 0, nothing happens.
384-
//|
385-
//| :param ReadableBuffer out_buffer: write out bytes from this buffer
386-
//| :param WriteableBuffer in_buffer: read bytes into this buffer
387-
//| :param int out_start: beginning of ``out_buffer`` slice
388-
//| :param int out_end: end of ``out_buffer`` slice; if not specified, use ``len(out_buffer)``
389-
//| :param int in_start: beginning of ``in_buffer`` slice
390-
//| :param int in_end: end of ``in_buffer slice``; if not specified, use ``len(in_buffer)``
391-
//| """
392-
//| ...
393-
//|
211+
212+
// TODO: def write_readinto
394213

395214
static mp_obj_t wiznet_pio_spi_write_readinto(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
396215
enum { ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };
@@ -447,12 +266,6 @@ static mp_obj_t wiznet_pio_spi_write_readinto(size_t n_args, const mp_obj_t *pos
447266
}
448267
MP_DEFINE_CONST_FUN_OBJ_KW(wiznet_pio_spi_write_readinto_obj, 1, wiznet_pio_spi_write_readinto);
449268

450-
//| frequency: int
451-
//| """The actual SPI bus frequency. This may not match the frequency requested
452-
//| due to internal limitations."""
453-
//|
454-
//|
455-
456269
#endif // CIRCUITPY_WIZNET_PIO_SPI
457270

458271
static const mp_rom_map_elem_t wiznet_pio_spi_locals_dict_table[] = {

shared-bindings/busio/__init__.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ static const mp_rom_map_elem_t busio_module_globals_table[] = {
7373
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&busio_i2c_type) },
7474
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&busio_spi_type) },
7575
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&busio_uart_type) },
76-
#if CIRCUITPY_WIZNET_PIO_SPI
76+
#if CIRCUITPY_WIZNET_PIO_SPI
7777
{ MP_ROM_QSTR(MP_QSTR_WIZNET_PIO_SPI), MP_ROM_PTR(&busio_wiznet_pio_spi_type) },
78-
#endif
78+
#endif
7979
};
8080

8181
static MP_DEFINE_CONST_DICT(busio_module_globals, busio_module_globals_table);

0 commit comments

Comments
 (0)