2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-05-04 03:15:12 -03:00
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
2012-12-17 23:56:21 -04:00
|
|
|
|
|
|
|
#include "RCOutput.h"
|
2016-01-04 16:19:47 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define ENABLE_DEBUG 0
|
|
|
|
|
|
|
|
#if ENABLE_DEBUG
|
|
|
|
# define Debug(fmt, args ...) do {::printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__, ## args); } while(0)
|
|
|
|
#else
|
|
|
|
# define Debug(fmt, args ...)
|
|
|
|
#endif
|
2012-12-17 23:56:21 -04:00
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
using namespace HALSITL;
|
2012-12-17 23:56:21 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
void RCOutput::init() {}
|
2012-12-17 23:56:21 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
void RCOutput::set_freq(uint32_t chmask, uint16_t freq_hz)
|
2016-01-04 16:19:47 -04:00
|
|
|
{
|
|
|
|
Debug("set_freq(0x%04x, %u)\n", (unsigned)chmask, (unsigned)freq_hz);
|
2012-12-17 23:56:21 -04:00
|
|
|
_freq_hz = freq_hz;
|
|
|
|
}
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
uint16_t RCOutput::get_freq(uint8_t ch)
|
2016-01-04 16:19:47 -04:00
|
|
|
{
|
2012-12-17 23:56:21 -04:00
|
|
|
return _freq_hz;
|
|
|
|
}
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
void RCOutput::enable_ch(uint8_t ch)
|
2016-01-04 16:19:47 -04:00
|
|
|
{
|
|
|
|
if (!(_enable_mask & (1U<<ch))) {
|
|
|
|
Debug("enable_ch(%u)\n", ch);
|
|
|
|
}
|
|
|
|
_enable_mask |= 1U<<ch;
|
|
|
|
}
|
2012-12-17 23:56:21 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
void RCOutput::disable_ch(uint8_t ch)
|
2016-01-04 16:19:47 -04:00
|
|
|
{
|
|
|
|
if (_enable_mask & (1U<<ch)) {
|
|
|
|
Debug("disable_ch(%u)\n", ch);
|
|
|
|
}
|
|
|
|
_enable_mask &= ~1U<<ch;
|
|
|
|
}
|
2012-12-17 23:56:21 -04:00
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
void RCOutput::write(uint8_t ch, uint16_t period_us)
|
2012-12-17 23:56:21 -04:00
|
|
|
{
|
2015-06-29 19:55:02 -03:00
|
|
|
if (ch < SITL_NUM_CHANNELS) {
|
2015-05-04 21:59:07 -03:00
|
|
|
_sitlState->pwm_output[ch] = period_us;
|
2014-11-11 00:15:28 -04:00
|
|
|
}
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
uint16_t RCOutput::read(uint8_t ch)
|
2014-11-11 00:15:28 -04:00
|
|
|
{
|
2015-06-29 19:55:02 -03:00
|
|
|
if (ch < SITL_NUM_CHANNELS) {
|
2015-05-04 21:59:07 -03:00
|
|
|
return _sitlState->pwm_output[ch];
|
2014-11-11 00:15:28 -04:00
|
|
|
}
|
|
|
|
return 0;
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
void RCOutput::read(uint16_t* period_us, uint8_t len)
|
2012-12-17 23:56:21 -04:00
|
|
|
{
|
2015-05-04 21:59:07 -03:00
|
|
|
memcpy(period_us, _sitlState->pwm_output, len*sizeof(uint16_t));
|
2012-12-17 23:56:21 -04:00
|
|
|
}
|
2012-12-18 05:04:47 -04:00
|
|
|
|
|
|
|
#endif
|