@@ -96,7 +96,6 @@ namespace {
9696 // we can avoid looking at the other pins.
9797 int startPin = 0 ;
9898 int endPin = 0 ;
99- int nextPin = 0 ;
10099 uint32_t nextEventCcy;
101100 } waveform;
102101
@@ -284,13 +283,11 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
284283 wave.nextPeriodCcy = waveform.pins [wave.alignPhase ].nextPeriodCcy + wave.nextPeriodCcy ;
285284 if (static_cast <int32_t >(waveform.nextEventCcy - wave.nextPeriodCcy ) > 0 ) {
286285 waveform.nextEventCcy = wave.nextPeriodCcy ;
287- waveform.nextPin = waveform.toSet ;
288286 }
289287 }
290288 else {
291289 wave.nextPeriodCcy = isrStartCcy;
292290 waveform.nextEventCcy = wave.nextPeriodCcy ;
293- waveform.nextPin = waveform.toSet ;
294291 }
295292 if (!wave.expiryCcy ) {
296293 wave.mode = WaveformMode::INFINITE;
@@ -310,31 +307,13 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
310307
311308 // Exit the loop if the next event, if any, is sufficiently distant.
312309 const uint32_t isrTimeoutCcy = isrStartCcy + ISRTIMEOUTCCYS;
313- uint32_t isrNextEventCcy;
314- uint32_t busyPins = waveform.enabled ;
315- if (waveform.enabled ) {
316- if (static_cast <int32_t >(waveform.nextEventCcy - isrTimeoutCcy) >= 0 ) {
317- busyPins = 0 ;
318- }
319- else {
320- isrNextEventCcy = waveform.nextEventCcy ;
321- waveform.nextEventCcy = isrStartCcy + MAXIRQTICKSCCYS;
322- if (!(waveform.enabled & (1UL << waveform.nextPin ))) {
323- waveform.nextPin = waveform.startPin ;
324- }
325- }
326- }
327- else {
310+ uint32_t busyPins = (static_cast <int32_t >(waveform.nextEventCcy - isrTimeoutCcy) < 0 ) ? waveform.enabled : 0 ;
311+ if (!waveform.enabled ) {
328312 waveform.nextEventCcy = isrStartCcy + MAXIRQTICKSCCYS;
329313 }
330314
331- const int stopPin = waveform.nextPin ;
332- int pin = stopPin;
333315 while (busyPins) {
334- while (static_cast <int32_t >(isrNextEventCcy - ESP.getCycleCount ()) > 0 ) {
335- }
336- isrNextEventCcy = isrTimeoutCcy;
337- do {
316+ for (int pin = waveform.startPin ; pin <= waveform.endPin ; ++pin) {
338317 const uint32_t pinBit = 1UL << pin;
339318 // If it's not on, ignore
340319 if (!(busyPins & pinBit))
@@ -415,14 +394,10 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
415394 busyPins ^= pinBit;
416395 if (static_cast <int32_t >(waveform.nextEventCcy - waveNextEventCcy) > 0 ) {
417396 waveform.nextEventCcy = waveNextEventCcy;
418- waveform.nextPin = pin;
419397 }
420398 }
421- else if (static_cast <int32_t >(isrNextEventCcy - waveNextEventCcy) > 0 ) {
422- isrNextEventCcy = waveNextEventCcy;
423- }
424399 }
425- } while ((pin = (pin < waveform. endPin ) ? pin + 1 : waveform. startPin ) != stopPin);
400+ }
426401 }
427402
428403 int32_t callbackCcys = 0 ;
0 commit comments