Add sideset_enable support to PIO
This allows for UART TX via PIO
This commit is contained in:
parent
7c2e7bfeaa
commit
3e13d4f5b5
@ -78,6 +78,7 @@
|
||||
//| sideset_pin_count: int = 1,
|
||||
//| initial_sideset_pin_state: int = 0,
|
||||
//| initial_sideset_pin_direction: int = 0x1f,
|
||||
//| sideset_enable: bool = False,
|
||||
//| exclusive_pin_use: bool = True,
|
||||
//| auto_pull: bool = False,
|
||||
//| pull_threshold: int = 32,
|
||||
@ -107,9 +108,10 @@
|
||||
//| :param int initial_set_pin_state: the initial output value for set pins starting at first_set_pin
|
||||
//| :param int initial_set_pin_direction: the initial output direction for set pins starting at first_set_pin
|
||||
//| :param ~microcontroller.Pin first_sideset_pin: the first pin to use with a side set
|
||||
//| :param int sideset_pin_count: the count of consecutive pins to use with a side set starting at first_sideset_pin
|
||||
//| :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
|
||||
//| :param int initial_sideset_pin_state: the initial output value for sideset pins starting at first_sideset_pin
|
||||
//| :param int initial_sideset_pin_direction: the initial output direction for sideset pins starting at first_sideset_pin
|
||||
//| :param bool sideset_enable: True when the top sideset bit is to enable. This should be used with the ".side_set # opt" directive
|
||||
//| :param ~microcontroller.Pin jmp_pin: the pin which determines the branch taken by JMP PIN instructions
|
||||
//| :param bool exclusive_pin_use: When True, do not share any pins with other state machines. Pins are never shared with other peripherals
|
||||
//| :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
|
||||
ARG_pull_in_pin_up, ARG_pull_in_pin_down,
|
||||
ARG_first_set_pin, ARG_set_pin_count, ARG_initial_set_pin_state, ARG_initial_set_pin_direction,
|
||||
ARG_first_sideset_pin, ARG_sideset_pin_count, ARG_initial_sideset_pin_state, ARG_initial_sideset_pin_direction,
|
||||
ARG_sideset_enable,
|
||||
ARG_jmp_pin,
|
||||
ARG_exclusive_pin_use,
|
||||
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
|
||||
{ MP_QSTR_initial_sideset_pin_state, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} },
|
||||
{ MP_QSTR_initial_sideset_pin_direction, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0x1f} },
|
||||
|
||||
{ MP_QSTR_sideset_enable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
|
||||
|
||||
{ MP_QSTR_jmp_pin, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
|
||||
|
||||
{ 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
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
args[ARG_sideset_enable].u_bool,
|
||||
jmp_pin,
|
||||
0,
|
||||
args[ARG_exclusive_pin_use].u_bool,
|
||||
|
@ -44,6 +44,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
||||
const mcu_pin_obj_t *first_in_pin, uint8_t in_pin_count, uint32_t pull_pin_up, uint32_t pull_pin_down,
|
||||
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,
|
||||
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,
|
||||
bool sideset_enable,
|
||||
const mcu_pin_obj_t *jmp_pin,
|
||||
uint32_t wait_gpio_mask,
|
||||
bool exclusive_pin_use,
|
||||
|
@ -133,7 +133,8 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self,
|
||||
false, 32, false, // shift out left to start with MSB
|
||||
false, // Wait for txstall
|
||||
false, 32, false, // in settings
|
||||
false); // Not user-interruptible.
|
||||
false, // Not user-interruptible.
|
||||
false); // No sideset enable
|
||||
|
||||
self->playing = false;
|
||||
audio_dma_init(&self->dma);
|
||||
|
@ -77,7 +77,8 @@ void common_hal_audiobusio_pdmin_construct(audiobusio_pdmin_obj_t *self,
|
||||
false, 32, false, // out settings
|
||||
false, // Wait for txstall
|
||||
false, 32, true, // in settings
|
||||
false); // Not user-interruptible
|
||||
false, // Not user-interruptible.
|
||||
false); // No sideset enable
|
||||
|
||||
uint32_t actual_frequency = common_hal_rp2pio_statemachine_get_frequency(&self->state_machine);
|
||||
if (actual_frequency < MIN_MIC_CLOCK) {
|
||||
|
@ -111,6 +111,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle
|
||||
#else
|
||||
NULL, 0, 0, 0, // sideset pins
|
||||
#endif
|
||||
false, // No sideset enable
|
||||
NULL, // jump pin
|
||||
(1 << vertical_sync->number) | (1 << horizontal_reference->number) | (1 << data_clock->number), // wait gpio pins
|
||||
true, // exclusive pin use
|
||||
|
@ -77,7 +77,8 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout,
|
||||
true, // Wait for txstall. If we don't, then we'll deinit too quickly.
|
||||
false, 32, true, // RX setting we don't use
|
||||
false, // claim pins
|
||||
false); // Not user-interruptible.
|
||||
false, // Not user-interruptible.
|
||||
false); // No sideset enable
|
||||
if (!ok) {
|
||||
// Do nothing. Maybe bitbang?
|
||||
return;
|
||||
|
@ -65,7 +65,13 @@ static void erase_and_write_sector(uint32_t address, uint32_t len, uint8_t *byte
|
||||
// Write a whole sector to flash, buffering it first and then erasing and rewriting it
|
||||
// since we can only erase a whole sector at a time.
|
||||
uint8_t buffer[FLASH_SECTOR_SIZE];
|
||||
// TODO: Update this to a better workaround for GCC 11 when one is provided.
|
||||
// See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578#c20
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
#pragma GCC diagnostic ignored "-Wstringop-overread"
|
||||
memcpy(buffer, (uint8_t *)CIRCUITPY_INTERNAL_NVM_START_ADDR, FLASH_SECTOR_SIZE);
|
||||
#pragma GCC diagnostic pop
|
||||
memcpy(buffer + address, bytes, len);
|
||||
// disable interrupts to prevent core hang on rp2040
|
||||
common_hal_mcu_disable_interrupts();
|
||||
|
@ -99,6 +99,7 @@ void common_hal_paralleldisplay_parallelbus_construct(paralleldisplay_parallelbu
|
||||
NULL, 0, 0, 0, // first in pin, # in pins
|
||||
NULL, 0, 0, 0, // first set pin
|
||||
write, 1, 0, 1, // first sideset pin
|
||||
false, // No sideset enable
|
||||
NULL, // jump pin
|
||||
0, // wait gpio pins
|
||||
true, // exclusive pin usage
|
||||
|
@ -73,7 +73,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
||||
false,
|
||||
true, 32, true, // RX auto-push every 32 bits
|
||||
false, // claim pins
|
||||
false); // Not user-interruptible.
|
||||
false, // Not user-interruptible.
|
||||
false); // No sideset enable
|
||||
|
||||
if (!ok) {
|
||||
mp_raise_RuntimeError(translate("All state machines in use"));
|
||||
|
@ -85,6 +85,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode
|
||||
3, 0, // in pulls
|
||||
NULL, 0, 0, 0x1f, // set pins
|
||||
NULL, 0, 0, 0x1f, // sideset pins
|
||||
false, // No sideset enable
|
||||
NULL, // jump pin
|
||||
0, // wait gpio pins
|
||||
true, // exclusive pin use
|
||||
|
@ -164,7 +164,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
||||
bool wait_for_txstall,
|
||||
bool auto_push, uint8_t push_threshold, bool in_shift_right,
|
||||
bool claim_pins,
|
||||
bool user_interruptible
|
||||
bool user_interruptible,
|
||||
bool sideset_enable
|
||||
) {
|
||||
// Create a program id that isn't the pointer so we can store it without storing the original object.
|
||||
uint32_t program_id = ~((uint32_t)program);
|
||||
@ -278,7 +279,11 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
||||
sm_config_set_set_pins(&c, first_set_pin->number, set_pin_count);
|
||||
}
|
||||
if (first_sideset_pin != NULL) {
|
||||
sm_config_set_sideset(&c, sideset_pin_count, false /* optional */, false /* pin direction */);
|
||||
size_t total_sideset_bits = sideset_pin_count;
|
||||
if (sideset_enable) {
|
||||
total_sideset_bits += 1;
|
||||
}
|
||||
sm_config_set_sideset(&c, total_sideset_bits, sideset_enable, false /* pin direction */);
|
||||
sm_config_set_sideset_pins(&c, first_sideset_pin->number);
|
||||
}
|
||||
if (jmp_pin != NULL) {
|
||||
@ -336,6 +341,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
||||
uint32_t pull_pin_up, uint32_t pull_pin_down,
|
||||
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,
|
||||
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,
|
||||
bool sideset_enable,
|
||||
const mcu_pin_obj_t *jmp_pin,
|
||||
uint32_t wait_gpio_mask,
|
||||
bool exclusive_pin_use,
|
||||
@ -503,7 +509,8 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
||||
wait_for_txstall,
|
||||
auto_push, push_threshold, in_shift_right,
|
||||
true /* claim pins */,
|
||||
user_interruptible);
|
||||
user_interruptible,
|
||||
sideset_enable);
|
||||
if (!ok) {
|
||||
mp_raise_RuntimeError(translate("All state machines in use"));
|
||||
}
|
||||
@ -513,7 +520,7 @@ void common_hal_rp2pio_statemachine_restart(rp2pio_statemachine_obj_t *self) {
|
||||
common_hal_rp2pio_statemachine_stop(self);
|
||||
// Reset program counter to the original offset. A JMP is 0x0000 plus
|
||||
// the desired offset, so we can just use self->offset.
|
||||
pio_sm_exec(self->pio, self->state_machine,self->offset);
|
||||
pio_sm_exec(self->pio, self->state_machine, self->offset);
|
||||
pio_sm_restart(self->pio, self->state_machine);
|
||||
uint8_t pio_index = pio_get_index(self->pio);
|
||||
uint32_t pins_we_use = _current_sm_pins[pio_index][self->state_machine];
|
||||
|
@ -75,7 +75,8 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
|
||||
bool wait_for_txstall,
|
||||
bool auto_push, uint8_t push_threshold, bool in_shift_right,
|
||||
bool claim_pins,
|
||||
bool interruptible);
|
||||
bool interruptible,
|
||||
bool sideset_enable);
|
||||
|
||||
uint8_t rp2pio_statemachine_program_offset(rp2pio_statemachine_obj_t *self);
|
||||
void rp2pio_statemachine_set_wrap(rp2pio_statemachine_obj_t *self, uint wrap_target, uint wrap);
|
||||
|
Loading…
x
Reference in New Issue
Block a user