Skip to content

Commit 7ba80e6

Browse files
committed
stopWaveform in _setPWM caused unconditional _stopPWM.
1 parent d3dec84 commit 7ba80e6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

Diff for: cores/esp8266/core_esp8266_waveform_pwm.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ static IRAM_ATTR void _notifyPWM(PWMState *p, bool idle) {
160160
MEMBARRIER();
161161
pwmState.pwmUpdate = p;
162162
MEMBARRIER();
163-
forceTimerInterrupt();
163+
if (idle) {
164+
forceTimerInterrupt();
165+
}
164166
while (pwmState.pwmUpdate) {
165167
if (idle) {
166168
esp_yield();
@@ -313,7 +315,10 @@ static void _addPWMtoList(PWMState& p, uint8_t pin, uint32_t val, uint32_t range
313315
// Called by analogWrite(1...99%) to set the PWM duty in clock cycles
314316
extern bool _setPWM_weak(uint8_t pin, uint32_t val, uint32_t range) __attribute__((weak));
315317
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+
}
317322
PWMState p; // Working copy
318323
p = pwmState;
319324
// Get rid of any entries for this pin
@@ -368,7 +373,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t timeHighCycles, uint32_t
368373

369374
_stopPWM(pin); // Make sure there's no PWM live here
370375

371-
uint32_t mask = 1<<pin;
376+
const uint32_t mask = 1<<pin;
372377
MEMBARRIER();
373378
if (wvfState.waveformEnabled & mask) {
374379
// Make sure no waveform changes are waiting to be applied
@@ -441,7 +446,7 @@ IRAM_ATTR int stopWaveform_weak(uint8_t pin) {
441446

442447
// If user sends in a pin >16 but <32, this will always point to a 0 bit
443448
// 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;
445450
if (wvfState.waveformEnabled & mask) {
446451
wvfState.waveformToDisable = mask;
447452
// Cancel any pending updates for this waveform, too.
@@ -569,7 +574,7 @@ static IRAM_ATTR void timer1Interrupt() {
569574
}
570575

571576
for (auto i = wvfState.startPin; i <= wvfState.endPin; i++) {
572-
uint32_t mask = 1<<i;
577+
const uint32_t mask = 1<<i;
573578

574579
// If it's not on, ignore!
575580
if (!(wvfState.waveformEnabled & mask)) {

0 commit comments

Comments
 (0)