From 91864a0d6ee5d4b35b0574e2e385df8d408f3efc Mon Sep 17 00:00:00 2001 From: Graham Sanderson Date: Thu, 29 Aug 2024 11:17:06 -0500 Subject: [PATCH] fix bug in sm_config_set_in_pin_count (#1880) * fix bug in sm_config_set_in_pin_count * comment updates --- .../hardware_pio/include/hardware/pio.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/rp2_common/hardware_pio/include/hardware/pio.h b/src/rp2_common/hardware_pio/include/hardware/pio.h index 83876d6cb..a8cd5b918 100644 --- a/src/rp2_common/hardware_pio/include/hardware/pio.h +++ b/src/rp2_common/hardware_pio/include/hardware/pio.h @@ -382,6 +382,19 @@ static inline void sm_config_set_in_pins(pio_sm_config *c, uint in_base) { sm_config_set_in_pin_base(c, in_base); } +/*! \brief Set the count of 'in' pins in a state machine configuration + * \ingroup sm_config + * + * When reading pins using the IN pin mapping, this many (low) bits will be read, with the rest taking + * the value zero. + * + * \if rp2040_specific + * RP2040 does not have the ability to mask unused input pins, so the in_count must be 32 + * \endif + * + * \param c Pointer to the configuration structure to modify + * \param in_count 1-32 The number of pins to include when reading via the IN pin mapping + */ static inline void sm_config_set_in_pin_count(pio_sm_config *c, uint in_count) { #if PICO_PIO_VERSION == 0 // can't be changed from 32 on PIO v0 @@ -390,7 +403,7 @@ static inline void sm_config_set_in_pin_count(pio_sm_config *c, uint in_count) { #else valid_params_if(HARDWARE_PIO, in_count && in_count <= 32); c->shiftctrl = (c->shiftctrl & ~PIO_SM0_SHIFTCTRL_IN_COUNT_BITS) | - ((in_count - 1) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB); + ((in_count & 0x1fu) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB); #endif } @@ -634,7 +647,7 @@ static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_statu * --------|-------- * Out Pins | 32 starting at 0 * Set Pins | 0 starting at 0 - * In Pins (base) | 0 + * In Pins | 32 starting at 0 * Side Set Pins (base) | 0 * Side Set | disabled * Wrap | wrap=31, wrap_to=0