Skip to content

Commit f17ba7f

Browse files
committed
Stopping of the same pin always wins over starting.
1 parent 50ded37 commit f17ba7f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cores/esp8266/core_esp8266_waveform_phase.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ constexpr int32_t DELTAIRQCCYS = ISCPUFREQ160MHZ ?
7878
enum class WaveformMode : uint8_t {INFINITE = 0, EXPIRES = 1, UPDATEEXPIRY = 2, INIT = 3};
7979

8080
// Waveform generator can create tones, PWM, and servos
81-
typedef struct {
81+
struct Waveform {
8282
uint32_t nextPeriodCcy; // ESP clock cycle when a period begins. If WaveformMode::INIT, temporarily holds positive phase offset ccy count
8383
uint32_t endDutyCcy; // ESP clock cycle when going from duty to off
8484
int32_t dutyCcys; // Set next off cycle at low->high to maintain phase
@@ -88,7 +88,7 @@ typedef struct {
8888
WaveformMode mode;
8989
int8_t alignPhase; // < 0 no phase alignment, otherwise starts waveform in relative phase offset to given pin
9090
bool autoPwm; // perform PWM duty to idle cycle ratio correction under high load at the expense of precise timings
91-
} Waveform;
91+
};
9292

9393
namespace {
9494

@@ -116,7 +116,6 @@ static IRAM_ATTR void timer1Interrupt();
116116
// Non-speed critical bits
117117
#pragma GCC optimize ("Os")
118118

119-
static void initTimer() __attribute__((noinline));
120119
static void initTimer() {
121120
timer1_disable();
122121
ETS_FRC_TIMER1_INTR_ATTACH(NULL, NULL);
@@ -126,7 +125,7 @@ static void initTimer() {
126125
timer1_write(IRQLATENCYCCYS); // Cause an interrupt post-haste
127126
}
128127

129-
static void IRAM_ATTR deinitTimer() {
128+
static IRAM_ATTR void deinitTimer() {
130129
ETS_FRC_TIMER1_NMI_INTR_ATTACH(NULL);
131130
timer1_disable();
132131
timer1_isr_init();
@@ -195,7 +194,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t highCcys, uint32_t lowCc
195194
if (!waveform.timer1Running) {
196195
initTimer();
197196
}
198-
// The ISR pulls updates on next PWM interval
197+
// The ISR pulls updates on the next waveform interval
199198
}
200199
else {
201200
wave.mode = WaveformMode::INFINITE; // turn off possible expiry to make update atomic from NMI
@@ -265,7 +264,7 @@ static IRAM_ATTR void timer1Interrupt() {
265264
const bool isCPU2X = CPU2X & 1;
266265
if ((waveform.toSetBits && !(waveform.enabled & waveform.toSetBits)) || waveform.toDisableBits) {
267266
// Handle enable/disable requests from main app.
268-
waveform.enabled = (waveform.enabled & ~waveform.toDisableBits) | waveform.toSetBits; // Set the requested waveforms on/off
267+
waveform.enabled = (waveform.enabled | waveform.toSetBits) & ~waveform.toDisableBits; // Set the requested waveforms on/off
269268
// Find the first GPIO being generated by checking GCC's find-first-set (returns 1 + the bit of the first 1 in an int32_t)
270269
waveform.toDisableBits = 0;
271270
}

0 commit comments

Comments
 (0)