Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 17, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions libraries/Servo/src/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -95,11 +90,8 @@ void Servo::detach()
{
if (_attached) {
_servoMap &= ~(1 << _pin);
#ifdef WAVEFORM_LOCKED_PHASE
// TODO - timeHigh == 0 is illegal in _PWM code branch. And now what?
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;
Expand All @@ -124,13 +116,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);
}
Expand Down