33
33
34
34
static std::map<const pio_program_t *, int > __pioMap[PIOCNT];
35
35
static bool __pioAllocated[PIOCNT];
36
- static bool __pioHighGPIO[PIOCNT];
37
36
auto_init_mutex (_pioMutex);
38
37
39
38
PIOProgram::PIOProgram (const pio_program_t *pgm) {
@@ -64,16 +63,16 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
64
63
return ret;
65
64
#endif
66
65
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 );
69
68
70
69
// If it's already loaded into PIO IRAM, try and allocate in that specific PIO
71
70
for (int o = 0 ; o < PIOCNT; o++) {
72
71
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 )) {
74
73
int idx = pio_claim_unused_sm (pi [o], false );
75
74
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 );
77
76
_pio = pi [o];
78
77
_sm = idx;
79
78
*pio = pi [o];
@@ -86,12 +85,12 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
86
85
87
86
// Not in any PIO IRAM, so try and add
88
87
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 )) {
90
89
DEBUGV (" PIOProgram: Checking PIO %p\n " , pi [o]);
91
90
if (pio_can_add_program (pi [o], _pgm)) {
92
91
int idx = pio_claim_unused_sm (pi [o], false );
93
92
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 );
95
94
int off = pio_add_program (pi [o], _pgm);
96
95
__pioMap[o].insert ({_pgm, off});
97
96
_pio = pi [o];
@@ -123,8 +122,7 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
123
122
}
124
123
assert (!__pioAllocated[o]);
125
124
__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 );
128
126
__pioMap[o].insert ({_pgm, off});
129
127
_pio = pi [o];
130
128
_sm = idx;
0 commit comments