Skip to content

Commit 4dd26fe

Browse files
committed
ports/rp2: Provide direct memory access to PIO FIFOs via proxy arrays.
Signed-off-by: Nicko van Someren <nicko@nicko.org>
1 parent 92ce8e4 commit 4dd26fe

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ports/rp2/machine_spi.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,18 @@ STATIC void machine_spi_transfer(mp_obj_base_t *self_in, size_t len, const uint8
302302
}
303303
}
304304

305+
// Buffer protocol implementation for StateMachine
306+
// The buffer represents the SPI data FIFO.
307+
STATIC mp_int_t machine_spi_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
308+
machine_spi_obj_t *self = MP_OBJ_TO_PTR(o_in);
309+
310+
bufinfo->len = 4;
311+
bufinfo->typecode = 'I';
312+
bufinfo->buf = (void *)&spi_get_hw(self->spi_inst)->dr;
313+
314+
return 0;
315+
}
316+
305317
STATIC const mp_machine_spi_p_t machine_spi_p = {
306318
.init = machine_spi_init,
307319
.transfer = machine_spi_transfer,
@@ -314,6 +326,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
314326
make_new, machine_spi_make_new,
315327
print, machine_spi_print,
316328
protocol, &machine_spi_p,
329+
buffer, machine_spi_get_buffer,
317330
locals_dict, &mp_machine_spi_locals_dict
318331
);
319332

ports/rp2/rp2_pio.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,23 @@ STATIC mp_obj_t rp2_state_machine_tx_fifo(mp_obj_t self_in) {
809809
}
810810
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rp2_state_machine_tx_fifo_obj, rp2_state_machine_tx_fifo);
811811

812+
// Buffer protocol implementation for StateMachine
813+
// The buffer represents one of the FIFO ports of the state machine. Note that a different
814+
// pointer is returned depending on if this is for reading or writing.
815+
STATIC mp_int_t rp2_state_machine_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
816+
rp2_state_machine_obj_t *self = MP_OBJ_TO_PTR(o_in);
817+
818+
bufinfo->len = 4;
819+
bufinfo->typecode = 'I';
820+
821+
if (flags & MP_BUFFER_WRITE) {
822+
bufinfo->buf = (void *)&self->pio->txf[self->sm];
823+
} else {
824+
bufinfo->buf = (void *)&self->pio->rxf[self->sm];
825+
}
826+
return 0;
827+
}
828+
812829
// StateMachine.irq(handler=None, trigger=0|1, hard=False)
813830
STATIC mp_obj_t rp2_state_machine_irq(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
814831
enum { ARG_handler, ARG_trigger, ARG_hard };
@@ -884,6 +901,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
884901
MP_TYPE_FLAG_NONE,
885902
make_new, rp2_state_machine_make_new,
886903
print, rp2_state_machine_print,
904+
buffer, rp2_state_machine_get_buffer,
887905
locals_dict, &rp2_state_machine_locals_dict
888906
);
889907

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy