Skip to content

Commit a2bf8fe

Browse files
committed
Use SDK API function to turn PIO index into PIO pointer
1 parent 53d8da6 commit a2bf8fe

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2040.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
picodvi_framebuffer_obj_t *active_picodvi = NULL;
2727

28-
static PIO pio_instances[2] = {pio0, pio1};
29-
3028
static void __not_in_flash_func(core1_main)(void) {
3129
// The MPU is reset before this starts.
3230

@@ -184,7 +182,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
184182
size_t pio_index = NUM_PIOS;
185183
int free_state_machines[4]; // We may find all four free. We only use the first three.
186184
for (size_t i = 0; i < NUM_PIOS; i++) {
187-
PIO pio = pio_instances[i];
185+
PIO pio = pio_get_instance(i);
188186
uint8_t free_count = 0;
189187
for (size_t sm = 0; sm < NUM_PIO_STATE_MACHINES; sm++) {
190188
if (!pio_sm_is_claimed(pio, sm)) {
@@ -244,7 +242,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
244242
}
245243

246244
for (size_t i = 0; i < 3; i++) {
247-
rp2pio_statemachine_never_reset(pio_instances[pio_index], free_state_machines[i]);
245+
rp2pio_statemachine_never_reset(pio_get_instance(pio_index), free_state_machines[i]);
248246
}
249247

250248
// For the output.
@@ -253,7 +251,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self,
253251
self->color_depth = color_depth;
254252

255253
self->dvi.timing = timing;
256-
self->dvi.ser_cfg.pio = pio_instances[pio_index];
254+
self->dvi.ser_cfg.pio = pio_get_instance(pio_index);
257255
self->dvi.ser_cfg.sm_tmds[0] = free_state_machines[0];
258256
self->dvi.ser_cfg.sm_tmds[1] = free_state_machines[1];
259257
self->dvi.ser_cfg.sm_tmds[2] = free_state_machines[2];

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ static int8_t _sm_dma_plus_one_read[NUM_PIOS][NUM_PIO_STATE_MACHINES];
5151
#define SM_DMA_CLEAR_CHANNEL_READ(pio_index, sm) (_sm_dma_plus_one_read[(pio_index)][(sm)] = 0)
5252
#define SM_DMA_SET_CHANNEL_READ(pio_index, sm, channel) (_sm_dma_plus_one_read[(pio_index)][(sm)] = (channel) + 1)
5353

54-
static PIO pio_instances[NUM_PIOS] = {
55-
pio0,
56-
pio1
57-
#if NUM_PIOS == 3
58-
, pio2
59-
#endif
60-
};
6154
typedef void (*interrupt_handler_type)(void *);
6255
static interrupt_handler_type _interrupt_handler[NUM_PIOS][NUM_PIO_STATE_MACHINES];
6356
static void *_interrupt_arg[NUM_PIOS][NUM_PIO_STATE_MACHINES];
@@ -162,7 +155,7 @@ static void _reset_statemachine(PIO pio, uint8_t sm, bool leave_pins) {
162155

163156
void reset_rp2pio_statemachine(void) {
164157
for (size_t i = 0; i < NUM_PIOS; i++) {
165-
PIO pio = pio_instances[i];
158+
PIO pio = pio_get_instance(i);
166159
for (size_t j = 0; j < NUM_PIO_STATE_MACHINES; j++) {
167160
if (_never_reset[i][j]) {
168161
continue;
@@ -252,7 +245,7 @@ static bool use_existing_program(PIO *pio_out, uint *sm_out, int *offset_inout,
252245
}
253246

254247
for (size_t i = 0; i < NUM_PIOS; i++) {
255-
PIO pio = pio_instances[i];
248+
PIO pio = pio_get_instance(i);
256249
if (!is_gpio_compatible(pio, required_gpio_ranges)) {
257250
continue;
258251
}
@@ -1097,7 +1090,7 @@ void common_hal_rp2pio_statemachine_set_interrupt_handler(rp2pio_statemachine_ob
10971090

10981091
static void rp2pio_statemachine_interrupt_handler(void) {
10991092
for (size_t pio_index = 0; pio_index < NUM_PIOS; pio_index++) {
1100-
PIO pio = pio_instances[pio_index];
1093+
PIO pio = pio_get_instance(pio_index);
11011094
for (size_t sm = 0; sm < NUM_PIO_STATE_MACHINES; sm++) {
11021095
if (!_interrupt_handler[pio_index][sm]) {
11031096
continue;
@@ -1452,7 +1445,7 @@ int common_hal_rp2pio_statemachine_get_offset(rp2pio_statemachine_obj_t *self) {
14521445

14531446
int common_hal_rp2pio_statemachine_get_pc(rp2pio_statemachine_obj_t *self) {
14541447
uint8_t pio_index = pio_get_index(self->pio);
1455-
PIO pio = pio_instances[pio_index];
1448+
PIO pio = pio_get_instance(pio_index);
14561449
uint8_t sm = self->state_machine;
14571450
return pio_sm_get_pc(pio, sm);
14581451
}

ports/raspberrypi/common-hal/usb_host/Port.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
usb_host_port_obj_t usb_host_instance;
3535

36-
static PIO pio_instances[2] = {pio0, pio1};
3736
volatile bool _core1_ready = false;
3837

3938
static void __not_in_flash_func(core1_main)(void) {
@@ -76,7 +75,7 @@ static void __not_in_flash_func(core1_main)(void) {
7675
}
7776

7877
static uint8_t _sm_free_count(uint8_t pio_index) {
79-
PIO pio = pio_instances[pio_index];
78+
PIO pio = pio_get_instance(pio_index);
8079
uint8_t free_count = 0;
8180
for (size_t j = 0; j < NUM_PIO_STATE_MACHINES; j++) {
8281
if (!pio_sm_is_claimed(pio, j)) {
@@ -87,7 +86,7 @@ static uint8_t _sm_free_count(uint8_t pio_index) {
8786
}
8887

8988
static bool _has_program_room(uint8_t pio_index, uint8_t program_size) {
90-
PIO pio = pio_instances[pio_index];
89+
PIO pio = pio_get_instance(pio_index);
9190
pio_program_t program_struct = {
9291
.instructions = NULL,
9392
.length = program_size,
@@ -148,7 +147,7 @@ usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp,
148147
self->dp = dp;
149148
self->dm = dm;
150149

151-
PIO pio = pio_instances[pio_cfg.pio_tx_num];
150+
PIO pio = pio_get_instance(pio_cfg.pio_tx_num);
152151

153152
// Unclaim everything so that the library can.
154153
dma_channel_unclaim(pio_cfg.tx_ch);

0 commit comments

Comments
 (0)