mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-29 13:46:37 +00:00
Merge pull request #7851 from s-hadinger/jitter_2
PWM anti-flicker, latest changes from Arduino Core
This commit is contained in:
commit
2f3f06ab0b
@ -170,6 +170,13 @@ static inline ICACHE_RAM_ATTR uint32_t min_u32(uint32_t a, uint32_t b) {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline ICACHE_RAM_ATTR int32_t max_32(int32_t a, int32_t b) {
|
||||||
|
if (a < b) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
// Stops a waveform on a pin
|
// Stops a waveform on a pin
|
||||||
int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) {
|
int ICACHE_RAM_ATTR stopWaveform(uint8_t pin) {
|
||||||
// Can't possibly need to stop anything if there is no timer active
|
// Can't possibly need to stop anything if there is no timer active
|
||||||
@ -261,6 +268,13 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
|
|||||||
// Check for toggles
|
// Check for toggles
|
||||||
int32_t cyclesToGo = wave->nextServiceCycle - now;
|
int32_t cyclesToGo = wave->nextServiceCycle - now;
|
||||||
if (cyclesToGo < 0) {
|
if (cyclesToGo < 0) {
|
||||||
|
// See #7057
|
||||||
|
// The following is a no-op unless we have overshot by an entire waveform cycle.
|
||||||
|
// As modulus is an expensive operation, this code is removed for now:
|
||||||
|
// cyclesToGo = -((-cyclesToGo) % (wave->nextTimeHighCycles + wave->nextTimeLowCycles));
|
||||||
|
//
|
||||||
|
// Alternative version with lower CPU impact:
|
||||||
|
// while (-cyclesToGo > wave->nextTimeHighCycles + wave->nextTimeLowCycles) { cyclesToGo += wave->nextTimeHighCycles + wave->nextTimeLowCycles)};
|
||||||
waveformState ^= mask;
|
waveformState ^= mask;
|
||||||
if (waveformState & mask) {
|
if (waveformState & mask) {
|
||||||
if (i == 16) {
|
if (i == 16) {
|
||||||
@ -268,16 +282,16 @@ static ICACHE_RAM_ATTR void timer1Interrupt() {
|
|||||||
} else {
|
} else {
|
||||||
SetGPIO(mask);
|
SetGPIO(mask);
|
||||||
}
|
}
|
||||||
wave->nextServiceCycle = now + wave->nextTimeHighCycles + cyclesToGo;
|
wave->nextServiceCycle += wave->nextTimeHighCycles;
|
||||||
nextEventCycles = min_u32(nextEventCycles, min_u32(wave->nextTimeHighCycles + cyclesToGo, 1));
|
nextEventCycles = min_u32(nextEventCycles, max_32(wave->nextTimeHighCycles + cyclesToGo, microsecondsToClockCycles(1)));
|
||||||
} else {
|
} else {
|
||||||
if (i == 16) {
|
if (i == 16) {
|
||||||
GP16O &= ~1; // GPIO16 write slow as it's RMW
|
GP16O &= ~1; // GPIO16 write slow as it's RMW
|
||||||
} else {
|
} else {
|
||||||
ClearGPIO(mask);
|
ClearGPIO(mask);
|
||||||
}
|
}
|
||||||
wave->nextServiceCycle = now + wave->nextTimeLowCycles + cyclesToGo;
|
wave->nextServiceCycle += wave->nextTimeLowCycles;
|
||||||
nextEventCycles = min_u32(nextEventCycles, min_u32(wave->nextTimeLowCycles + cyclesToGo, 1));
|
nextEventCycles = min_u32(nextEventCycles, max_32(wave->nextTimeLowCycles + cyclesToGo, microsecondsToClockCycles(1)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint32_t deltaCycles = wave->nextServiceCycle - now;
|
uint32_t deltaCycles = wave->nextServiceCycle - now;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user