Skip to content

Commit 5fe8d12

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 91b6aab + 345a829 commit 5fe8d12

File tree

12 files changed

+237
-46
lines changed

12 files changed

+237
-46
lines changed

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 122 additions & 24 deletions
Large diffs are not rendered by default.

ports/raspberrypi/bindings/rp2pio/StateMachine.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
3434
bool auto_push, uint8_t push_threshold, bool in_shift_right,
3535
bool user_interruptible,
3636
int wrap_taget, int wrap,
37-
int offset);
37+
int offset,
38+
int fifo_type,
39+
int mov_status_type,
40+
int mov_status_n);
3841

3942
void common_hal_rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self);
4043
bool common_hal_rp2pio_statemachine_deinited(rp2pio_statemachine_obj_t *self);
@@ -70,3 +73,5 @@ int common_hal_rp2pio_statemachine_get_offset(rp2pio_statemachine_obj_t *self);
7073
int common_hal_rp2pio_statemachine_get_pc(rp2pio_statemachine_obj_t *self);
7174

7275
void common_hal_rp2pio_statemachine_set_interrupt_handler(rp2pio_statemachine_obj_t *self, void (*handler)(void *), void *arg, int mask);
76+
77+
mp_obj_t common_hal_rp2pio_statemachine_get_rxfifo(rp2pio_statemachine_obj_t *self);

ports/raspberrypi/common-hal/audiobusio/I2SOut.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
198198
false, 32, false, // in settings
199199
false, // Not user-interruptible.
200200
0, -1, // wrap settings
201-
PIO_ANY_OFFSET);
201+
PIO_ANY_OFFSET,
202+
PIO_FIFO_TYPE_DEFAULT,
203+
PIO_MOV_STATUS_DEFAULT,
204+
PIO_MOV_N_DEFAULT
205+
);
202206

203207
self->playing = false;
204208
audio_dma_init(&self->dma);

ports/raspberrypi/common-hal/audiobusio/PDMIn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
6060
false, 32, true, // in settings
6161
false, // Not user-interruptible.
6262
0, -1, // wrap settings
63-
PIO_ANY_OFFSET);
63+
PIO_ANY_OFFSET,
64+
PIO_FIFO_TYPE_DEFAULT,
65+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
6466
uint32_t actual_frequency = common_hal_rp2pio_statemachine_get_frequency(&self->state_machine);
6567
if (actual_frequency < MIN_MIC_CLOCK) {
6668
mp_raise_ValueError(MP_ERROR_TEXT("sampling rate out of range"));

ports/raspberrypi/common-hal/floppyio/__init__.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ int common_hal_floppyio_flux_readinto(void *buf, size_t len, digitalio_digitalin
9999
false, // Not user-interruptible.
100100
false, // No sideset enable
101101
0, -1, // wrap
102-
PIO_ANY_OFFSET // offset
102+
PIO_ANY_OFFSET, // offset
103+
PIO_FIFO_TYPE_DEFAULT,
104+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT
103105
);
104106
if (!ok) {
105107
mp_raise_RuntimeError(MP_ERROR_TEXT("All state machines in use"));

ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
101101
true, 32, true, // in settings
102102
false, // Not user-interruptible.
103103
2, 5, // wrap settings
104-
PIO_ANY_OFFSET);
104+
PIO_ANY_OFFSET,
105+
PIO_FIFO_TYPE_DEFAULT,
106+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
105107
}
106108

107109
void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self) {

ports/raspberrypi/common-hal/neopixel_write/__init__.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,
6060
false, // Not user-interruptible.
6161
false, // No sideset enable
6262
0, -1, // wrap
63-
PIO_ANY_OFFSET // offset
64-
);
63+
PIO_ANY_OFFSET, // offset
64+
PIO_FIFO_TYPE_DEFAULT,
65+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
6566
if (!ok) {
6667
// Do nothing. Maybe bitbang?
6768
return;

ports/raspberrypi/common-hal/paralleldisplaybus/ParallelBus.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ void common_hal_paralleldisplaybus_parallelbus_construct(paralleldisplaybus_para
9292
false, 32, true, // RX setting we don't use
9393
false, // Not user-interruptible.
9494
0, -1, // wrap settings
95-
PIO_ANY_OFFSET);
95+
PIO_ANY_OFFSET,
96+
PIO_FIFO_TYPE_DEFAULT,
97+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
9698

9799
common_hal_rp2pio_statemachine_never_reset(&self->state_machine);
98100
}

ports/raspberrypi/common-hal/pulseio/PulseIn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
5454
true, 32, true, // RX auto pull every 32 bits. shift left to output msb first
5555
false, // Not user-interruptible.
5656
0, -1, // wrap settings
57-
PIO_ANY_OFFSET);
57+
PIO_ANY_OFFSET,
58+
PIO_FIFO_TYPE_DEFAULT,
59+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
5860

5961
common_hal_pulseio_pulsein_pause(self);
6062

ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
7676
false, 32, false, // in settings
7777
false, // Not user-interruptible.
7878
0, MP_ARRAY_SIZE(encoder) - 1, // wrap settings
79-
PIO_ANY_OFFSET
80-
);
79+
PIO_ANY_OFFSET,
80+
PIO_FIFO_TYPE_DEFAULT,
81+
PIO_MOV_STATUS_DEFAULT, PIO_MOV_N_DEFAULT);
8182

8283
// We're guaranteed by the init code that some output will be available promptly
8384
uint8_t quiescent_state;

ports/raspberrypi/common-hal/rp2pio/StateMachine.c

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "shared-bindings/digitalio/Pull.h"
1313
#include "shared-bindings/microcontroller/__init__.h"
1414
#include "shared-bindings/microcontroller/Pin.h"
15+
#include "shared-bindings/memorymap/AddressRange.h"
1516

1617
#include "src/rp2040/hardware_regs/include/hardware/platform_defs.h"
1718
#include "src/rp2_common/hardware_clocks/include/hardware/clocks.h"
@@ -180,6 +181,33 @@ static uint add_program(PIO pio, const pio_program_t *program, int offset) {
180181
}
181182
}
182183

184+
static enum pio_fifo_join compute_fifo_type(int fifo_type_in, bool rx_fifo, bool tx_fifo) {
185+
if (fifo_type_in != PIO_FIFO_JOIN_AUTO) {
186+
return fifo_type_in;
187+
}
188+
if (!rx_fifo) {
189+
return PIO_FIFO_JOIN_TX;
190+
}
191+
if (!tx_fifo) {
192+
return PIO_FIFO_JOIN_RX;
193+
}
194+
return PIO_FIFO_JOIN_NONE;
195+
}
196+
197+
static int compute_fifo_depth(enum pio_fifo_join join) {
198+
if (join == PIO_FIFO_JOIN_TX || join == PIO_FIFO_JOIN_RX) {
199+
return 8;
200+
}
201+
202+
#if PICO_PIO_VERSION > 0
203+
if (join == PIO_FIFO_JOIN_PUTGET) {
204+
return 0;
205+
}
206+
#endif
207+
208+
return 4;
209+
}
210+
183211
bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
184212
const uint16_t *program, size_t program_len,
185213
size_t frequency,
@@ -199,7 +227,9 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
199227
bool user_interruptible,
200228
bool sideset_enable,
201229
int wrap_target, int wrap,
202-
int offset
230+
int offset,
231+
int fifo_type,
232+
int mov_status_type, int mov_status_n
203233
) {
204234
// Create a program id that isn't the pointer so we can store it without storing the original object.
205235
uint32_t program_id = ~((uint32_t)program);
@@ -343,15 +373,27 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
343373

344374
sm_config_set_wrap(&c, wrap_target, wrap);
345375
sm_config_set_in_shift(&c, in_shift_right, auto_push, push_threshold);
376+
#if PICO_PIO_VERSION > 0
377+
sm_config_set_in_pin_count(&c, in_pin_count);
378+
#endif
379+
346380
sm_config_set_out_shift(&c, out_shift_right, auto_pull, pull_threshold);
381+
sm_config_set_out_pin_count(&c, out_pin_count);
347382

348-
enum pio_fifo_join join = PIO_FIFO_JOIN_NONE;
349-
if (!rx_fifo) {
350-
join = PIO_FIFO_JOIN_TX;
351-
} else if (!tx_fifo) {
352-
join = PIO_FIFO_JOIN_RX;
383+
sm_config_set_set_pin_count(&c, set_pin_count);
384+
385+
enum pio_fifo_join join = compute_fifo_type(fifo_type, rx_fifo, tx_fifo);
386+
387+
self->fifo_depth = compute_fifo_depth(join);
388+
389+
#if PICO_PIO_VERSION > 0
390+
if (fifo_type == PIO_FIFO_JOIN_TXPUT || fifo_type == PIO_FIFO_JOIN_TXGET) {
391+
self->rxfifo_obj.base.type = &memorymap_addressrange_type;
392+
common_hal_memorymap_addressrange_construct(&self->rxfifo_obj, (uint8_t *)self->pio->rxf_putget[self->state_machine], 4 * sizeof(uint32_t));
393+
} else {
394+
self->rxfifo_obj.base.type = NULL;
353395
}
354-
self->fifo_depth = (join == PIO_FIFO_JOIN_NONE) ? 4 : 8;
396+
#endif
355397

356398
if (rx_fifo) {
357399
self->rx_dreq = pio_get_dreq(self->pio, self->state_machine, false);
@@ -370,6 +412,11 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
370412
self->init_len = init_len;
371413

372414
sm_config_set_fifo_join(&c, join);
415+
416+
// TODO: these arguments
417+
// int mov_status_type, int mov_status_n,
418+
// int set_count, int out_count
419+
373420
self->sm_config = c;
374421

375422
// no DMA allocated
@@ -519,7 +566,10 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
519566
bool auto_push, uint8_t push_threshold, bool in_shift_right,
520567
bool user_interruptible,
521568
int wrap_target, int wrap,
522-
int offset) {
569+
int offset,
570+
int fifo_type,
571+
int mov_status_type,
572+
int mov_status_n) {
523573

524574
// First, check that all pins are free OR already in use by any PIO if exclusive_pin_use is false.
525575
uint32_t pins_we_use = wait_gpio_mask;
@@ -585,7 +635,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
585635
pull_up |= jmp_mask;
586636
}
587637
if (jmp_pull == PULL_DOWN) {
588-
pull_up |= jmp_mask;
638+
pull_down |= jmp_mask;
589639
}
590640
}
591641
if (initial_pin_direction & (pull_up | pull_down)) {
@@ -610,7 +660,9 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
610660
true /* claim pins */,
611661
user_interruptible,
612662
sideset_enable,
613-
wrap_target, wrap, offset);
663+
wrap_target, wrap, offset,
664+
fifo_type,
665+
mov_status_type, mov_status_n);
614666
if (!ok) {
615667
mp_raise_RuntimeError(MP_ERROR_TEXT("All state machines in use"));
616668
}
@@ -1102,6 +1154,16 @@ int common_hal_rp2pio_statemachine_get_pc(rp2pio_statemachine_obj_t *self) {
11021154
return pio_sm_get_pc(pio, sm);
11031155
}
11041156

1157+
mp_obj_t common_hal_rp2pio_statemachine_get_rxfifo(rp2pio_statemachine_obj_t *self) {
1158+
#if PICO_PIO_VERSION > 0
1159+
if (self->rxfifo_obj.base.type) {
1160+
return MP_OBJ_FROM_PTR(&self->rxfifo_obj);
1161+
}
1162+
#endif
1163+
return mp_const_none;
1164+
}
1165+
1166+
11051167
// Use a compile-time constant for MP_REGISTER_POINTER so the preprocessor will
11061168
// not split the expansion across multiple lines.
11071169
MP_REGISTER_ROOT_POINTER(mp_obj_t background_pio[enum_NUM_DMA_CHANNELS]);

ports/raspberrypi/common-hal/rp2pio/StateMachine.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
#include "py/obj.h"
1010

1111
#include "common-hal/microcontroller/Pin.h"
12+
#include "common-hal/memorymap/AddressRange.h"
1213
#include "src/rp2_common/hardware_pio/include/hardware/pio.h"
1314

1415
enum { PIO_ANY_OFFSET = -1 };
16+
enum { PIO_FIFO_JOIN_AUTO = -1, PIO_FIFO_TYPE_DEFAULT = PIO_FIFO_JOIN_AUTO };
17+
enum { PIO_MOV_STATUS_DEFAULT = STATUS_TX_LESSTHAN };
18+
enum { PIO_MOV_N_DEFAULT = 0 };
1519

1620
typedef struct sm_buf_info {
1721
mp_obj_t obj;
@@ -47,6 +51,9 @@ typedef struct {
4751
sm_buf_info current, once, loop;
4852
int background_stride_in_bytes;
4953
bool dma_completed, byteswap;
54+
#if PICO_PIO_VERSION > 0
55+
memorymap_addressrange_obj_t rxfifo_obj;
56+
#endif
5057
} rp2pio_statemachine_obj_t;
5158

5259
void reset_rp2pio_statemachine(void);
@@ -70,7 +77,10 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
7077
bool claim_pins,
7178
bool interruptible,
7279
bool sideset_enable,
73-
int wrap_target, int wrap, int offset);
80+
int wrap_target, int wrap, int offset,
81+
int fifo_type,
82+
int mov_status_type, int mov_status_n
83+
);
7484

7585
uint8_t rp2pio_statemachine_program_offset(rp2pio_statemachine_obj_t *self);
7686

0 commit comments

Comments
 (0)