3333
3434static std::map<const pio_program_t *, int > __pioMap[PIOCNT];
3535static bool __pioAllocated[PIOCNT];
36- static bool __pioHighGPIO[PIOCNT];
3736auto_init_mutex (_pioMutex);
3837
3938PIOProgram::PIOProgram (const pio_program_t *pgm) {
@@ -64,16 +63,16 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
6463 return ret;
6564#endif
6665
67- bool needsHigh = (start + cnt) >= 32 ;
68- DEBUGV (" PIOProgram %p: Searching for high =%d, pins %d-%d\n " , _pgm, needsHigh ? 1 : 0 , start, start + cnt - 1 );
66+ uint gpioBaseNeeded = (( start + cnt) >= 32 ) ? 16 : 0 ;
67+ DEBUGV (" PIOProgram %p: Searching for base =%d, pins %d-%d\n " , _pgm, gpioBaseNeeded , start, start + cnt - 1 );
6968
7069 // If it's already loaded into PIO IRAM, try and allocate in that specific PIO
7170 for (int o = 0 ; o < PIOCNT; o++) {
7271 auto p = __pioMap[o].find (_pgm);
73- if ((p != __pioMap[o].end ()) && (__pioHighGPIO[o] == needsHigh )) {
72+ if ((p != __pioMap[o].end ()) && (pio_get_gpio_base ( pio_get_instance (o)) == gpioBaseNeeded )) {
7473 int idx = pio_claim_unused_sm (pi[o], false );
7574 if (idx >= 0 ) {
76- DEBUGV (" PIOProgram %p: Reusing IMEM ON PIO %p(high =%d) for pins %d-%d\n " , _pgm, pi[o], __pioHighGPIO[o] ? 1 : 0 , start, start + cnt - 1 );
75+ DEBUGV (" PIOProgram %p: Reusing IMEM ON PIO %p(base =%d) for pins %d-%d\n " , _pgm, pi[o], pio_get_gpio_base ( pio_get_instance (o)) , start, start + cnt - 1 );
7776 _pio = pi[o];
7877 _sm = idx;
7978 *pio = pi[o];
@@ -86,12 +85,12 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
8685
8786 // Not in any PIO IRAM, so try and add
8887 for (int o = 0 ; o < PIOCNT; o++) {
89- if (__pioAllocated[o] && (__pioHighGPIO[o] == needsHigh )) {
88+ if (__pioAllocated[o] && (pio_get_gpio_base ( pio_get_instance (o)) == gpioBaseNeeded )) {
9089 DEBUGV (" PIOProgram: Checking PIO %p\n " , pi[o]);
9190 if (pio_can_add_program (pi[o], _pgm)) {
9291 int idx = pio_claim_unused_sm (pi[o], false );
9392 if (idx >= 0 ) {
94- DEBUGV (" PIOProgram %p: Adding IMEM ON PIO %p(high =%d) for pins %d-%d\n " , _pgm, pi[o], __pioHighGPIO[o] ? 1 : 0 , start, start + cnt - 1 );
93+ DEBUGV (" PIOProgram %p: Adding IMEM ON PIO %p(base =%d) for pins %d-%d\n " , _pgm, pi[o], pio_get_gpio_base ( pio_get_instance (o)) , start, start + cnt - 1 );
9594 int off = pio_add_program (pi[o], _pgm);
9695 __pioMap[o].insert ({_pgm, off});
9796 _pio = pi[o];
@@ -123,8 +122,7 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
123122 }
124123 assert (!__pioAllocated[o]);
125124 __pioAllocated[o] = true ;
126- __pioHighGPIO[o] = needsHigh;
127- DEBUGV (" PIOProgram %p: Allocating new PIO %p(high=%d) for pins %d-%d\n " , _pgm, pi[o], __pioHighGPIO[o] ? 1 : 0 , start, start + cnt - 1 );
125+ DEBUGV (" PIOProgram %p: Allocating new PIO %p(base=%d) for pins %d-%d\n " , _pgm, pi[o], pio_get_gpio_base (pio_get_instance (o)), start, start + cnt - 1 );
128126 __pioMap[o].insert ({_pgm, off});
129127 _pio = pi[o];
130128 _sm = idx;
0 commit comments