1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

Resolve "PWM-locked" / "phase-locked" waveform merge leftover in Servo lib (#7978)

Library was overlooked in "PWM-locked" / "phase-locked" waveform mode merge.
This commit is contained in:
Dirk O. Kaar 2021-04-17 22:43:02 +02:00 committed by GitHub
parent 209e467120
commit 41de4115fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 14 deletions

View File

@ -356,7 +356,7 @@ int startWaveformClockCycles_weak(uint8_t pin, uint32_t timeHighCycles, uint32_t
(void) phaseOffsetUS;
(void) autoPwm;
if ((pin > 16) || isFlashInterfacePin(pin)) {
if ((pin > 16) || isFlashInterfacePin(pin) || (timeHighCycles == 0)) {
return false;
}
Waveform *wave = &wvfState.waveform[pin];

View File

@ -69,13 +69,8 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs, int value)
{
if (!_attached) {
#ifdef WAVEFORM_LOCKED_PHASE
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
#else
digitalWrite(pin, LOW);
pinMode(pin, OUTPUT);
#endif
_pin = pin;
_attached = true;
}
@ -95,11 +90,7 @@ void Servo::detach()
{
if (_attached) {
_servoMap &= ~(1 << _pin);
#ifdef WAVEFORM_LOCKED_PHASE
startWaveform(_pin, 0, REFRESH_INTERVAL, 1);
#else
// TODO - timeHigh == 0 is illegal in _PWM code branch. Do nothing for now.
#endif
delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances.
stopWaveform(_pin);
_attached = false;
@ -124,13 +115,9 @@ void Servo::writeMicroseconds(int value)
_valueUs = value;
if (_attached) {
_servoMap &= ~(1 << _pin);
#ifdef WAVEFORM_LOCKED_PHASE
// 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)
int phaseReference = __builtin_ffs(_servoMap) - 1;
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0, phaseReference))
#else
if (startWaveform(_pin, _valueUs, REFRESH_INTERVAL - _valueUs, 0))
#endif
{
_servoMap |= (1 << _pin);
}