mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-29 07:24:13 +01:00
rcvr: convert PWM, PPM, SBUS and Spektrum to use PIOS_RCVR
All receivers now fall under the same driver API provided by pios_rcvr.c. This is part of a larger sequence of commits that will switch the receiver selection over to boot time dynamic configuration via UAVObjects.
This commit is contained in:
parent
e77795dc28
commit
740b5f1584
@ -211,6 +211,7 @@ SRC += $(PIOSCOMMON)/pios_com.c
|
||||
SRC += $(PIOSCOMMON)/pios_i2c_esc.c
|
||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
SRC += $(PIOSCOMMON)/pios_rcvr.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
## Libraries for flight calculations
|
||||
SRC += $(FLIGHTLIB)/fifo_buffer.c
|
||||
|
@ -43,6 +43,8 @@
|
||||
#define PIOS_INCLUDE_IRQ
|
||||
#define PIOS_INCLUDE_LED
|
||||
|
||||
#define PIOS_INCLUDE_RCVR
|
||||
|
||||
/* Receiver interfaces - only one allowed */
|
||||
#if !defined(USE_SPEKTRUM) && !defined(USE_SBUS)
|
||||
//#define PIOS_INCLUDE_PPM
|
||||
|
@ -469,13 +469,13 @@ const struct pios_usart_cfg pios_usart_spektrum_cfg = {
|
||||
},
|
||||
};
|
||||
|
||||
#include <pios_spektrum_priv.h>
|
||||
static uint32_t pios_usart_spektrum_id;
|
||||
void PIOS_USART_spektrum_irq_handler(void)
|
||||
{
|
||||
SPEKTRUM_IRQHandler(pios_usart_spektrum_id);
|
||||
PIOS_SPEKTRUM_irq_handler(pios_usart_spektrum_id);
|
||||
}
|
||||
|
||||
#include <pios_spektrum_priv.h>
|
||||
void RTC_IRQHandler();
|
||||
void RTC_IRQHandler() __attribute__ ((alias ("PIOS_SUPV_irq_handler")));
|
||||
const struct pios_spektrum_cfg pios_spektrum_cfg = {
|
||||
@ -501,7 +501,7 @@ void PIOS_SUPV_irq_handler() {
|
||||
if (RTC_GetITStatus(RTC_IT_SEC))
|
||||
{
|
||||
/* Call the right handler */
|
||||
PIOS_SPEKTRUM_irq_handler(pios_usart_spektrum_id);
|
||||
PIOS_SPEKTRUMSV_irq_handler(pios_usart_spektrum_id);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
@ -561,7 +561,7 @@ const struct pios_usart_cfg pios_usart_sbus_cfg = {
|
||||
static uint32_t pios_usart_sbus_id;
|
||||
void PIOS_USART_sbus_irq_handler(void)
|
||||
{
|
||||
SBUS_IRQHandler(pios_usart_sbus_id);
|
||||
PIOS_SBUS_irq_handler(pios_usart_sbus_id);
|
||||
}
|
||||
|
||||
#include <pios_sbus_priv.h>
|
||||
@ -587,7 +587,7 @@ void PIOS_SUPV_irq_handler() {
|
||||
if (RTC_GetITStatus(RTC_IT_SEC))
|
||||
{
|
||||
/* Call the right handler */
|
||||
PIOS_SBUS_irq_handler(pios_usart_sbus_id);
|
||||
PIOS_SBUSSV_irq_handler(pios_usart_sbus_id);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
@ -869,6 +869,13 @@ void PIOS_I2C_main_adapter_er_irq_handler(void)
|
||||
|
||||
#endif /* PIOS_INCLUDE_I2C */
|
||||
|
||||
#if defined(PIOS_INCLUDE_RCVR)
|
||||
#include "pios_rcvr_priv.h"
|
||||
|
||||
uint32_t pios_rcvr_channel_to_id_map[PIOS_RCVR_MAX_DEVS];
|
||||
uint32_t pios_rcvr_max_channel;
|
||||
#endif /* PIOS_INCLUDE_RCVR */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
|
||||
uint32_t pios_com_telem_rf_id;
|
||||
@ -897,18 +904,6 @@ void PIOS_Board_Init(void) {
|
||||
|
||||
PIOS_FLASHFS_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
/* SPEKTRUM init must come before comms */
|
||||
PIOS_SPEKTRUM_Init();
|
||||
|
||||
if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_spektrum_id, &pios_usart_com_driver, pios_usart_spektrum_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Initialize UAVObject libraries */
|
||||
EventDispatcherInitialize();
|
||||
UAVObjInitialize();
|
||||
@ -938,6 +933,26 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_GPS */
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
/* SPEKTRUM init must come before comms */
|
||||
PIOS_SPEKTRUM_Init();
|
||||
|
||||
if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_spektrum_id, &pios_usart_com_driver, pios_usart_spektrum_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
for (uint8_t i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_spektrum_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_SBUS)
|
||||
PIOS_SBUS_Init();
|
||||
|
||||
@ -947,6 +962,16 @@ void PIOS_Board_Init(void) {
|
||||
if (PIOS_COM_Init(&pios_com_sbus_id, &pios_usart_com_driver, pios_usart_sbus_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
for (uint8_t i = 0; i < SBUS_NUMBER_OF_CHANNELS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_sbus_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PIOS_INCLUDE_SBUS */
|
||||
#endif /* PIOS_INCLUDE_COM */
|
||||
|
||||
@ -958,10 +983,34 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
#if (PIOS_PWM_NUM_INPUTS > PIOS_RCVR_MAX_DEVS)
|
||||
#error More receiver inputs than available devices
|
||||
#endif
|
||||
PIOS_PWM_Init();
|
||||
for (uint8_t i = 0; i < PIOS_PWM_NUM_INPUTS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_pwm_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_PPM)
|
||||
#if (PIOS_PPM_NUM_INPUTS > PIOS_RCVR_MAX_DEVS)
|
||||
#error More receiver inputs than available devices
|
||||
#endif
|
||||
PIOS_PPM_Init();
|
||||
for (uint8_t i = 0; i < PIOS_PPM_NUM_INPUTS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_ppm_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
PIOS_USB_HID_Init(0);
|
||||
|
@ -209,19 +209,12 @@ static void manualControlTask(void *parameters)
|
||||
if (!ManualControlCommandReadOnly(&cmd)) {
|
||||
|
||||
// Read channel values in us
|
||||
// TODO: settings.InputMode is currently ignored because PIOS will not allow runtime
|
||||
// selection of PWM and PPM. The configuration is currently done at compile time in
|
||||
// the pios_config.h file.
|
||||
for (int n = 0; n < MANUALCONTROLCOMMAND_CHANNEL_NUMELEM; ++n) {
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
cmd.Channel[n] = PIOS_PWM_Get(n);
|
||||
#elif defined(PIOS_INCLUDE_PPM)
|
||||
cmd.Channel[n] = PIOS_PPM_Get(n);
|
||||
#elif defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
cmd.Channel[n] = PIOS_SPEKTRUM_Get(n);
|
||||
#elif defined(PIOS_INCLUDE_SBUS)
|
||||
cmd.Channel[n] = PIOS_SBUS_Get(n);
|
||||
#endif
|
||||
if (pios_rcvr_channel_to_id_map[n]) {
|
||||
cmd.Channel[n] = PIOS_RCVR_Read(pios_rcvr_channel_to_id_map[n]);
|
||||
} else {
|
||||
cmd.Channel[n] = -1;
|
||||
}
|
||||
scaledChannel[n] = scaleChannel(cmd.Channel[n], settings.ChannelMax[n], settings.ChannelMin[n], settings.ChannelNeutral[n]);
|
||||
}
|
||||
|
||||
|
@ -196,6 +196,7 @@ SRC += $(PIOSCOMMON)/pios_hcsr04.c
|
||||
SRC += $(PIOSCOMMON)/pios_i2c_esc.c
|
||||
SRC += $(PIOSCOMMON)/pios_iap.c
|
||||
SRC += $(PIOSCOMMON)/pios_bl_helper.c
|
||||
SRC += $(PIOSCOMMON)/pios_rcvr.c
|
||||
SRC += $(PIOSCOMMON)/printf-stdarg.c
|
||||
SRC += $(FLIGHTLIB)/ahrs_spi_comm.c
|
||||
SRC += $(FLIGHTLIB)/ahrs_comm_objects.c
|
||||
|
@ -42,6 +42,8 @@
|
||||
#define PIOS_INCLUDE_IRQ
|
||||
#define PIOS_INCLUDE_LED
|
||||
|
||||
#define PIOS_INCLUDE_RCVR
|
||||
|
||||
#if defined(USE_SPEKTRUM)
|
||||
#define PIOS_INCLUDE_SPEKTRUM
|
||||
#elif defined(USE_SBUS)
|
||||
|
@ -497,13 +497,13 @@ const struct pios_usart_cfg pios_usart_spektrum_cfg = {
|
||||
},
|
||||
};
|
||||
|
||||
#include <pios_spektrum_priv.h>
|
||||
static uint32_t pios_usart_spektrum_id;
|
||||
void PIOS_USART_spektrum_irq_handler(void)
|
||||
{
|
||||
SPEKTRUM_IRQHandler(pios_usart_spektrum_id);
|
||||
PIOS_SPEKTRUM_irq_handler(pios_usart_spektrum_id);
|
||||
}
|
||||
|
||||
#include <pios_spektrum_priv.h>
|
||||
void RTC_IRQHandler();
|
||||
void RTC_IRQHandler() __attribute__ ((alias ("PIOS_SUPV_irq_handler")));
|
||||
const struct pios_spektrum_cfg pios_spektrum_cfg = {
|
||||
@ -525,11 +525,11 @@ const struct pios_spektrum_cfg pios_spektrum_cfg = {
|
||||
.pin = GPIO_Pin_10,
|
||||
};
|
||||
|
||||
void PIOS_SUPV_irq_handler() {
|
||||
void PIOS_SUPV_irq_handler(void) {
|
||||
if (RTC_GetITStatus(RTC_IT_SEC))
|
||||
{
|
||||
/* Call the right handler */
|
||||
PIOS_SPEKTRUM_irq_handler(pios_usart_spektrum_id);
|
||||
PIOS_SPEKTRUMSV_irq_handler(pios_usart_spektrum_id);
|
||||
|
||||
/* Wait until last write operation on RTC registers has finished */
|
||||
RTC_WaitForLastTask();
|
||||
@ -802,7 +802,7 @@ const struct pios_ppmsv_cfg pios_ppmsv_cfg = {
|
||||
.ccr = TIM_IT_Update,
|
||||
};
|
||||
|
||||
void PIOS_TIM6_irq_handler()
|
||||
void PIOS_TIM6_irq_handler(void)
|
||||
{
|
||||
PIOS_PPMSV_irq_handler();
|
||||
}
|
||||
@ -844,7 +844,7 @@ const struct pios_ppm_cfg pios_ppm_cfg = {
|
||||
.ccr = TIM_IT_CC2,
|
||||
};
|
||||
|
||||
void PIOS_TIM1_CC_irq_handler()
|
||||
void PIOS_TIM1_CC_irq_handler(void)
|
||||
{
|
||||
PIOS_PPM_irq_handler();
|
||||
}
|
||||
@ -1013,6 +1013,13 @@ static const struct stm32_gpio pios_debug_pins[] = {
|
||||
|
||||
#endif /* PIOS_ENABLE_DEBUG_PINS */
|
||||
|
||||
#if defined(PIOS_INCLUDE_RCVR)
|
||||
#include "pios_rcvr_priv.h"
|
||||
|
||||
uint32_t pios_rcvr_channel_to_id_map[PIOS_RCVR_MAX_DEVS];
|
||||
uint32_t pios_rcvr_max_channel;
|
||||
#endif /* PIOS_INCLUDE_RCVR */
|
||||
|
||||
extern const struct pios_com_driver pios_usb_com_driver;
|
||||
|
||||
uint32_t pios_com_telem_rf_id;
|
||||
@ -1050,18 +1057,6 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_SDCARD_MountFS(0);
|
||||
#endif /* PIOS_INCLUDE_SPI */
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
/* SPEKTRUM init must come before comms */
|
||||
PIOS_RTC_Init(); // Spektrum uses RTC to check for frame failures
|
||||
PIOS_SPEKTRUM_Init();
|
||||
|
||||
if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_spektrum_id, &pios_usart_com_driver, pios_usart_spektrum_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
#endif
|
||||
/* Initialize UAVObject libraries */
|
||||
EventDispatcherInitialize();
|
||||
UAVObjInitialize();
|
||||
@ -1105,11 +1100,59 @@ void PIOS_Board_Init(void) {
|
||||
PIOS_ADC_Init();
|
||||
PIOS_GPIO_Init();
|
||||
|
||||
#if defined(PIOS_INCLUDE_SPEKTRUM)
|
||||
#if (PIOS_SPEKTRUM_NUM_INPUTS > PIOS_RCVR_MAX_DEVS)
|
||||
#error More receiver inputs than available devices
|
||||
#endif
|
||||
/* SPEKTRUM init must come before comms */
|
||||
PIOS_SPEKTRUM_Init();
|
||||
|
||||
if (PIOS_USART_Init(&pios_usart_spektrum_id, &pios_usart_spektrum_cfg)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
if (PIOS_COM_Init(&pios_com_spektrum_id, &pios_usart_com_driver, pios_usart_spektrum_id)) {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
for (uint8_t i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_spektrum_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
#if (PIOS_PWM_NUM_INPUTS > PIOS_RCVR_MAX_DEVS)
|
||||
#error More receiver inputs than available devices
|
||||
#endif
|
||||
PIOS_PWM_Init();
|
||||
for (uint8_t i = 0; i < PIOS_PWM_NUM_INPUTS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_pwm_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_PPM)
|
||||
#if (PIOS_PPM_NUM_INPUTS > PIOS_RCVR_MAX_DEVS)
|
||||
#error More receiver inputs than available devices
|
||||
#endif
|
||||
PIOS_PPM_Init();
|
||||
for (uint8_t i = 0; i < PIOS_PPM_NUM_INPUTS; i++) {
|
||||
if (!PIOS_RCVR_Init(&pios_rcvr_channel_to_id_map[pios_rcvr_max_channel],
|
||||
&pios_ppm_rcvr_driver,
|
||||
i)) {
|
||||
pios_rcvr_max_channel++;
|
||||
} else {
|
||||
PIOS_DEBUG_Assert(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_USB_HID)
|
||||
PIOS_USB_HID_Init(0);
|
||||
|
@ -225,10 +225,27 @@ extern uint32_t pios_com_sbus_id;
|
||||
#define PIOS_ADC_RATE (72.0e6 / 1.0 / 8.0 / 252.0 / (PIOS_ADC_NUM_CHANNELS >> PIOS_ADC_USE_ADC2))
|
||||
#define PIOS_ADC_MAX_OVERSAMPLING 36
|
||||
|
||||
//------------------------
|
||||
// PIOS_RCVR
|
||||
// See also pios_board.c
|
||||
//------------------------
|
||||
#define PIOS_RCVR_MAX_DEVS 12
|
||||
|
||||
//-------------------------
|
||||
// Receiver PWM inputs
|
||||
// Receiver PPM input
|
||||
//-------------------------
|
||||
#define PIOS_PWM_MAX_INPUTS 6
|
||||
#define PIOS_PPM_NUM_INPUTS 6 //Could be more if needed
|
||||
#define PIOS_PPM_SUPV_ENABLED 1
|
||||
|
||||
//-------------------------
|
||||
// Receiver PWM input
|
||||
//-------------------------
|
||||
#define PIOS_PWM_NUM_INPUTS 6
|
||||
|
||||
//-------------------------
|
||||
// Receiver SPEKTRUM input
|
||||
//-------------------------
|
||||
#define PIOS_SPEKTRUM_NUM_INPUTS 12
|
||||
|
||||
//-------------------------
|
||||
// Servo outputs
|
||||
|
@ -199,37 +199,33 @@ extern uint32_t pios_com_sbus_id;
|
||||
#define PIOS_IRQ_PRIO_HIGH 5 // for SPI, ADC, I2C etc...
|
||||
#define PIOS_IRQ_PRIO_HIGHEST 4 // for USART etc...
|
||||
|
||||
//-------------------------
|
||||
// Receiver PWM inputs
|
||||
//-------------------------
|
||||
/*#define PIOS_PWM_SUPV_ENABLED 1
|
||||
#define PIOS_PWM_SUPV_TIMER TIM6
|
||||
#define PIOS_PWM_SUPV_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE)
|
||||
#define PIOS_PWM_SUPV_HZ 25
|
||||
#define PIOS_PWM_SUPV_IRQ_CHANNEL TIM6_IRQn
|
||||
#define PIOS_PWM_SUPV_IRQ_FUNC void TIM6_IRQHandler(void)*/
|
||||
//------------------------
|
||||
// PIOS_RCVR
|
||||
// See also pios_board.c
|
||||
//------------------------
|
||||
#define PIOS_RCVR_MAX_DEVS 12
|
||||
|
||||
//-------------------------
|
||||
// Receiver PPM input
|
||||
//-------------------------
|
||||
#define PIOS_PPM_NUM_INPUTS 8 //Could be more if needed
|
||||
#define PIOS_PPM_SUPV_ENABLED 1
|
||||
|
||||
//-------------------------
|
||||
// SPEKTRUM input
|
||||
// Receiver PWM input
|
||||
//-------------------------
|
||||
//#define PIOS_SPEKTRUM_SUPV_ENABLED 1
|
||||
//#define PIOS_SPEKTRUM_SUPV_TIMER TIM6
|
||||
//#define PIOS_SPEKTRUM_SUPV_TIMER_RCC_FUNC RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE)
|
||||
//#define PIOS_SPEKTRUM_SUPV_HZ 60 // 1/22ms
|
||||
//#define PIOS_SPEKTRUM_SUPV_IRQ_CHANNEL TIM6_IRQn
|
||||
//#define PIOS_SPEKTRUM_SUPV_IRQ_FUNC void TIM6_IRQHandler(void)
|
||||
#define PIOS_PWM_NUM_INPUTS 8
|
||||
|
||||
//-------------------------
|
||||
// Receiver SPEKTRUM input
|
||||
//-------------------------
|
||||
#define PIOS_SPEKTRUM_NUM_INPUTS 12
|
||||
|
||||
//-------------------------
|
||||
// Servo outputs
|
||||
//-------------------------
|
||||
#define PIOS_SERVO_UPDATE_HZ 50
|
||||
#define PIOS_SERVOS_INITIAL_POSITION 0 /* dont want to start motors, have no pulse till settings loaded */
|
||||
#define PIOS_PWM_MAX_INPUTS 8
|
||||
|
||||
//-------------------------
|
||||
// ADC
|
||||
|
@ -34,8 +34,14 @@
|
||||
|
||||
#if defined(PIOS_INCLUDE_PPM)
|
||||
|
||||
/* Local Variables */
|
||||
/* Provide a RCVR driver */
|
||||
static int32_t PIOS_PPM_Get(uint32_t chan_id);
|
||||
|
||||
const struct pios_rcvr_driver pios_ppm_rcvr_driver = {
|
||||
.read = PIOS_PPM_Get,
|
||||
};
|
||||
|
||||
/* Local Variables */
|
||||
static TIM_ICInitTypeDef TIM_ICInitStructure;
|
||||
static uint8_t PulseIndex;
|
||||
static uint32_t PreviousValue;
|
||||
@ -208,13 +214,13 @@ void PIOS_PPM_Init(void)
|
||||
* \output -1 Channel not available
|
||||
* \output >0 Channel value
|
||||
*/
|
||||
int32_t PIOS_PPM_Get(int8_t Channel)
|
||||
static int32_t PIOS_PPM_Get(uint32_t chan_id)
|
||||
{
|
||||
/* Return error if channel not available */
|
||||
if (Channel >= PIOS_PPM_NUM_INPUTS) {
|
||||
if (chan_id >= PIOS_PPM_NUM_INPUTS) {
|
||||
return -1;
|
||||
}
|
||||
return CaptureValue[Channel];
|
||||
return CaptureValue[chan_id];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -34,15 +34,20 @@
|
||||
|
||||
#if defined(PIOS_INCLUDE_PWM)
|
||||
|
||||
/* Local Variables */
|
||||
static uint8_t CaptureState[PIOS_PWM_MAX_INPUTS];
|
||||
static uint16_t RiseValue[PIOS_PWM_MAX_INPUTS];
|
||||
static uint16_t FallValue[PIOS_PWM_MAX_INPUTS];
|
||||
static uint32_t CaptureValue[PIOS_PWM_MAX_INPUTS];
|
||||
/* Provide a RCVR driver */
|
||||
static int32_t PIOS_PWM_Get(uint32_t chan_id);
|
||||
|
||||
//static uint8_t SupervisorState = 0;
|
||||
static uint32_t CapCounter[PIOS_PWM_MAX_INPUTS];
|
||||
//static uint32_t CapCounterPrev[MAX_CHANNELS];
|
||||
const struct pios_rcvr_driver pios_pwm_rcvr_driver = {
|
||||
.read = PIOS_PWM_Get,
|
||||
};
|
||||
|
||||
/* Local Variables */
|
||||
static uint8_t CaptureState[PIOS_PWM_NUM_INPUTS];
|
||||
static uint16_t RiseValue[PIOS_PWM_NUM_INPUTS];
|
||||
static uint16_t FallValue[PIOS_PWM_NUM_INPUTS];
|
||||
static uint32_t CaptureValue[PIOS_PWM_NUM_INPUTS];
|
||||
|
||||
static uint32_t CapCounter[PIOS_PWM_NUM_INPUTS];
|
||||
|
||||
/**
|
||||
* Initialises all the pins
|
||||
@ -127,52 +132,6 @@ void PIOS_PWM_Init(void)
|
||||
/* Warning, I don't think this will work for multiple remaps at once */
|
||||
GPIO_PinRemapConfig(pios_pwm_cfg.remap, ENABLE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Supervisor Setup */
|
||||
#if (PIOS_PWM_SUPV_ENABLED)
|
||||
/* Flush counter variables */
|
||||
for (i = 0; i < PIOS_PWM_NUM_INPUTS; i++) {
|
||||
CapCounter[i] = 0;
|
||||
}
|
||||
for (i = 0; i < PIOS_PWM_NUM_INPUTS; i++) {
|
||||
CapCounterPrev[i] = 0;
|
||||
}
|
||||
|
||||
/* Enable timer clock */
|
||||
PIOS_PWM_SUPV_TIMER_RCC_FUNC;
|
||||
|
||||
/* Configure interrupts */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = PIOS_PWM_SUPV_IRQ_CHANNEL;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
|
||||
/* Time base configuration */
|
||||
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
|
||||
TIM_TimeBaseStructure.TIM_Period = ((1000000 / PIOS_PWM_SUPV_HZ) - 1);
|
||||
TIM_TimeBaseStructure.TIM_Prescaler = (PIOS_MASTER_CLOCK / 1000000) - 1; /* For 1 uS accuracy */
|
||||
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
|
||||
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
||||
TIM_TimeBaseInit(PIOS_PWM_SUPV_TIMER, &TIM_TimeBaseStructure);
|
||||
|
||||
/* Enable the CC2 Interrupt Request */
|
||||
TIM_ITConfig(PIOS_PWM_SUPV_TIMER, TIM_IT_Update, ENABLE);
|
||||
|
||||
/* Clear update pending flag */
|
||||
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
|
||||
|
||||
/* Enable counter */
|
||||
TIM_Cmd(PIOS_PWM_SUPV_TIMER, ENABLE);
|
||||
#endif
|
||||
|
||||
/* Setup local variable which stays in this scope */
|
||||
/* Doing this here and using a local variable saves doing it in the ISR */
|
||||
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
||||
TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
|
||||
TIM_ICInitStructure.TIM_ICFilter = 0x0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,13 +140,13 @@ void PIOS_PWM_Init(void)
|
||||
* \output -1 Channel not available
|
||||
* \output >0 Channel value
|
||||
*/
|
||||
int32_t PIOS_PWM_Get(int8_t Channel)
|
||||
static int32_t PIOS_PWM_Get(uint32_t chan_id)
|
||||
{
|
||||
/* Return error if channel not available */
|
||||
if (Channel >= pios_pwm_cfg.num_channels) {
|
||||
if (chan_id >= pios_pwm_cfg.num_channels) {
|
||||
return -1;
|
||||
}
|
||||
return CaptureValue[Channel];
|
||||
return CaptureValue[chan_id];
|
||||
}
|
||||
|
||||
void PIOS_PWM_irq_handler(TIM_TypeDef * timer)
|
||||
@ -254,84 +213,6 @@ void PIOS_PWM_irq_handler(TIM_TypeDef * timer)
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Handle TIM5 global interrupt request
|
||||
*/
|
||||
void TIM5_IRQHandler(void)
|
||||
{
|
||||
/* Do this as it's more efficient */
|
||||
if (TIM_GetITStatus(PIOS_PWM_TIM_PORT[2], PIOS_PWM_TIM_CCR[2]) == SET) {
|
||||
if (CaptureState[2] == 0) {
|
||||
RiseValue[2] = TIM_GetCapture1(PIOS_PWM_TIM_PORT[2]);
|
||||
} else {
|
||||
FallValue[2] = TIM_GetCapture1(PIOS_PWM_TIM_PORT[2]);
|
||||
}
|
||||
|
||||
/* Clear TIM3 Capture compare interrupt pending bit */
|
||||
TIM_ClearITPendingBit(PIOS_PWM_TIM_PORT[2], PIOS_PWM_TIM_CCR[2]);
|
||||
|
||||
/* Simple rise or fall state machine */
|
||||
if (CaptureState[2] == 0) {
|
||||
/* Switch states */
|
||||
CaptureState[2] = 1;
|
||||
|
||||
/* Switch polarity of input capture */
|
||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling;
|
||||
TIM_ICInitStructure.TIM_Channel = PIOS_PWM_TIM_CHANNEL[2];
|
||||
TIM_ICInit(PIOS_PWM_TIM_PORT[2], &TIM_ICInitStructure);
|
||||
|
||||
} else {
|
||||
/* Capture computation */
|
||||
if (FallValue[2] > RiseValue[2]) {
|
||||
CaptureValue[2] = (FallValue[2] - RiseValue[2]);
|
||||
} else {
|
||||
CaptureValue[2] = ((0xFFFF - RiseValue[2]) + FallValue[2]);
|
||||
}
|
||||
|
||||
/* Switch states */
|
||||
CaptureState[2] = 0;
|
||||
|
||||
/* Increase supervisor counter */
|
||||
CapCounter[2]++;
|
||||
|
||||
/* Switch polarity of input capture */
|
||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
||||
TIM_ICInitStructure.TIM_Channel = PIOS_PWM_TIM_CHANNEL[2];
|
||||
TIM_ICInit(PIOS_PWM_TIM_PORT[2], &TIM_ICInitStructure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function handles TIM3 global interrupt request.
|
||||
*/
|
||||
PIOS_PWM_SUPV_IRQ_FUNC {
|
||||
/* Clear timer interrupt pending bit */
|
||||
TIM_ClearITPendingBit(PIOS_PWM_SUPV_TIMER, TIM_IT_Update);
|
||||
|
||||
/* Simple state machine */
|
||||
if (SupervisorState == 0) {
|
||||
/* Save this states values */
|
||||
for (int32_t i = 0; i < PIOS_PWM_NUM_INPUTS; i++) {
|
||||
CapCounterPrev[i] = CapCounter[i];
|
||||
}
|
||||
|
||||
/* Move to next state */
|
||||
SupervisorState = 1;
|
||||
} else {
|
||||
/* See what channels have been updated */
|
||||
for (int32_t i = 0; i < PIOS_PWM_NUM_INPUTS; i++) {
|
||||
if (CapCounter[i] == CapCounterPrev[i]) {
|
||||
CaptureValue[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to next state */
|
||||
SupervisorState = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,13 @@
|
||||
|
||||
/* Global Variables */
|
||||
|
||||
/* Provide a RCVR driver */
|
||||
static int32_t PIOS_SBUS_Get(uint32_t chan_id);
|
||||
|
||||
const struct pios_rcvr_driver pios_sbus_rcvr_driver = {
|
||||
.read = PIOS_SBUS_Get,
|
||||
};
|
||||
|
||||
/* Local Variables */
|
||||
static uint16_t channel_data[SBUS_NUMBER_OF_CHANNELS];
|
||||
static uint8_t received_data[SBUS_FRAME_LENGTH - 2];
|
||||
@ -154,19 +161,19 @@ void PIOS_SBUS_Init(void)
|
||||
* \output -1 channel not available
|
||||
* \output >0 channel value
|
||||
*/
|
||||
int16_t PIOS_SBUS_Get(int8_t channel)
|
||||
static int32_t PIOS_SBUS_Get(uint32_t chan_id)
|
||||
{
|
||||
/* return error if channel is not available */
|
||||
if (channel >= SBUS_NUMBER_OF_CHANNELS) {
|
||||
if (chan_id >= SBUS_NUMBER_OF_CHANNELS) {
|
||||
return -1;
|
||||
}
|
||||
return channel_data[channel];
|
||||
return channel_data[chan_id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Interrupt handler for USART
|
||||
*/
|
||||
void SBUS_IRQHandler(uint32_t usart_id)
|
||||
void PIOS_SBUS_irq_handler(uint32_t usart_id)
|
||||
{
|
||||
/* by always reading DR after SR make sure to clear any error interrupts */
|
||||
volatile uint16_t sr = pios_sbus_cfg.pios_usart_sbus_cfg->regs->SR;
|
||||
@ -198,7 +205,7 @@ void SBUS_IRQHandler(uint32_t usart_id)
|
||||
* data reception. If no new data received in 100ms, we must call the
|
||||
* failsafe function which clears all channels.
|
||||
*/
|
||||
void PIOS_SBUS_irq_handler()
|
||||
void PIOS_SBUSSV_irq_handler()
|
||||
{
|
||||
/* waiting for new frame if no bytes were received in 3.2ms */
|
||||
if (++receive_timer > 2) {
|
||||
|
@ -51,8 +51,15 @@
|
||||
|
||||
/* Global Variables */
|
||||
|
||||
/* Provide a RCVR driver */
|
||||
static int32_t PIOS_SPEKTRUM_Get(uint32_t chan_id);
|
||||
|
||||
const struct pios_rcvr_driver pios_spektrum_rcvr_driver = {
|
||||
.read = PIOS_SPEKTRUM_Get,
|
||||
};
|
||||
|
||||
/* Local Variables */
|
||||
static uint16_t CaptureValue[12],CaptureValueTemp[12];
|
||||
static uint16_t CaptureValue[PIOS_SPEKTRUM_NUM_INPUTS],CaptureValueTemp[PIOS_SPEKTRUM_NUM_INPUTS];
|
||||
static uint8_t prev_byte = 0xFF, sync = 0, bytecount = 0, datalength=0, frame_error=0, byte_array[20] = { 0 };
|
||||
uint8_t sync_of = 0;
|
||||
uint16_t supv_timer=0;
|
||||
@ -84,13 +91,13 @@ void PIOS_SPEKTRUM_Init(void)
|
||||
* \output -1 Channel not available
|
||||
* \output >0 Channel value
|
||||
*/
|
||||
int16_t PIOS_SPEKTRUM_Get(int8_t Channel)
|
||||
static int32_t PIOS_SPEKTRUM_Get(uint32_t chan_id)
|
||||
{
|
||||
/* Return error if channel not available */
|
||||
if (Channel >= 12) {
|
||||
if (chan_id >= PIOS_SPEKTRUM_NUM_INPUTS) {
|
||||
return -1;
|
||||
}
|
||||
return CaptureValue[Channel];
|
||||
return CaptureValue[chan_id];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -201,7 +208,7 @@ int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
|
||||
{
|
||||
frame_error=1;
|
||||
}
|
||||
if (channeln < 12 && !frame_error)
|
||||
if (channeln < PIOS_SPEKTRUM_NUM_INPUTS && !frame_error)
|
||||
CaptureValueTemp[channeln] = data;
|
||||
}
|
||||
}
|
||||
@ -212,7 +219,7 @@ int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
|
||||
sync_of = 0;
|
||||
if (!frame_error)
|
||||
{
|
||||
for(int i=0;i<12;i++)
|
||||
for(int i=0;i<PIOS_SPEKTRUM_NUM_INPUTS;i++)
|
||||
{
|
||||
CaptureValue[i] = CaptureValueTemp[i];
|
||||
}
|
||||
@ -224,7 +231,7 @@ int32_t PIOS_SPEKTRUM_Decode(uint8_t b)
|
||||
}
|
||||
|
||||
/* Interrupt handler for USART */
|
||||
void SPEKTRUM_IRQHandler(uint32_t usart_id) {
|
||||
void PIOS_SPEKTRUM_irq_handler(uint32_t usart_id) {
|
||||
/* by always reading DR after SR make sure to clear any error interrupts */
|
||||
volatile uint16_t sr = pios_spektrum_cfg.pios_usart_spektrum_cfg->regs->SR;
|
||||
volatile uint8_t b = pios_spektrum_cfg.pios_usart_spektrum_cfg->regs->DR;
|
||||
@ -248,7 +255,7 @@ void SPEKTRUM_IRQHandler(uint32_t usart_id) {
|
||||
*@brief This function is called between frames and when a spektrum word hasnt been decoded for too long
|
||||
*@brief clears the channel values
|
||||
*/
|
||||
void PIOS_SPEKTRUM_irq_handler() {
|
||||
void PIOS_SPEKTRUMSV_irq_handler() {
|
||||
/* 125hz */
|
||||
supv_timer++;
|
||||
if(supv_timer > 5) {
|
||||
@ -262,7 +269,7 @@ void PIOS_SPEKTRUM_irq_handler() {
|
||||
if (sync_of > 12) {
|
||||
/* signal lost */
|
||||
sync_of = 0;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
for (int i = 0; i < PIOS_SPEKTRUM_NUM_INPUTS; i++) {
|
||||
CaptureValue[i] = 0;
|
||||
CaptureValueTemp[i] = 0;
|
||||
}
|
||||
|
@ -30,8 +30,4 @@
|
||||
#ifndef PIOS_PPM_H
|
||||
#define PIOS_PPM_H
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_PPM_Init(void);
|
||||
extern int32_t PIOS_PPM_Get(int8_t Channel);
|
||||
|
||||
#endif /* PIOS_PPM_H */
|
||||
|
@ -59,6 +59,10 @@ extern uint8_t pios_ppm_num_channels;
|
||||
extern const struct pios_ppm_cfg pios_ppm_cfg;
|
||||
extern const struct pios_ppmsv_cfg pios_ppmsv_cfg;
|
||||
|
||||
extern const struct pios_rcvr_driver pios_ppm_rcvr_driver;
|
||||
|
||||
extern void PIOS_PPM_Init(void);
|
||||
|
||||
#endif /* PIOS_PPM_PRIV_H */
|
||||
|
||||
/**
|
||||
|
@ -30,9 +30,4 @@
|
||||
#ifndef PIOS_PWM_H
|
||||
#define PIOS_PWM_H
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_PWM_Init(void);
|
||||
extern int32_t PIOS_PWM_Get(int8_t Channel);
|
||||
//extern void PIOS_PWM_irq_handler(TIM_TypeDef * timer);
|
||||
|
||||
#endif /* PIOS_PWM_H */
|
||||
|
@ -57,6 +57,10 @@ extern void PIOS_PWM_irq_handler(TIM_TypeDef * timer);
|
||||
extern uint8_t pios_pwm_num_channels;
|
||||
extern const struct pios_pwm_cfg pios_pwm_cfg;
|
||||
|
||||
extern const struct pios_rcvr_driver pios_pwm_rcvr_driver;
|
||||
|
||||
extern void PIOS_PWM_Init(void);
|
||||
|
||||
#endif /* PIOS_PWM_PRIV_H */
|
||||
|
||||
/**
|
||||
|
@ -33,9 +33,6 @@
|
||||
/* Global Types */
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_SBUS_Init(void);
|
||||
extern int16_t PIOS_SBUS_Get(int8_t Channel);
|
||||
extern void SBUS_IRQHandler(uint32_t usart_id);
|
||||
|
||||
#endif /* PIOS_SBUS_H */
|
||||
|
||||
|
@ -76,9 +76,16 @@ struct pios_sbus_cfg {
|
||||
GPIO_InitTypeDef gpio_inv_init;
|
||||
BitAction gpio_inv_enable;
|
||||
};
|
||||
extern const struct pios_sbus_cfg pios_sbus_cfg;
|
||||
|
||||
extern void PIOS_SBUS_irq_handler();
|
||||
extern void PIOS_SBUSSV_irq_handler();
|
||||
|
||||
extern uint8_t pios_sbus_num_channels;
|
||||
extern const struct pios_sbus_cfg pios_sbus_cfg;
|
||||
|
||||
extern const struct pios_rcvr_driver pios_sbus_rcvr_driver;
|
||||
|
||||
extern void PIOS_SBUS_Init(void);
|
||||
|
||||
#endif /* PIOS_SBUS_PRIV_H */
|
||||
|
||||
|
@ -34,11 +34,8 @@
|
||||
/* Global Types */
|
||||
|
||||
/* Public Functions */
|
||||
extern void PIOS_SPEKTRUM_Init(void);
|
||||
extern uint8_t PIOS_SPEKTRUM_Bind(void);
|
||||
extern int32_t PIOS_SPEKTRUM_Decode(uint8_t b);
|
||||
extern int16_t PIOS_SPEKTRUM_Get(int8_t Channel);
|
||||
extern void SPEKTRUM_IRQHandler(uint32_t usart_id);
|
||||
|
||||
#endif /* PIOS_SPEKTRUM_H */
|
||||
|
||||
|
@ -45,10 +45,15 @@ struct pios_spektrum_cfg {
|
||||
};
|
||||
|
||||
extern void PIOS_SPEKTRUM_irq_handler();
|
||||
extern void PIOS_SPEKTRUMSV_irq_handler();
|
||||
|
||||
extern uint8_t pios_spektrum_num_channels;
|
||||
extern const struct pios_spektrum_cfg pios_spektrum_cfg;
|
||||
|
||||
extern const struct pios_rcvr_driver pios_spektrum_rcvr_driver;
|
||||
|
||||
extern void PIOS_SPEKTRUM_Init(void);
|
||||
|
||||
#endif /* PIOS_PWM_PRIV_H */
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user