@@ -294,29 +294,26 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
294
294
295
295
// Exit the loop if the next event, if any, is sufficiently distant.
296
296
const uint32_t isrTimeoutCcy = isrStartCcy + ISRTIMEOUTCCYS;
297
- bool busy;
298
- if (!waveform.enabled ) {
299
- busy = false ;
300
- waveform.nextEventCcy = ESP.getCycleCount () + MAXIRQTICKSCCYS;
301
- }
302
- else {
303
- busy = static_cast <int32_t >(isrTimeoutCcy - waveform.nextEventCcy ) > 0 ;
297
+ uint32_t busyPins = waveform.enabled ;
298
+ if (busyPins) {
299
+ if (static_cast <int32_t >(waveform.nextEventCcy - isrTimeoutCcy) >= 0 ) {
300
+ busyPins = 0 ;
301
+ }
302
+ else {
303
+ waveform.nextEventCcy = ESP.getCycleCount () + MAXIRQTICKSCCYS;
304
+ }
304
305
if (!(waveform.enabled & (1UL << waveform.nextPin ))) {
305
306
waveform.nextPin = waveform.startPin ;
306
307
}
307
308
}
308
- while (busy ) {
309
+ while (busyPins ) {
309
310
int stopPin = waveform.nextPin ;
310
311
int pin = waveform.nextPin ;
311
- uint32_t now;
312
- do {
313
- now = ESP.getCycleCount ();
314
- } while (static_cast <int32_t >(waveform.nextEventCcy - now) > 0 );
315
- waveform.nextEventCcy = now + MAXIRQTICKSCCYS;
312
+ uint32_t now = ESP.getCycleCount ();
316
313
317
314
do {
318
315
// If it's not on, ignore
319
- if (!(waveform. enabled & (1UL << pin)))
316
+ if (!(busyPins & (1UL << pin)))
320
317
continue ;
321
318
322
319
Waveform& wave = waveform.pins [pin];
@@ -325,7 +322,8 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
325
322
if (static_cast <int32_t >(overshootCcys) >= 0 ) {
326
323
if (WaveformMode::EXPIRES == wave.mode && wave.nextEventCcy == wave.expiryCcy ) {
327
324
// Disable any waveforms that are done
328
- waveform.enabled ^= 1UL << pin;
325
+ waveform.enabled &= ~(1UL << pin);
326
+ busyPins &= ~(1UL << pin);
329
327
}
330
328
else {
331
329
const uint32_t fwdPeriods = (overshootCcys + wave.dutyCcys ) / wave.periodCcys ;
@@ -408,14 +406,16 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
408
406
}
409
407
}
410
408
411
- // join events below performance threshold apart
412
- if (static_cast <int32_t >(waveform.nextEventCcy - wave.nextEventCcy ) > IRQLATENCYCCYS) {
413
- waveform.nextEventCcy = wave.nextEventCcy ;
414
- waveform.nextPin = pin;
409
+ if (static_cast <int32_t >(wave.nextEventCcy - isrTimeoutCcy) >= 0 ) {
410
+ busyPins &= ~(1UL << pin);
411
+ // join events below performance threshold apart
412
+ if (static_cast <int32_t >(waveform.nextEventCcy - wave.nextEventCcy ) > IRQLATENCYCCYS) {
413
+ waveform.nextEventCcy = wave.nextEventCcy ;
414
+ waveform.nextPin = pin;
415
+ }
415
416
}
416
- } while ((pin = (pin < waveform.endPin ) ? pin + 1 : waveform.startPin , pin != stopPin));
417
417
418
- busy = static_cast < int32_t >(isrTimeoutCcy - waveform.nextEventCcy ) > 0 ;
418
+ } while ((pin = (pin < waveform.endPin ) ? pin + 1 : waveform. startPin ) != stopPin) ;
419
419
}
420
420
421
421
int32_t nextTimerCcys;
0 commit comments