-
Notifications
You must be signed in to change notification settings - Fork 233
pio/pio_spi.py: methods of PIOSPI are missing self
#20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think the |
Yup, seems like you're right. AFAICT the method-declarations should be:
I'm not very familiar with the low-level details of SPI or PIO, so I suspect this is one for @Wren6991 - but I think that as I also see that https://github.com/raspberrypi/pico-micropython-examples/blob/master/pio/pio_spi.py#L30 has There's a more complete example of SPI-implemented-with-PIO at https://github.com/raspberrypi/pico-examples/blob/master/pio/spi/spi.pio |
Great link, this is where I took "inspiration" for my own version of SPI that just does sending, without MISO or CS pins (because I didn't need them for my application). This saved me two pins :). |
Necro-bump. We just hit this ourselves! In theory, the To compound matters, from rp2 import StateMachine
class SPI:
"""
Raspberry Pi Pico-specific drop-in replacement for Micropython's stock
:class:`machine.SPI` class, implemented as a Programmable Input/Output
(PIO)-optimized class.
Attributes
--------------
_sm : StateMachine
Finite state machine (FSM) underlying the PIO performed by this class.
"""
#FIXME: Generalize to support enabling the "cpha" and "cpol" parameters.
def __init__(
self,
pio_statemachine_id,
mosi,
miso,
sck,
baudrate,
cpha=False,
cpol=False,
):
"""
Create this PIO-optimized SPI interface.
Parameters
--------------
pio_statemachine_id : int
0-based index of the PIO-based finite state machine (FSM) to run
this SPI implementation on. Since the Pico supports 8 PIO FSMs,
this *must* be an integer in ``[0, 7]``.
"""
# If this SPI baudrate exceeds the Pico's system clock frequency,
# raise an exception.
if baudrate > 125000000:
raise ValueError(
f'SPI baudrate {baudrate} > system clock frequency {BAUDRATE_MAX}.')
# If the caller attempted to enable either CPHA or CPOL, raise an
# exception. This run_spi_cpol_0_cpha_0() assembly deferred to below
# currently assumes this to be the case.
if cpha:
raise ValueError('Enabling CPHA currently unsupported.')
if cpol:
raise ValueError('Enabling CPOL currently unsupported.')
# Create, classify, and enable a new FSM running this PIO assembly.
self._sm = StateMachine(
# These first two parameters *MUST* be passed positionally.
pio_statemachine_id,
spi_cpha0,
# All remaining parameters *MAY* be passed by keyword.
#FIXME: Why the "4" multiplier magic number here? *sigh*
freq=4 * baudrate,
sideset_base=sck,
out_base=mosi,
in_base=miso,
)
self._sm.active(1)
def read(self, buffer_out):
for byte_index in range(len(buffer_out)):
buffer_out[byte_index] = self._sm.get() & 0xff
def write(self, buffer_in):
for byte_in in buffer_in:
self._sm.put(byte_in << 24)
# Drain the RX FIFO to avoid catastrophic memory leaks.
self._sm.get() & 0xff
def write_readinto(self, buffer_in, buffer_out):
for byte_index in range(len(buffer_out)):
self._sm.put(buffer_in[byte_index] << 24)
buffer_out[byte_index] = self._sm.get() & 0xff Great, right? Nope. This is profiling as approximately four times slower than We suspect this is all probably intended and unexpected, but thought it worth mentioning for everyone watching back home. tl;drJust use |
The RP2040 MicroPython port has been merged upstream to the main MicroPython repo, see micropython/micropython#6791. Going forward you should report problems with the port there, https://github.com/micropython/micropython/. Technical support for MicroPython problems can be found on the MicroPython forums, https://forum.micropython.org/viewforum.php. |
Oh. You're quite right. I'll copy-pasta myself over there, then. Thanks for the heads up, Alasdair! Interestingly, MicroPython's RP2040 |
Hi!
It seems methods here are missing
self
:https://github.com/raspberrypi/pico-micropython-examples/blob/master/pio/pio_spi.py
The text was updated successfully, but these errors were encountered: