2016-02-17 21:25:26 -04:00
|
|
|
#pragma once
|
2014-09-18 10:29:47 -03:00
|
|
|
|
2016-05-27 09:35:59 -03:00
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_Linux.h"
|
2014-09-18 10:29:47 -03:00
|
|
|
|
2015-09-08 03:39:12 -03:00
|
|
|
#define PCA9685_PRIMARY_ADDRESS 0x40 // All address pins low, PCA9685 default
|
|
|
|
#define PCA9685_SECONDARY_ADDRESS 0x41
|
|
|
|
#define PCA9685_TERTIARY_ADDRESS 0x42
|
2015-11-28 05:38:56 -04:00
|
|
|
#define PCA9685_QUATENARY_ADDRESS 0x55
|
2016-10-17 15:07:01 -03:00
|
|
|
#define PCA9685_QUINARY_ADDRESS 0x61
|
2015-09-08 03:39:12 -03:00
|
|
|
|
2016-07-29 16:14:02 -03:00
|
|
|
namespace Linux {
|
|
|
|
|
|
|
|
class RCOutput_PCA9685 : public AP_HAL::RCOutput {
|
|
|
|
public:
|
2016-05-27 09:35:59 -03:00
|
|
|
RCOutput_PCA9685(AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev,
|
2020-11-17 14:25:14 -04:00
|
|
|
uint32_t external_clock,
|
2016-05-27 09:35:59 -03:00
|
|
|
uint8_t channel_offset,
|
|
|
|
int16_t oe_pin_number);
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
~RCOutput_PCA9685();
|
2019-02-21 19:08:12 -04:00
|
|
|
void init() override;
|
2015-02-26 07:40:24 -04:00
|
|
|
void reset_all_channels();
|
2019-02-21 19:08:12 -04:00
|
|
|
void set_freq(uint32_t chmask, uint16_t freq_hz) override;
|
|
|
|
uint16_t get_freq(uint8_t ch) override;
|
|
|
|
void enable_ch(uint8_t ch) override;
|
|
|
|
void disable_ch(uint8_t ch) override;
|
2021-09-08 13:26:36 -03:00
|
|
|
bool force_safety_on() override;
|
|
|
|
void force_safety_off() override;
|
2019-02-21 19:08:12 -04:00
|
|
|
void write(uint8_t ch, uint16_t period_us) override;
|
2015-09-28 19:39:17 -03:00
|
|
|
void cork() override;
|
|
|
|
void push() override;
|
2019-02-21 19:08:12 -04:00
|
|
|
uint16_t read(uint8_t ch) override;
|
|
|
|
void read(uint16_t* period_us, uint8_t len) override;
|
2014-09-18 10:29:47 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void reset();
|
2015-03-01 16:35:07 -04:00
|
|
|
|
2015-08-25 15:51:00 -03:00
|
|
|
AP_HAL::DigitalSource *_enable_pin;
|
2016-05-27 09:35:59 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
|
2015-02-26 07:53:45 -04:00
|
|
|
uint16_t _frequency;
|
2015-06-12 14:46:01 -03:00
|
|
|
float _osc_clock;
|
2015-03-01 16:35:07 -04:00
|
|
|
|
|
|
|
uint16_t *_pulses_buffer;
|
2015-08-25 16:06:10 -03:00
|
|
|
|
2020-11-17 14:25:14 -04:00
|
|
|
uint32_t _external_clock;
|
2015-09-28 19:39:17 -03:00
|
|
|
bool _corking = false;
|
2015-08-25 16:06:10 -03:00
|
|
|
uint8_t _channel_offset;
|
2015-09-08 03:33:34 -03:00
|
|
|
int16_t _oe_pin_number;
|
2022-05-15 18:30:16 -03:00
|
|
|
uint32_t _pending_write_mask;
|
2014-09-18 10:29:47 -03:00
|
|
|
};
|
2016-07-29 16:14:02 -03:00
|
|
|
|
|
|
|
}
|