|
63 | 63 | typedef struct {
|
64 | 64 | uint32_t nextServiceCycle; // ESP cycle timer when a transition required
|
65 | 65 | uint32_t timeLeftCycles; // For time-limited waveform, how many ESP cycles left
|
66 |
| - uint16_t gpioMask; // Mask instead of value to speed IRQ loop |
67 |
| - uint16_t gpio16Mask; // Mask instead of value to speed IRQ loop |
| 66 | + const uint16_t gpioMask; // Mask instead of value to speed IRQ loop |
| 67 | + const uint16_t gpio16Mask; // Mask instead of value to speed IRQ loop |
68 | 68 | unsigned state : 1; // Current state of this pin
|
69 | 69 | unsigned nextTimeHighCycles : 31; // Copy over low->high to keep smooth waveform
|
70 | 70 | unsigned enabled : 1; // Is this GPIO generating a waveform?
|
@@ -204,13 +204,21 @@ int startWaveform(uint8_t pin, uint32_t timeHighUS, uint32_t timeLowUS, uint32_t
|
204 | 204 |
|
205 | 205 | // Stops a waveform on a pin
|
206 | 206 | int stopWaveform(uint8_t pin) {
|
| 207 | + // Can't possibly need to stop anything if there is no timer active |
| 208 | + if (!timerRunning) { |
| 209 | + return false; |
| 210 | + } |
| 211 | + |
207 | 212 | for (size_t i = 0; i < countof(waveform); i++) {
|
208 |
| - if ((((pin == 16) && waveform[i].gpio16Mask) || ((pin != 16) && (waveform[i].gpioMask == 1<<pin))) && waveform[i].enabled) { |
| 213 | + if (!waveform[i].enabled) { |
| 214 | + continue; // Skip fast to next one, can't need to stop this one since it's not running |
| 215 | + } |
| 216 | + if (((pin == 16) && waveform[i].gpio16Mask) || ((pin != 16) && (waveform[i].gpioMask == 1<<pin))) { |
209 | 217 | // Note that there is no interrupt unsafety here. The IRQ can only ever change .enabled from 1->0
|
210 | 218 | // We're also doing that, so even if an IRQ occurred it would still stay as 0.
|
211 | 219 | waveform[i].enabled = 0;
|
212 |
| - int cnt = timer1CB?1:0; |
213 |
| - for (size_t i = 0; i < countof(waveform); i++) { |
| 220 | + int cnt = timer1CB ? 1 : 0; |
| 221 | + for (size_t i = 0; (cnt == 0) && (i < countof(waveform)); i++) { |
214 | 222 | cnt += waveform[i].enabled ? 1 : 0;
|
215 | 223 | }
|
216 | 224 | if (!cnt) {
|
|
0 commit comments