@@ -170,7 +170,8 @@ int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys,
170
170
wave.autoPwm = autoPwm;
171
171
172
172
std::atomic_thread_fence (std::memory_order_acquire);
173
- if (!(waveform.enabled & (1UL << pin))) {
173
+ const uint32_t pinBit = 1UL << pin;
174
+ if (!(waveform.enabled & pinBit)) {
174
175
// wave.nextPeriodCcy and wave.endDutyCcy are initialized by the ISR
175
176
wave.nextPeriodCcy = phaseOffsetCcys;
176
177
wave.expiryCcy = runTimeCcys; // in WaveformMode::INIT, temporarily hold relative cycle count
@@ -182,7 +183,7 @@ int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys,
182
183
GP16O = 0 ;
183
184
}
184
185
else {
185
- GPOC = 1UL << pin ;
186
+ GPOC = pinBit ;
186
187
}
187
188
}
188
189
std::atomic_thread_fence (std::memory_order_release);
@@ -223,7 +224,8 @@ int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) {
223
224
// If user sends in a pin >16 but <32, this will always point to a 0 bit
224
225
// If they send >=32, then the shift will result in 0 and it will also return false
225
226
std::atomic_thread_fence (std::memory_order_acquire);
226
- if (waveform.enabled & (1UL << pin)) {
227
+ const uint32_t pinBit = 1UL << pin;
228
+ if (waveform.enabled & pinBit) {
227
229
waveform.toDisable = pin;
228
230
std::atomic_thread_fence (std::memory_order_release);
229
231
// Must not interfere if Timer is due shortly
@@ -335,8 +337,9 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
335
337
} while (static_cast <int32_t >(isrNextEventCcy - now) > 0 );
336
338
isrNextEventCcy = isrTimeoutCcy;
337
339
do {
340
+ const uint32_t pinBit = 1UL << pin;
338
341
// If it's not on, ignore
339
- if (!(busyPins & ( 1UL << pin) ))
342
+ if (!(busyPins & pinBit ))
340
343
continue ;
341
344
342
345
Waveform& wave = waveform.pins [pin];
@@ -345,13 +348,13 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
345
348
if (WaveformMode::EXPIRES == wave.mode && wave.nextEventCcy == wave.expiryCcy &&
346
349
static_cast <int32_t >(overshootCcys) >= 0 ) {
347
350
// Disable any waveforms that are done
348
- waveform.enabled &= ~( 1UL << pin) ;
349
- busyPins &= ~( 1UL << pin) ;
351
+ waveform.enabled &= ~pinBit ;
352
+ busyPins &= ~pinBit ;
350
353
}
351
354
else {
352
355
if (static_cast <int32_t >(overshootCcys) >= 0 ) {
353
356
uint32_t nextEdgeCcy;
354
- if (waveform.states & ( 1UL << pin) ) {
357
+ if (waveform.states & pinBit ) {
355
358
// active configuration and forward are 100% duty
356
359
if (wave.periodCcys == wave.dutyCcys ) {
357
360
wave.nextPeriodCcy += wave.periodCcys ;
@@ -368,12 +371,12 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
368
371
}
369
372
else {
370
373
nextEdgeCcy = wave.nextPeriodCcy ;
371
- waveform.states &= ~( 1UL << pin) ;
374
+ waveform.states &= ~pinBit ;
372
375
if (16 == pin) {
373
376
GP16O = 0 ;
374
377
}
375
378
else {
376
- GPOC = 1UL << pin ;
379
+ GPOC = pinBit ;
377
380
}
378
381
}
379
382
}
@@ -396,12 +399,12 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
396
399
if (WaveformMode::EXPIRES == wave.mode )
397
400
wave.expiryCcy += adj * wave.periodCcys ;
398
401
}
399
- waveform.states |= 1UL << pin ;
402
+ waveform.states |= pinBit ;
400
403
if (16 == pin) {
401
404
GP16O = 1 ;
402
405
}
403
406
else {
404
- GPOS = 1UL << pin ;
407
+ GPOS = pinBit ;
405
408
}
406
409
}
407
410
nextEdgeCcy = wave.endDutyCcy ;
@@ -413,7 +416,7 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
413
416
}
414
417
415
418
if (static_cast <int32_t >(wave.nextEventCcy - isrTimeoutCcy) >= 0 ) {
416
- busyPins &= ~( 1UL << pin) ;
419
+ busyPins &= ~pinBit ;
417
420
if (static_cast <int32_t >(waveform.nextEventCcy - wave.nextEventCcy ) > 0 ) {
418
421
waveform.nextEventCcy = wave.nextEventCcy ;
419
422
waveform.nextPin = pin;
0 commit comments