2013-09-22 03:01:24 -03:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_LINUX_RCINPUT_H__
|
|
|
|
#define __AP_HAL_LINUX_RCINPUT_H__
|
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_Linux.h"
|
2013-09-22 03:01:24 -03:00
|
|
|
|
2014-08-17 23:32:22 -03:00
|
|
|
#define LINUX_RC_INPUT_NUM_CHANNELS 16
|
2014-08-14 13:48:17 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
class Linux::RCInput : public AP_HAL::RCInput {
|
2013-09-22 03:01:24 -03:00
|
|
|
public:
|
2015-10-20 18:13:25 -03:00
|
|
|
RCInput();
|
2015-09-13 15:28:02 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
static RCInput *from(AP_HAL::RCInput *rcinput) {
|
|
|
|
return static_cast<RCInput*>(rcinput);
|
2015-09-13 15:28:02 -03:00
|
|
|
}
|
|
|
|
|
2015-12-02 11:14:20 -04:00
|
|
|
virtual void init();
|
2014-03-25 00:39:41 -03:00
|
|
|
bool new_input();
|
|
|
|
uint8_t num_channels();
|
2013-09-22 03:01:24 -03:00
|
|
|
uint16_t read(uint8_t ch);
|
|
|
|
uint8_t read(uint16_t* periods, uint8_t len);
|
|
|
|
|
|
|
|
bool set_overrides(int16_t *overrides, uint8_t len);
|
|
|
|
bool set_override(uint8_t channel, int16_t override);
|
|
|
|
void clear_overrides();
|
2014-08-17 23:32:22 -03:00
|
|
|
|
2014-08-19 00:37:10 -03:00
|
|
|
// default empty _timer_tick, this is overridden by board
|
|
|
|
// specific implementations
|
|
|
|
virtual void _timer_tick() {}
|
|
|
|
|
|
|
|
protected:
|
2014-10-06 23:24:23 -03:00
|
|
|
void _process_rc_pulse(uint16_t width_s0, uint16_t width_s1);
|
2015-09-04 13:37:09 -03:00
|
|
|
void _update_periods(uint16_t *periods, uint8_t len);
|
2014-08-17 23:32:22 -03:00
|
|
|
|
2014-06-27 07:29:14 -03:00
|
|
|
private:
|
2014-08-17 23:32:22 -03:00
|
|
|
volatile bool new_rc_input;
|
|
|
|
|
2014-10-08 19:19:35 -03:00
|
|
|
uint16_t _pwm_values[LINUX_RC_INPUT_NUM_CHANNELS];
|
|
|
|
uint8_t _num_channels;
|
2014-08-17 23:32:22 -03:00
|
|
|
|
2014-10-06 23:24:23 -03:00
|
|
|
void _process_ppmsum_pulse(uint16_t width);
|
|
|
|
void _process_sbus_pulse(uint16_t width_s0, uint16_t width_s1);
|
2014-10-07 22:49:42 -03:00
|
|
|
void _process_dsm_pulse(uint16_t width_s0, uint16_t width_s1);
|
2014-10-06 23:24:23 -03:00
|
|
|
|
2014-08-19 00:37:10 -03:00
|
|
|
/* override state */
|
|
|
|
uint16_t _override[LINUX_RC_INPUT_NUM_CHANNELS];
|
2014-10-06 23:24:23 -03:00
|
|
|
|
2014-10-08 19:19:35 -03:00
|
|
|
// state of ppm decoder
|
|
|
|
struct {
|
|
|
|
int8_t _channel_counter;
|
|
|
|
uint16_t _pulse_capt[LINUX_RC_INPUT_NUM_CHANNELS];
|
|
|
|
} ppm_state;
|
|
|
|
|
2014-10-06 23:24:23 -03:00
|
|
|
// state of SBUS bit decoder
|
|
|
|
struct {
|
|
|
|
uint16_t bytes[25]; // including start bit, parity and stop bits
|
|
|
|
uint16_t bit_ofs;
|
|
|
|
} sbus_state;
|
2014-10-07 22:49:42 -03:00
|
|
|
|
|
|
|
// state of DSM decoder
|
|
|
|
struct {
|
|
|
|
uint16_t bytes[16]; // including start bit and stop bit
|
|
|
|
uint16_t bit_ofs;
|
|
|
|
} dsm_state;
|
2013-09-22 03:01:24 -03:00
|
|
|
};
|
|
|
|
|
2014-08-19 00:37:10 -03:00
|
|
|
#include "RCInput_PRU.h"
|
2014-11-13 19:16:59 -04:00
|
|
|
#include "RCInput_ZYNQ.h"
|
2014-08-19 00:37:10 -03:00
|
|
|
|
2013-09-22 03:01:24 -03:00
|
|
|
#endif // __AP_HAL_LINUX_RCINPUT_H__
|