@@ -78,7 +78,7 @@ constexpr int32_t DELTAIRQCCYS = ISCPUFREQ160MHZ ?
78
78
enum class WaveformMode : uint8_t {INFINITE = 0 , EXPIRES = 1 , UPDATEEXPIRY = 2 , INIT = 3 };
79
79
80
80
// Waveform generator can create tones, PWM, and servos
81
- typedef struct {
81
+ struct Waveform {
82
82
uint32_t nextPeriodCcy; // ESP clock cycle when a period begins. If WaveformMode::INIT, temporarily holds positive phase offset ccy count
83
83
uint32_t endDutyCcy; // ESP clock cycle when going from duty to off
84
84
int32_t dutyCcys; // Set next off cycle at low->high to maintain phase
@@ -88,7 +88,7 @@ typedef struct {
88
88
WaveformMode mode;
89
89
int8_t alignPhase; // < 0 no phase alignment, otherwise starts waveform in relative phase offset to given pin
90
90
bool autoPwm; // perform PWM duty to idle cycle ratio correction under high load at the expense of precise timings
91
- } Waveform ;
91
+ };
92
92
93
93
namespace {
94
94
@@ -116,7 +116,6 @@ static IRAM_ATTR void timer1Interrupt();
116
116
// Non-speed critical bits
117
117
#pragma GCC optimize ("Os")
118
118
119
- static void initTimer () __attribute__((noinline));
120
119
static void initTimer () {
121
120
timer1_disable ();
122
121
ETS_FRC_TIMER1_INTR_ATTACH (NULL , NULL );
@@ -126,7 +125,7 @@ static void initTimer() {
126
125
timer1_write (IRQLATENCYCCYS); // Cause an interrupt post-haste
127
126
}
128
127
129
- static void IRAM_ATTR deinitTimer () {
128
+ static IRAM_ATTR void deinitTimer () {
130
129
ETS_FRC_TIMER1_NMI_INTR_ATTACH (NULL );
131
130
timer1_disable ();
132
131
timer1_isr_init ();
@@ -195,7 +194,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t highCcys, uint32_t lowCc
195
194
if (!waveform.timer1Running ) {
196
195
initTimer ();
197
196
}
198
- // The ISR pulls updates on next PWM interval
197
+ // The ISR pulls updates on the next waveform interval
199
198
}
200
199
else {
201
200
wave.mode = WaveformMode::INFINITE; // turn off possible expiry to make update atomic from NMI
@@ -265,7 +264,7 @@ static IRAM_ATTR void timer1Interrupt() {
265
264
const bool isCPU2X = CPU2X & 1 ;
266
265
if ((waveform.toSetBits && !(waveform.enabled & waveform.toSetBits )) || waveform.toDisableBits ) {
267
266
// 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
269
268
// 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)
270
269
waveform.toDisableBits = 0 ;
271
270
}
0 commit comments