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,
|
|
|
|
bool external_clock,
|
|
|
|
uint8_t channel_offset,
|
|
|
|
int16_t oe_pin_number);
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
~RCOutput_PCA9685();
|
2015-12-02 11:14:20 -04:00
|
|
|
void init();
|
2015-02-26 07:40:24 -04:00
|
|
|
void reset_all_channels();
|
2014-09-18 10:29:47 -03:00
|
|
|
void set_freq(uint32_t chmask, uint16_t freq_hz);
|
|
|
|
uint16_t get_freq(uint8_t ch);
|
|
|
|
void enable_ch(uint8_t ch);
|
|
|
|
void disable_ch(uint8_t ch);
|
|
|
|
void write(uint8_t ch, uint16_t period_us);
|
2015-09-28 19:39:17 -03:00
|
|
|
void cork() override;
|
|
|
|
void push() override;
|
2014-09-18 10:29:47 -03:00
|
|
|
uint16_t read(uint8_t ch);
|
|
|
|
void read(uint16_t* period_us, uint8_t len);
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-06-12 14:46:01 -03:00
|
|
|
bool _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;
|
2015-09-28 19:39:17 -03:00
|
|
|
uint16_t _pending_write_mask;
|
2014-09-18 10:29:47 -03:00
|
|
|
};
|
2016-07-29 16:14:02 -03:00
|
|
|
|
|
|
|
}
|