@@ -160,7 +160,9 @@ static IRAM_ATTR void _notifyPWM(PWMState *p, bool idle) {
160
160
MEMBARRIER ();
161
161
pwmState.pwmUpdate = p;
162
162
MEMBARRIER ();
163
- forceTimerInterrupt ();
163
+ if (idle) {
164
+ forceTimerInterrupt ();
165
+ }
164
166
while (pwmState.pwmUpdate ) {
165
167
if (idle) {
166
168
esp_yield ();
@@ -313,7 +315,10 @@ static void _addPWMtoList(PWMState& p, uint8_t pin, uint32_t val, uint32_t range
313
315
// Called by analogWrite(1...99%) to set the PWM duty in clock cycles
314
316
extern bool _setPWM_weak (uint8_t pin, uint32_t val, uint32_t range) __attribute__((weak));
315
317
bool _setPWM_weak (uint8_t pin, uint32_t val, uint32_t range) {
316
- stopWaveform (pin);
318
+ const uint32_t mask = 1 <<pin;
319
+ if (wvfState.waveformEnabled & mask) {
320
+ stopWaveform (pin);
321
+ }
317
322
PWMState p; // Working copy
318
323
p = pwmState;
319
324
// Get rid of any entries for this pin
@@ -368,7 +373,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t timeHighCycles, uint32_t
368
373
369
374
_stopPWM (pin); // Make sure there's no PWM live here
370
375
371
- uint32_t mask = 1 <<pin;
376
+ const uint32_t mask = 1 <<pin;
372
377
MEMBARRIER ();
373
378
if (wvfState.waveformEnabled & mask) {
374
379
// Make sure no waveform changes are waiting to be applied
@@ -441,7 +446,7 @@ IRAM_ATTR int stopWaveform_weak(uint8_t pin) {
441
446
442
447
// If user sends in a pin >16 but <32, this will always point to a 0 bit
443
448
// If they send >=32, then the shift will result in 0 and it will also return false
444
- uint32_t mask = 1 <<pin;
449
+ const uint32_t mask = 1 <<pin;
445
450
if (wvfState.waveformEnabled & mask) {
446
451
wvfState.waveformToDisable = mask;
447
452
// Cancel any pending updates for this waveform, too.
@@ -569,7 +574,7 @@ static IRAM_ATTR void timer1Interrupt() {
569
574
}
570
575
571
576
for (auto i = wvfState.startPin ; i <= wvfState.endPin ; i++) {
572
- uint32_t mask = 1 <<i;
577
+ const uint32_t mask = 1 <<i;
573
578
574
579
// If it's not on, ignore!
575
580
if (!(wvfState.waveformEnabled & mask)) {
0 commit comments