RCOutput_PC9685: refactor write/write_gpio

This commit is contained in:
Willian Galvani 2022-08-29 11:30:19 -03:00
parent 20be1a6d44
commit 6e14f14e09
2 changed files with 9 additions and 9 deletions

View File

@ -199,13 +199,7 @@ void RCOutput_PCA9685::write(uint8_t ch, uint16_t period_us)
if (_is_gpio_mask & (1U << ch)) { if (_is_gpio_mask & (1U << ch)) {
return; return;
} }
_pulses_buffer[ch] = period_us; write_raw(ch, period_us);
_pending_write_mask |= (1U << ch);
if (!_corking) {
_corking = true;
push();
}
} }
void RCOutput_PCA9685::write_gpio(uint8_t chan, bool active) void RCOutput_PCA9685::write_gpio(uint8_t chan, bool active)
@ -213,8 +207,13 @@ void RCOutput_PCA9685::write_gpio(uint8_t chan, bool active)
if (chan >= (PWM_CHAN_COUNT - _channel_offset)) { if (chan >= (PWM_CHAN_COUNT - _channel_offset)) {
return; return;
} }
_is_relay_mask |= (1U << ch); _is_gpio_mask |= (1U << chan);
_pulses_buffer[ch] = active; write_raw(chan, active);
}
void RCOutput_PCA9685::write_raw(uint8_t ch, uint16_t period_us) {
/* Common code used by both write() and write_gpio() */
_pulses_buffer[ch] = period_us;
_pending_write_mask |= (1U << ch); _pending_write_mask |= (1U << ch);
if (!_corking) { if (!_corking) {

View File

@ -38,6 +38,7 @@ public:
private: private:
void reset(); void reset();
void write_raw(uint8_t ch, uint16_t period_us);
AP_HAL::DigitalSource *_enable_pin; AP_HAL::DigitalSource *_enable_pin;
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev; AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;