2012-08-27 15:44:50 -03:00
|
|
|
|
|
|
|
#ifndef __AP_HAL_AVR_RC_INPUT_H__
|
|
|
|
#define __AP_HAL_AVR_RC_INPUT_H__
|
|
|
|
|
|
|
|
#include <AP_HAL.h>
|
|
|
|
#include "AP_HAL_AVR_Namespace.h"
|
|
|
|
|
2015-01-20 23:13:49 -04:00
|
|
|
#define AVR_RC_INPUT_NUM_CHANNELS 11
|
2013-04-29 02:35:59 -03:00
|
|
|
#define AVR_RC_INPUT_MIN_CHANNELS 5 // for ppm sum we allow less than 8 channels to make up a valid packet
|
2012-08-27 20:45:27 -03:00
|
|
|
|
2015-02-08 02:09:17 -04:00
|
|
|
/*
|
|
|
|
mininum pulse width in microseconds to signal end of a PPM-SUM
|
|
|
|
frame. This value is chosen to be smaller than the default 3000 sync
|
|
|
|
pulse width for OpenLRSng. Note that this is the total pulse with
|
|
|
|
(typically 300us low followed by a long high pulse)
|
|
|
|
*/
|
|
|
|
#define AVR_RC_INPUT_MIN_SYNC_PULSE_WIDTH 2700
|
|
|
|
|
2012-08-27 15:44:50 -03:00
|
|
|
class AP_HAL_AVR::APM1RCInput : public AP_HAL::RCInput {
|
|
|
|
public:
|
2012-12-03 21:47:18 -04:00
|
|
|
/**
|
|
|
|
* init:
|
|
|
|
* HAL_AVR::init should pass in a AP_HAL_AVR::ISRRegistry* as a void*
|
|
|
|
*/
|
2012-08-27 20:45:27 -03:00
|
|
|
void init(void* isrregistry);
|
2012-12-03 21:47:18 -04:00
|
|
|
|
|
|
|
/**
|
2015-02-08 18:56:32 -04:00
|
|
|
* Return true if there has been new input since the last read()
|
|
|
|
* call. This call also clears the new_input flag, so once it
|
|
|
|
* returns true it won't return true again until another frame is
|
|
|
|
* received.
|
2012-12-03 21:47:18 -04:00
|
|
|
*/
|
2014-03-25 00:39:41 -03:00
|
|
|
bool new_input();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the number of input channels in last read()
|
|
|
|
*/
|
|
|
|
uint8_t num_channels();
|
2012-12-03 21:47:18 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* read(uint8_t):
|
|
|
|
* Read a single channel at a time
|
|
|
|
*/
|
2012-08-27 20:45:27 -03:00
|
|
|
uint16_t read(uint8_t ch);
|
2012-12-03 21:47:18 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* read(uint16_t*,uint8_t):
|
|
|
|
* Read an array of channels, return the valid count
|
|
|
|
*/
|
2012-08-27 20:45:27 -03:00
|
|
|
uint8_t read(uint16_t* periods, uint8_t len);
|
2012-12-03 21:47:18 -04:00
|
|
|
|
2012-12-06 16:45:56 -04:00
|
|
|
/**
|
|
|
|
* Overrides: these are really grody and don't belong here but we need
|
|
|
|
* them at the moment to make the port work.
|
|
|
|
* case v of:
|
|
|
|
* v == -1 -> no change to this channel
|
|
|
|
* v == 0 -> do not override this channel
|
|
|
|
* v > 0 -> set v as override.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* set_overrides: array starts at ch 0, for len channels */
|
|
|
|
bool set_overrides(int16_t *overrides, uint8_t len);
|
|
|
|
/* set_override: set just a specific channel */
|
|
|
|
bool set_override(uint8_t channel, int16_t override);
|
|
|
|
/* clear_overrides: equivelant to setting all overrides to 0 */
|
|
|
|
void clear_overrides();
|
|
|
|
|
2012-08-27 15:44:50 -03:00
|
|
|
private:
|
2012-08-27 20:45:27 -03:00
|
|
|
/* private callback for input capture ISR */
|
|
|
|
static void _timer4_capt_cb(void);
|
|
|
|
/* private variables to communicate with input capture isr */
|
|
|
|
static volatile uint16_t _pulse_capt[AVR_RC_INPUT_NUM_CHANNELS];
|
2014-03-25 00:39:41 -03:00
|
|
|
static volatile uint8_t _num_channels;
|
|
|
|
static volatile bool _new_input;
|
2012-12-06 16:45:56 -04:00
|
|
|
|
|
|
|
/* override state */
|
|
|
|
uint16_t _override[AVR_RC_INPUT_NUM_CHANNELS];
|
2012-08-27 15:44:50 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
class AP_HAL_AVR::APM2RCInput : public AP_HAL::RCInput {
|
2012-08-27 20:45:27 -03:00
|
|
|
/* Pass in a AP_HAL_AVR::ISRRegistry* as void*. */
|
|
|
|
void init(void* isrregistry);
|
2014-03-25 00:39:41 -03:00
|
|
|
bool new_input();
|
|
|
|
uint8_t num_channels();
|
2012-08-27 20:45:27 -03:00
|
|
|
uint16_t read(uint8_t ch);
|
|
|
|
uint8_t read(uint16_t* periods, uint8_t len);
|
2012-12-06 16:45:56 -04:00
|
|
|
bool set_overrides(int16_t *overrides, uint8_t len);
|
|
|
|
bool set_override(uint8_t channel, int16_t override);
|
|
|
|
void clear_overrides();
|
2012-08-27 15:44:50 -03:00
|
|
|
private:
|
2012-08-27 20:45:27 -03:00
|
|
|
/* private callback for input capture ISR */
|
|
|
|
static void _timer5_capt_cb(void);
|
|
|
|
/* private variables to communicate with input capture isr */
|
|
|
|
static volatile uint16_t _pulse_capt[AVR_RC_INPUT_NUM_CHANNELS];
|
2014-03-25 00:39:41 -03:00
|
|
|
static volatile uint8_t _num_channels;
|
|
|
|
static volatile bool _new_input;
|
2012-12-06 16:45:56 -04:00
|
|
|
|
|
|
|
/* override state */
|
|
|
|
uint16_t _override[AVR_RC_INPUT_NUM_CHANNELS];
|
2012-08-27 15:44:50 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __AP_HAL_AVR_RC_INPUT_H__
|
|
|
|
|