2014-09-18 10:29:47 -03:00
|
|
|
|
2015-09-02 11:10:46 -03:00
|
|
|
#ifndef __AP_HAL_LINUX_RCOUTPUT_PCA9685_H__
|
|
|
|
#define __AP_HAL_LINUX_RCOUTPUT_PCA9685_H__
|
2014-09-18 10:29:47 -03:00
|
|
|
|
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-10-20 18:13:25 -03:00
|
|
|
class Linux::RCOutput_PCA9685 : public AP_HAL::RCOutput {
|
2015-03-01 16:35:07 -04:00
|
|
|
public:
|
2015-10-20 18:13:25 -03:00
|
|
|
RCOutput_PCA9685(uint8_t addr, bool external_clock, uint8_t channel_offset,
|
2015-09-08 03:33:34 -03:00
|
|
|
int16_t oe_pin_number);
|
2015-10-20 18:13:25 -03:00
|
|
|
~RCOutput_PCA9685();
|
2014-09-18 10:29:47 -03:00
|
|
|
void init(void* machtnichts);
|
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
|
|
|
|
2014-09-18 10:29:47 -03:00
|
|
|
AP_HAL::Semaphore *_i2c_sem;
|
2015-08-25 15:51:00 -03:00
|
|
|
AP_HAL::DigitalSource *_enable_pin;
|
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-09-08 03:39:12 -03:00
|
|
|
uint8_t _addr;
|
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
|
|
|
};
|
|
|
|
|
2015-09-02 11:10:46 -03:00
|
|
|
#endif // __AP_HAL_LINUX_RCOUTPUT_PCA9685_H__
|