Skip to content

Commit 91864a0

Browse files
authored
fix bug in sm_config_set_in_pin_count (#1880)
* fix bug in sm_config_set_in_pin_count * comment updates
1 parent 2d60604 commit 91864a0

File tree

1 file changed

+15
-2
lines changed
  • src/rp2_common/hardware_pio/include/hardware

1 file changed

+15
-2
lines changed

src/rp2_common/hardware_pio/include/hardware/pio.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,19 @@ static inline void sm_config_set_in_pins(pio_sm_config *c, uint in_base) {
382382
sm_config_set_in_pin_base(c, in_base);
383383
}
384384

385+
/*! \brief Set the count of 'in' pins in a state machine configuration
386+
* \ingroup sm_config
387+
*
388+
* When reading pins using the IN pin mapping, this many (low) bits will be read, with the rest taking
389+
* the value zero.
390+
*
391+
* \if rp2040_specific
392+
* RP2040 does not have the ability to mask unused input pins, so the in_count must be 32
393+
* \endif
394+
*
395+
* \param c Pointer to the configuration structure to modify
396+
* \param in_count 1-32 The number of pins to include when reading via the IN pin mapping
397+
*/
385398
static inline void sm_config_set_in_pin_count(pio_sm_config *c, uint in_count) {
386399
#if PICO_PIO_VERSION == 0
387400
// 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) {
390403
#else
391404
valid_params_if(HARDWARE_PIO, in_count && in_count <= 32);
392405
c->shiftctrl = (c->shiftctrl & ~PIO_SM0_SHIFTCTRL_IN_COUNT_BITS) |
393-
((in_count - 1) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB);
406+
((in_count & 0x1fu) << PIO_SM0_SHIFTCTRL_IN_COUNT_LSB);
394407
#endif
395408
}
396409

@@ -634,7 +647,7 @@ static inline void sm_config_set_mov_status(pio_sm_config *c, enum pio_mov_statu
634647
* --------|--------
635648
* Out Pins | 32 starting at 0
636649
* Set Pins | 0 starting at 0
637-
* In Pins (base) | 0
650+
* In Pins | 32 starting at 0
638651
* Side Set Pins (base) | 0
639652
* Side Set | disabled
640653
* Wrap | wrap=31, wrap_to=0

0 commit comments

Comments
 (0)