9 changed files with 183 additions and 80 deletions
@ -0,0 +1,52 @@ |
|||||||
|
|
||||||
|
#include "RCInput.h" |
||||||
|
|
||||||
|
using namespace AVR_SITL; |
||||||
|
|
||||||
|
extern const AP_HAL::HAL& hal; |
||||||
|
|
||||||
|
void SITLRCInput::init(void* machtnichts) |
||||||
|
{ |
||||||
|
clear_overrides(); |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t SITLRCInput::valid() { |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
uint16_t SITLRCInput::read(uint8_t ch) { |
||||||
|
return _override[ch]? _override[ch] : _sitlState->pwm_input[ch]; |
||||||
|
} |
||||||
|
|
||||||
|
uint8_t SITLRCInput::read(uint16_t* periods, uint8_t len) { |
||||||
|
for (uint8_t i=0; i<len; i++) { |
||||||
|
periods[i] = _override[i]? _override[i] : _sitlState->pwm_input[i]; |
||||||
|
} |
||||||
|
return len; |
||||||
|
} |
||||||
|
|
||||||
|
bool SITLRCInput::set_overrides(int16_t *overrides, uint8_t len) { |
||||||
|
bool res = false; |
||||||
|
for (uint8_t i = 0; i < len; i++) { |
||||||
|
res |= set_override(i, overrides[i]); |
||||||
|
} |
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
bool SITLRCInput::set_override(uint8_t channel, int16_t override) { |
||||||
|
if (override < 0) return false; /* -1: no change. */ |
||||||
|
if (channel < 8) { |
||||||
|
_override[channel] = override; |
||||||
|
if (override != 0) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
void SITLRCInput::clear_overrides() |
||||||
|
{ |
||||||
|
for (uint8_t i = 0; i < 8; i++) { |
||||||
|
_override[i] = 0; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,28 @@ |
|||||||
|
|
||||||
|
#ifndef __AP_HAL_AVR_SITL_RCINPUT_H__ |
||||||
|
#define __AP_HAL_AVR_SITL_RCINPUT_H__ |
||||||
|
|
||||||
|
#include <AP_HAL_AVR_SITL.h> |
||||||
|
|
||||||
|
class AVR_SITL::SITLRCInput : public AP_HAL::RCInput { |
||||||
|
public: |
||||||
|
SITLRCInput(SITL_State *sitlState) { |
||||||
|
_sitlState = sitlState; |
||||||
|
} |
||||||
|
void init(void* machtnichts); |
||||||
|
uint8_t valid(); |
||||||
|
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(); |
||||||
|
private: |
||||||
|
SITL_State *_sitlState; |
||||||
|
|
||||||
|
/* override state */ |
||||||
|
uint16_t _override[8]; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // __AP_HAL_AVR_SITL_RCINPUT_H__
|
||||||
|
|
@ -0,0 +1,45 @@ |
|||||||
|
|
||||||
|
#include "RCOutput.h" |
||||||
|
|
||||||
|
using namespace AVR_SITL; |
||||||
|
|
||||||
|
void SITLRCOutput::init(void* machtnichts) {} |
||||||
|
|
||||||
|
void SITLRCOutput::set_freq(uint32_t chmask, uint16_t freq_hz) { |
||||||
|
_freq_hz = freq_hz; |
||||||
|
} |
||||||
|
|
||||||
|
uint16_t SITLRCOutput::get_freq(uint8_t ch) { |
||||||
|
return _freq_hz; |
||||||
|
} |
||||||
|
|
||||||
|
void SITLRCOutput::enable_ch(uint8_t ch) |
||||||
|
{} |
||||||
|
|
||||||
|
void SITLRCOutput::enable_mask(uint32_t chmask) |
||||||
|
{} |
||||||
|
|
||||||
|
void SITLRCOutput::disable_ch(uint8_t ch) |
||||||
|
{} |
||||||
|
|
||||||
|
void SITLRCOutput::disable_mask(uint32_t chmask) |
||||||
|
{} |
||||||
|
|
||||||
|
void SITLRCOutput::write(uint8_t ch, uint16_t period_us) |
||||||
|
{ |
||||||
|
_sitlState->pwm_output[ch] = period_us; |
||||||
|
} |
||||||
|
|
||||||
|
void SITLRCOutput::write(uint8_t ch, uint16_t* period_us, uint8_t len) |
||||||
|
{ |
||||||
|
memcpy(_sitlState->pwm_output+ch, period_us, len*sizeof(uint16_t)); |
||||||
|
} |
||||||
|
|
||||||
|
uint16_t SITLRCOutput::read(uint8_t ch) { |
||||||
|
return _sitlState->pwm_output[ch]; |
||||||
|
} |
||||||
|
|
||||||
|
void SITLRCOutput::read(uint16_t* period_us, uint8_t len) |
||||||
|
{ |
||||||
|
memcpy(period_us, _sitlState->pwm_output, len*sizeof(uint16_t)); |
||||||
|
} |
@ -0,0 +1,31 @@ |
|||||||
|
|
||||||
|
#ifndef __AP_HAL_AVR_SITL_RCOUTPUT_H__ |
||||||
|
#define __AP_HAL_AVR_SITL_RCOUTPUT_H__ |
||||||
|
|
||||||
|
#include <AP_HAL_AVR_SITL.h> |
||||||
|
|
||||||
|
class AVR_SITL::SITLRCOutput : public AP_HAL::RCOutput { |
||||||
|
public: |
||||||
|
SITLRCOutput(SITL_State *sitlState) { |
||||||
|
_sitlState = sitlState; |
||||||
|
_freq_hz = 50; |
||||||
|
} |
||||||
|
void init(void* machtnichts); |
||||||
|
void set_freq(uint32_t chmask, uint16_t freq_hz); |
||||||
|
uint16_t get_freq(uint8_t ch); |
||||||
|
void enable_ch(uint8_t ch); |
||||||
|
void enable_mask(uint32_t chmask); |
||||||
|
void disable_ch(uint8_t ch); |
||||||
|
void disable_mask(uint32_t chmask); |
||||||
|
void write(uint8_t ch, uint16_t period_us); |
||||||
|
void write(uint8_t ch, uint16_t* period_us, uint8_t len); |
||||||
|
uint16_t read(uint8_t ch); |
||||||
|
void read(uint16_t* period_us, uint8_t len); |
||||||
|
|
||||||
|
private:
|
||||||
|
SITL_State *_sitlState; |
||||||
|
uint16_t _freq_hz; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // __AP_HAL_AVR_SITL_RCOUTPUT_H__
|
||||||
|
|
@ -1,52 +0,0 @@ |
|||||||
/*
|
|
||||||
RC input emulation |
|
||||||
Code by Andrew Tridgell November 2011 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef _SITL_RC_H |
|
||||||
#define _SITL_RC_H |
|
||||||
|
|
||||||
struct RC_ICR4 { |
|
||||||
uint16_t channels[9]; // 9th channel is sync
|
|
||||||
uint32_t value; |
|
||||||
uint8_t idx; |
|
||||||
|
|
||||||
RC_ICR4() { |
|
||||||
// constructor
|
|
||||||
channels[0] = channels[1] = channels[3] = 1500; |
|
||||||
channels[4] = channels[7] = 1800; |
|
||||||
channels[2] = channels[5] = channels[6] = 1000; |
|
||||||
channels[8] = 4500; // sync
|
|
||||||
idx = 0; |
|
||||||
} |
|
||||||
|
|
||||||
/*
|
|
||||||
read from ICR4 fetches next channel |
|
||||||
*/ |
|
||||||
operator int() { |
|
||||||
value += channels[idx++]*2; |
|
||||||
if (idx == 9) { |
|
||||||
idx = 0; |
|
||||||
} |
|
||||||
value = value % 40000; |
|
||||||
return (uint16_t)value; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
ignore rate assignment for now (needed for apm2 |
|
||||||
emulation) |
|
||||||
*/ |
|
||||||
RC_ICR4& operator=(uint16_t rate) { |
|
||||||
return *this; |
|
||||||
} |
|
||||||
|
|
||||||
/*
|
|
||||||
interface to set a channel value from SITL |
|
||||||
*/ |
|
||||||
void set(uint8_t i, uint16_t v) { |
|
||||||
channels[i] = v; |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
Loading…
Reference in new issue