Skip to content

Commit 3e13d4f

Browse files
committed
Add sideset_enable support to PIO
This allows for UART TX via PIO
1 parent 7c2e7bf commit 3e13d4f

File tree

12 files changed

+38
-10
lines changed

12 files changed

+38
-10
lines changed

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
//| sideset_pin_count: int = 1,
7979
//| initial_sideset_pin_state: int = 0,
8080
//| initial_sideset_pin_direction: int = 0x1f,
81+
//| sideset_enable: bool = False,
8182
//| exclusive_pin_use: bool = True,
8283
//| auto_pull: bool = False,
8384
//| pull_threshold: int = 32,
@@ -107,9 +108,10 @@
107108
//| :param int initial_set_pin_state: the initial output value for set pins starting at first_set_pin
108109
//| :param int initial_set_pin_direction: the initial output direction for set pins starting at first_set_pin
109110
//| :param ~microcontroller.Pin first_sideset_pin: the first pin to use with a side set
110-
//| :param int sideset_pin_count: the count of consecutive pins to use with a side set starting at first_sideset_pin
111+
//| :param int sideset_pin_count: the count of consecutive pins to use with a side set starting at first_sideset_pin. Does not include sideset enable
111112
//| :param int initial_sideset_pin_state: the initial output value for sideset pins starting at first_sideset_pin
112113
//| :param int initial_sideset_pin_direction: the initial output direction for sideset pins starting at first_sideset_pin
114+
//| :param bool sideset_enable: True when the top sideset bit is to enable. This should be used with the ".side_set # opt" directive
113115
//| :param ~microcontroller.Pin jmp_pin: the pin which determines the branch taken by JMP PIN instructions
114116
//| :param bool exclusive_pin_use: When True, do not share any pins with other state machines. Pins are never shared with other peripherals
115117
//| :param bool auto_pull: When True, automatically load data from the tx FIFO into the
@@ -147,6 +149,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
147149
ARG_pull_in_pin_up, ARG_pull_in_pin_down,
148150
ARG_first_set_pin, ARG_set_pin_count, ARG_initial_set_pin_state, ARG_initial_set_pin_direction,
149151
ARG_first_sideset_pin, ARG_sideset_pin_count, ARG_initial_sideset_pin_state, ARG_initial_sideset_pin_direction,
152+
ARG_sideset_enable,
150153
ARG_jmp_pin,
151154
ARG_exclusive_pin_use,
152155
ARG_auto_pull, ARG_pull_threshold, ARG_out_shift_right,
@@ -178,6 +181,8 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
178181
{ MP_QSTR_initial_sideset_pin_state, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
179182
{ MP_QSTR_initial_sideset_pin_direction, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x1f} },
180183

184+
{ MP_QSTR_sideset_enable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
185+
181186
{ MP_QSTR_jmp_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
182187

183188
{ MP_QSTR_exclusive_pin_use, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
@@ -257,6 +262,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n
257262
first_in_pin, args[ARG_in_pin_count].u_int, args[ARG_pull_in_pin_up].u_int, args[ARG_pull_in_pin_down].u_int,
258263
first_set_pin, args[ARG_set_pin_count].u_int, args[ARG_initial_set_pin_state].u_int, args[ARG_initial_set_pin_direction].u_int,
259264
first_sideset_pin, args[ARG_sideset_pin_count].u_int, args[ARG_initial_sideset_pin_state].u_int, args[ARG_initial_sideset_pin_direction].u_int,
265+
args[ARG_sideset_enable].u_bool,
260266
jmp_pin,
261267
0,
262268
args[ARG_exclusive_pin_use].u_bool,

ports/raspberrypi/bindings/rp2pio/StateMachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
4444
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count, uint32_t pull_pin_up, uint32_t pull_pin_down,
4545
const mcu_pin_obj_t *first_set_pin, uint8_t set_pin_count, uint32_t initial_set_pin_state, uint32_t initial_set_pin_direction,
4646
const mcu_pin_obj_t *first_sideset_pin, uint8_t sideset_pin_count, uint32_t initial_sideset_pin_state, uint32_t initial_sideset_pin_direction,
47+
bool sideset_enable,
4748
const mcu_pin_obj_t *jmp_pin,
4849
uint32_t wait_gpio_mask,
4950
bool exclusive_pin_use,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
133133
false, 32, false, // shift out left to start with MSB
134134
false, // Wait for txstall
135135
false, 32, false, // in settings
136-
false); // Not user-interruptible.
136+
false, // Not user-interruptible.
137+
false); // No sideset enable
137138

138139
self->playing = false;
139140
audio_dma_init(&self->dma);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
7777
false, 32, false, // out settings
7878
false, // Wait for txstall
7979
false, 32, true, // in settings
80-
false); // Not user-interruptible
80+
false, // Not user-interruptible.
81+
false); // No sideset enable
8182

8283
uint32_t actual_frequency = common_hal_rp2pio_statemachine_get_frequency(&self->state_machine);
8384
if (actual_frequency < MIN_MIC_CLOCK) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
111111
#else
112112
NULL, 0, 0, 0, // sideset pins
113113
#endif
114+
false, // No sideset enable
114115
NULL, // jump pin
115116
(1 << vertical_sync->number) | (1 << horizontal_reference->number) | (1 << data_clock->number), // wait gpio pins
116117
true, // exclusive pin use

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,
7777
true, // Wait for txstall. If we don't, then we'll deinit too quickly.
7878
false, 32, true, // RX setting we don't use
7979
false, // claim pins
80-
false); // Not user-interruptible.
80+
false, // Not user-interruptible.
81+
false); // No sideset enable
8182
if (!ok) {
8283
// Do nothing. Maybe bitbang?
8384
return;

ports/raspberrypi/common-hal/nvm/ByteArray.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ static void erase_and_write_sector(uint32_t address, uint32_t len, uint8_t *byte
6565
// Write a whole sector to flash, buffering it first and then erasing and rewriting it
6666
// since we can only erase a whole sector at a time.
6767
uint8_t buffer[FLASH_SECTOR_SIZE];
68+
// TODO: Update this to a better workaround for GCC 11 when one is provided.
69+
// See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578#c20
70+
#pragma GCC diagnostic push
71+
#pragma GCC diagnostic ignored "-Warray-bounds"
72+
#pragma GCC diagnostic ignored "-Wstringop-overread"
6873
memcpy(buffer, (uint8_t *)CIRCUITPY_INTERNAL_NVM_START_ADDR, FLASH_SECTOR_SIZE);
74+
#pragma GCC diagnostic pop
6975
memcpy(buffer + address, bytes, len);
7076
// disable interrupts to prevent core hang on rp2040
7177
common_hal_mcu_disable_interrupts();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ void common_hal_paralleldisplay_parallelbus_construct(paralleldisplay_parallelbu
9999
NULL, 0, 0, 0, // first in pin, # in pins
100100
NULL, 0, 0, 0, // first set pin
101101
write, 1, 0, 1, // first sideset pin
102+
false, // No sideset enable
102103
NULL, // jump pin
103104
0, // wait gpio pins
104105
true, // exclusive pin usage

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
7373
false,
7474
true, 32, true, // RX auto-push every 32 bits
7575
false, // claim pins
76-
false); // Not user-interruptible.
76+
false, // Not user-interruptible.
77+
false); // No sideset enable
7778

7879
if (!ok) {
7980
mp_raise_RuntimeError(translate("All state machines in use"));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
8585
3, 0, // in pulls
8686
NULL, 0, 0, 0x1f, // set pins
8787
NULL, 0, 0, 0x1f, // sideset pins
88+
false, // No sideset enable
8889
NULL, // jump pin
8990
0, // wait gpio pins
9091
true, // exclusive pin use

0 commit comments

Comments
 (0)