@@ -269,11 +269,13 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
269
269
wave.nextPeriodCcy = waveform.pins [wave.alignPhase ].nextPeriodCcy + wave.nextPeriodCcy ;
270
270
if (static_cast <int32_t >(waveform.nextEventCcy - wave.nextPeriodCcy ) > 0 ) {
271
271
waveform.nextEventCcy = wave.nextPeriodCcy ;
272
+ waveform.nextPin = waveform.toSet ;
272
273
}
273
274
}
274
275
else {
275
- wave.nextPeriodCcy = ESP. getCycleCount () ;
276
+ wave.nextPeriodCcy = isrStartCcy ;
276
277
waveform.nextEventCcy = wave.nextPeriodCcy ;
278
+ waveform.nextPin = waveform.toSet ;
277
279
}
278
280
wave.nextEventCcy = wave.nextPeriodCcy ;
279
281
if (!wave.expiryCcy ) {
@@ -293,23 +295,32 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
293
295
294
296
// Exit the loop if the next event, if any, is sufficiently distant.
295
297
const uint32_t isrTimeoutCcy = isrStartCcy + ISRTIMEOUTCCYS;
298
+ uint32_t isrNextEventCcy;
296
299
uint32_t busyPins = waveform.enabled ;
297
- if (busyPins ) {
300
+ if (waveform. enabled ) {
298
301
if (static_cast <int32_t >(waveform.nextEventCcy - isrTimeoutCcy) >= 0 ) {
299
302
busyPins = 0 ;
300
303
}
301
304
else {
302
- waveform.nextEventCcy = ESP.getCycleCount () + MAXIRQTICKSCCYS;
303
- }
304
- if (!(waveform.enabled & (1UL << waveform.nextPin ))) {
305
- waveform.nextPin = waveform.startPin ;
305
+ isrNextEventCcy = waveform.nextEventCcy ;
306
+ waveform.nextEventCcy = isrStartCcy + MAXIRQTICKSCCYS;
307
+ if (!(waveform.enabled & (1UL << waveform.nextPin ))) {
308
+ waveform.nextPin = waveform.startPin ;
309
+ }
306
310
}
307
311
}
308
- while (busyPins) {
309
- int stopPin = waveform.nextPin ;
310
- int pin = waveform.nextPin ;
311
- uint32_t now = ESP.getCycleCount ();
312
+ else {
313
+ waveform.nextEventCcy = isrStartCcy + MAXIRQTICKSCCYS;
314
+ }
312
315
316
+ const int stopPin = waveform.nextPin ;
317
+ int pin = stopPin;
318
+ while (busyPins) {
319
+ uint32_t now;
320
+ do {
321
+ now = ESP.getCycleCount ();
322
+ } while (static_cast <int32_t >(isrNextEventCcy - now) > 0 );
323
+ isrNextEventCcy = isrTimeoutCcy;
313
324
do {
314
325
// If it's not on, ignore
315
326
if (!(busyPins & (1UL << pin)))
@@ -395,7 +406,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
395
406
waveform.nextPin = pin;
396
407
}
397
408
}
409
+ else if (static_cast <int32_t >(isrNextEventCcy - wave.nextEventCcy ) > 0 ) {
410
+ isrNextEventCcy = wave.nextEventCcy ;
411
+ }
398
412
413
+ now = ESP.getCycleCount ();
399
414
} while ((pin = (pin < waveform.endPin ) ? pin + 1 : waveform.startPin ) != stopPin);
400
415
}
401
416
0 commit comments