1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-30 15:52:12 +01:00

Spektrum support for Revolution

This commit is contained in:
James Cotton 2011-11-26 22:19:42 -06:00
parent e24c905ff7
commit 21367d3a22
5 changed files with 215 additions and 41 deletions

View File

@ -117,7 +117,7 @@ extern uint32_t pios_i2c_mag_adapter_id;
// //
// See also pios_board.c // See also pios_board.c
//------------------------- //-------------------------
#define PIOS_USART_MAX_DEVS 2 #define PIOS_USART_MAX_DEVS 5
//------------------------- //-------------------------
// PIOS_COM // PIOS_COM
@ -185,6 +185,12 @@ extern uint32_t pios_com_telem_usb_id;
#define PIOS_SBUS_MAX_DEVS 1 #define PIOS_SBUS_MAX_DEVS 1
#define PIOS_SBUS_NUM_INPUTS (16+2) #define PIOS_SBUS_NUM_INPUTS (16+2)
//-------------------------
// Receiver DSM input
//-------------------------
#define PIOS_DSM_MAX_DEVS 2
#define PIOS_DSM_NUM_INPUTS 12
//------------------------- //-------------------------
// Servo outputs // Servo outputs
//------------------------- //-------------------------

View File

@ -34,6 +34,10 @@
#if defined(PIOS_INCLUDE_DSM) #if defined(PIOS_INCLUDE_DSM)
#if !defined(PIOS_INCLUDE_RTC)
#error PIOS_INCLUDE_RTC must be used to use DSM
#endif
/* Forward Declarations */ /* Forward Declarations */
static int32_t PIOS_DSM_Get(uint32_t rcvr_id, uint8_t channel); static int32_t PIOS_DSM_Get(uint32_t rcvr_id, uint8_t channel);
static uint16_t PIOS_DSM_RxInCallback(uint32_t context, static uint16_t PIOS_DSM_RxInCallback(uint32_t context,
@ -113,10 +117,8 @@ static void PIOS_DSM_Bind(struct pios_dsm_dev *dsm_dev, uint8_t bind)
{ {
const struct pios_dsm_cfg *cfg = dsm_dev->cfg; const struct pios_dsm_cfg *cfg = dsm_dev->cfg;
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef GPIO_InitStructure = cfg->bind.init;
GPIO_InitStructure.GPIO_Pin = cfg->bind.init.GPIO_Pin; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = cfg->bind.init.GPIO_Speed;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
/* just to limit bind pulses */ /* just to limit bind pulses */
if (bind > 10) if (bind > 10)

View File

@ -74,14 +74,18 @@ static bool PIOS_USART_validate(struct pios_usart_dev * usart_dev)
return (usart_dev->magic == PIOS_USART_DEV_MAGIC); return (usart_dev->magic == PIOS_USART_DEV_MAGIC);
} }
#if defined(PIOS_INCLUDE_FREERTOS) && 0 #if defined(PIOS_INCLUDE_FREERTOS)
static struct pios_usart_dev * PIOS_USART_alloc(void) static struct pios_usart_dev * PIOS_USART_alloc(void)
{ {
struct pios_usart_dev * usart_dev; struct pios_usart_dev * usart_dev;
usart_dev = (struct pios_usart_dev *)malloc(sizeof(*usart_dev)); usart_dev = (struct pios_usart_dev *)pvPortMalloc(sizeof(*usart_dev));
if (!usart_dev) return(NULL); if (!usart_dev) return(NULL);
usart_dev->rx_in_cb = 0;
usart_dev->rx_in_context = 0;
usart_dev->tx_out_cb = 0;
usart_dev->tx_out_context = 0;
usart_dev->magic = PIOS_USART_DEV_MAGIC; usart_dev->magic = PIOS_USART_DEV_MAGIC;
return(usart_dev); return(usart_dev);
} }
@ -111,21 +115,47 @@ static struct pios_usart_dev * PIOS_USART_alloc(void)
*/ */
static void PIOS_USART_generic_irq_handler(uint32_t usart_id); static void PIOS_USART_generic_irq_handler(uint32_t usart_id);
#define USART_HANDLER(_n) \ static uint32_t PIOS_USART_1_id;
static uint32_t PIOS_USART_ ## _n ## _id; \ void USART1_IRQHandler(void) __attribute__ ((alias ("PIOS_USART_1_irq_handler")));
void USART ## _n ## _IRQHandler(void) __attribute__ ((alias ("PIOS_USART_" #_n "_irq_handler"))); \ static void PIOS_USART_1_irq_handler (void)
static void PIOS_USART_ ## _n ## _irq_handler (void) \ {
{ \ PIOS_USART_generic_irq_handler (PIOS_USART_1_id);
PIOS_USART_generic_irq_handler (PIOS_USART_ ## _n ## _id); \ }
} \
struct hack
USART_HANDLER(1); static uint32_t PIOS_USART_2_id;
USART_HANDLER(2); void USART2_IRQHandler(void) __attribute__ ((alias ("PIOS_USART_2_irq_handler")));
USART_HANDLER(3); static void PIOS_USART_2_irq_handler (void)
USART_HANDLER(4); {
USART_HANDLER(5); PIOS_USART_generic_irq_handler (PIOS_USART_2_id);
USART_HANDLER(6); }
static uint32_t PIOS_USART_3_id;
void USART3_IRQHandler(void) __attribute__ ((alias ("PIOS_USART_3_irq_handler")));
static void PIOS_USART_3_irq_handler (void)
{
PIOS_USART_generic_irq_handler (PIOS_USART_3_id);
}
static uint32_t PIOS_USART_4_id;
void USART4_IRQHandler(void) __attribute__ ((alias ("PIOS_USART_4_irq_handler")));
static void PIOS_USART_4_irq_handler (void)
{
PIOS_USART_generic_irq_handler (PIOS_USART_4_id);
}
static uint32_t PIOS_USART_5_id;
void USART5_IRQHandler(void) __attribute__ ((alias ("PIOS_USART_5_irq_handler")));
static void PIOS_USART_5_irq_handler (void)
{
PIOS_USART_generic_irq_handler (PIOS_USART_5_id);
}
static uint32_t PIOS_USART_6_id;
void USART6_IRQHandler(void) __attribute__ ((alias ("PIOS_USART_6_irq_handler")));
static void PIOS_USART_6_irq_handler (void)
{
PIOS_USART_generic_irq_handler (PIOS_USART_6_id);
}
/** /**
* Initialise a single USART device * Initialise a single USART device
@ -185,6 +215,8 @@ int32_t PIOS_USART_Init(uint32_t * usart_id, const struct pios_usart_cfg * cfg)
break; break;
} }
NVIC_Init((NVIC_InitTypeDef *)&(usart_dev->cfg->irq.init)); NVIC_Init((NVIC_InitTypeDef *)&(usart_dev->cfg->irq.init));
USART_ITConfig(usart_dev->cfg->regs, USART_IT_RXNE, ENABLE);
USART_ITConfig(usart_dev->cfg->regs, USART_IT_TXE, ENABLE);
// FIXME XXX Clear / reset uart here - sends NUL char else // FIXME XXX Clear / reset uart here - sends NUL char else

View File

@ -3340,6 +3340,7 @@
65FAA03F133B669400F6F5CD /* GTOP_BIN.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = GTOP_BIN.c; sourceTree = "<group>"; }; 65FAA03F133B669400F6F5CD /* GTOP_BIN.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = GTOP_BIN.c; sourceTree = "<group>"; };
65FAB8FC1480DA19000FF8B2 /* pios_dsm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_dsm.c; sourceTree = "<group>"; }; 65FAB8FC1480DA19000FF8B2 /* pios_dsm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_dsm.c; sourceTree = "<group>"; };
65FAB8FD1480DA19000FF8B2 /* pios_pwm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_pwm.c; sourceTree = "<group>"; }; 65FAB8FD1480DA19000FF8B2 /* pios_pwm.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_pwm.c; sourceTree = "<group>"; };
65FAB8FE1481A5C5000FF8B2 /* pios_rtc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pios_rtc.c; sourceTree = "<group>"; };
65FBE14412E7C98100176B5A /* pios_servo_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_servo_priv.h; sourceTree = "<group>"; }; 65FBE14412E7C98100176B5A /* pios_servo_priv.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = pios_servo_priv.h; sourceTree = "<group>"; };
65FC66AA123F30F100B04F74 /* ahrs_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ahrs_timer.c; path = ../../AHRS/ahrs_timer.c; sourceTree = SOURCE_ROOT; }; 65FC66AA123F30F100B04F74 /* ahrs_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = ahrs_timer.c; path = ../../AHRS/ahrs_timer.c; sourceTree = SOURCE_ROOT; };
65FC66AB123F312A00B04F74 /* ahrs_timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ahrs_timer.h; sourceTree = "<group>"; }; 65FC66AB123F312A00B04F74 /* ahrs_timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ahrs_timer.h; sourceTree = "<group>"; };
@ -3862,8 +3863,6 @@
65904E5D14613B6100FD9482 /* STM32F4xx */ = { 65904E5D14613B6100FD9482 /* STM32F4xx */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
65FAB8FC1480DA19000FF8B2 /* pios_dsm.c */,
65FAB8FD1480DA19000FF8B2 /* pios_pwm.c */,
65904E5E14613B6100FD9482 /* inc */, 65904E5E14613B6100FD9482 /* inc */,
65904E6214613B6100FD9482 /* Libraries */, 65904E6214613B6100FD9482 /* Libraries */,
65904EC114613B6100FD9482 /* library.mk */, 65904EC114613B6100FD9482 /* library.mk */,
@ -3875,6 +3874,7 @@
65904EC714613B6100FD9482 /* pios_bmp085.c */, 65904EC714613B6100FD9482 /* pios_bmp085.c */,
65904EC814613B6100FD9482 /* pios_debug.c */, 65904EC814613B6100FD9482 /* pios_debug.c */,
65904EC914613B6100FD9482 /* pios_delay.c */, 65904EC914613B6100FD9482 /* pios_delay.c */,
65FAB8FC1480DA19000FF8B2 /* pios_dsm.c */,
65904ECA14613B6100FD9482 /* pios_exti.c */, 65904ECA14613B6100FD9482 /* pios_exti.c */,
65904ECB14613B6100FD9482 /* pios_gpio.c */, 65904ECB14613B6100FD9482 /* pios_gpio.c */,
65904ECC14613B6100FD9482 /* pios_hmc5883.c */, 65904ECC14613B6100FD9482 /* pios_hmc5883.c */,
@ -3886,6 +3886,8 @@
6534B5581474F7B1003DF47C /* pios_mpu6000.c */, 6534B5581474F7B1003DF47C /* pios_mpu6000.c */,
65FA9B7A14709E700019A260 /* pios_mpu6050.c */, 65FA9B7A14709E700019A260 /* pios_mpu6050.c */,
65904ED214613B6100FD9482 /* pios_ppm.c */, 65904ED214613B6100FD9482 /* pios_ppm.c */,
65FAB8FD1480DA19000FF8B2 /* pios_pwm.c */,
65FAB8FE1481A5C5000FF8B2 /* pios_rtc.c */,
65904ED314613B6100FD9482 /* pios_servo.c */, 65904ED314613B6100FD9482 /* pios_servo.c */,
65904ED414613B6100FD9482 /* pios_spi.c */, 65904ED414613B6100FD9482 /* pios_spi.c */,
65904ED514613B6100FD9482 /* pios_sys.c */, 65904ED514613B6100FD9482 /* pios_sys.c */,

View File

@ -517,8 +517,7 @@ static uint8_t pios_com_gps_rx_buffer[PIOS_COM_GPS_RX_BUF_LEN];
*/ */
static const struct pios_usart_cfg pios_usart_telem_main_cfg = { static const struct pios_usart_cfg pios_usart_telem_main_cfg = {
.regs = USART6, .regs = USART6,
.regs = USART1, .remap = GPIO_AF_USART6,
.remap = GPIO_AF_USART1,
.init = { .init = {
.USART_BaudRate = 57600, .USART_BaudRate = 57600,
.USART_WordLength = USART_WordLength_8b, .USART_WordLength = USART_WordLength_8b,
@ -530,12 +529,64 @@ static const struct pios_usart_cfg pios_usart_telem_main_cfg = {
}, },
.irq = { .irq = {
.init = { .init = {
.NVIC_IRQChannel = USART1_IRQn, .NVIC_IRQChannel = USART6_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID, .NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_MID,
.NVIC_IRQChannelSubPriority = 0, .NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE, .NVIC_IRQChannelCmd = ENABLE,
}, },
}, },
.rx = {
.gpio = GPIOC,
.init = {
.GPIO_Pin = GPIO_Pin_7,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP
},
},
.tx = {
.gpio = GPIOC,
.init = {
.GPIO_Pin = GPIO_Pin_6,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP
},
},
};
#define PIOS_COM_TELEM_RF_RX_BUF_LEN 512
#define PIOS_COM_TELEM_RF_TX_BUF_LEN 512
#endif /* PIOS_COM_TELEM */
#if defined(PIOS_INCLUDE_DSM)
/*
* Spektrum/JR DSM USART
*/
#include <pios_dsm_priv.h>
static const struct pios_usart_cfg pios_usart_dsm_main_cfg = {
.regs = USART1,
.remap = GPIO_AF_USART1,
.init = {
.USART_BaudRate = 115200,
.USART_WordLength = USART_WordLength_8b,
.USART_Parity = USART_Parity_No,
.USART_StopBits = USART_StopBits_1,
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
.USART_Mode = USART_Mode_Rx,
},
.irq = {
.init = {
.NVIC_IRQChannel = USART1_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = { .rx = {
.gpio = GPIOA, .gpio = GPIOA,
.init = { .init = {
@ -558,10 +609,76 @@ static const struct pios_usart_cfg pios_usart_telem_main_cfg = {
}, },
}; };
#define PIOS_COM_TELEM_RF_RX_BUF_LEN 512 static const struct pios_dsm_cfg pios_dsm_main_cfg = {
#define PIOS_COM_TELEM_RF_TX_BUF_LEN 512 .bind = {
.gpio = GPIOA,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_OUT,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_NOPULL
},
},
};
#endif /* PIOS_COM_TELEM */
static const struct pios_usart_cfg pios_usart_dsm_flexi_cfg = {
.regs = USART3,
.remap = GPIO_AF_USART3,
.init = {
.USART_BaudRate = 115200,
.USART_WordLength = USART_WordLength_8b,
.USART_Parity = USART_Parity_No,
.USART_StopBits = USART_StopBits_1,
.USART_HardwareFlowControl = USART_HardwareFlowControl_None,
.USART_Mode = USART_Mode_Rx,
},
.irq = {
.init = {
.NVIC_IRQChannel = USART3_IRQn,
.NVIC_IRQChannelPreemptionPriority = PIOS_IRQ_PRIO_HIGH,
.NVIC_IRQChannelSubPriority = 0,
.NVIC_IRQChannelCmd = ENABLE,
},
},
.rx = {
.gpio = GPIOB,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP
},
},
.tx = {
.gpio = GPIOB,
.init = {
.GPIO_Pin = GPIO_Pin_10,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_AF,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_UP
},
},
};
static const struct pios_dsm_cfg pios_dsm_flexi_cfg = {
.bind = {
.gpio = GPIOB,
.init = {
.GPIO_Pin = GPIO_Pin_11,
.GPIO_Speed = GPIO_Speed_2MHz,
.GPIO_Mode = GPIO_Mode_OUT,
.GPIO_OType = GPIO_OType_PP,
.GPIO_PuPd = GPIO_PuPd_NOPULL
},
},
};
#endif /* PIOS_INCLUDE_DSM */
#if defined(PIOS_INCLUDE_COM) #if defined(PIOS_INCLUDE_COM)
@ -1388,10 +1505,6 @@ static const struct pios_mpu6000_cfg pios_mpu6000_cfg = {
* initializes all the core subsystems on this specific hardware * initializes all the core subsystems on this specific hardware
* called from System/openpilot.c * called from System/openpilot.c
*/ */
int32_t test_val;
uint8_t buf[4];
uint8_t rec[4];
struct pios_mpu6000_data test_gyro_data;
void PIOS_Board_Init(void) { void PIOS_Board_Init(void) {
/* Delay system */ /* Delay system */
@ -1486,16 +1599,39 @@ void PIOS_Board_Init(void) {
#endif /* PIOS_INCLUDE_COM */ #endif /* PIOS_INCLUDE_COM */
// Set up spektrum receiver
enum pios_dsm_proto proto;
proto = PIOS_DSM_PROTO_DSM2;
uint32_t pios_usart_dsm_id;
if (PIOS_USART_Init(&pios_usart_dsm_id, &pios_usart_dsm_main_cfg)) {
PIOS_Assert(0);
}
uint32_t pios_dsm_id;
if (PIOS_DSM_Init(&pios_dsm_id,
&pios_dsm_main_cfg,
&pios_usart_com_driver,
pios_usart_dsm_id,
proto, 0)) {
PIOS_Assert(0);
}
uint32_t pios_dsm_rcvr_id;
if (PIOS_RCVR_Init(&pios_dsm_rcvr_id, &pios_dsm_rcvr_driver, pios_dsm_id)) {
PIOS_Assert(0);
}
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_DSMMAINPORT] = pios_dsm_rcvr_id;
/* Set up the receiver port. Later this should be optional */ /* Set up the receiver port. Later this should be optional */
uint32_t pios_pwm_id; //uint32_t pios_pwm_id;
PIOS_PWM_Init(&pios_pwm_id, &pios_pwm_cfg); //PIOS_PWM_Init(&pios_pwm_id, &pios_pwm_cfg);
uint32_t pios_pwm_rcvr_id; /*uint32_t pios_pwm_rcvr_id;
if (PIOS_RCVR_Init(&pios_pwm_rcvr_id, &pios_pwm_rcvr_driver, pios_pwm_id)) { if (PIOS_RCVR_Init(&pios_pwm_rcvr_id, &pios_pwm_rcvr_driver, pios_pwm_id)) {
PIOS_Assert(0); PIOS_Assert(0);
} }
pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PWM] = pios_pwm_rcvr_id; pios_rcvr_group_map[MANUALCONTROLSETTINGS_CHANNELGROUPS_PWM] = pios_pwm_rcvr_id;*/
/* Set up the servo outputs */ /* Set up the servo outputs */
PIOS_Servo_Init(&pios_servo_cfg); PIOS_Servo_Init(&pios_servo_cfg);
@ -1517,7 +1653,6 @@ void PIOS_Board_Init(void) {
PIOS_DEBUG_Assert(0); PIOS_DEBUG_Assert(0);
} }
PIOS_MPU6000_Attach(pios_spi_gyro_id); PIOS_MPU6000_Attach(pios_spi_gyro_id);
PIOS_MPU6000_Init(&pios_mpu6000_cfg); PIOS_MPU6000_Init(&pios_mpu6000_cfg);
@ -1525,9 +1660,6 @@ void PIOS_Board_Init(void) {
PIOS_BMA180_Init(&pios_bma180_cfg); PIOS_BMA180_Init(&pios_bma180_cfg);
PIOS_HMC5883_Init(&pios_hmc5883_cfg); PIOS_HMC5883_Init(&pios_hmc5883_cfg);
} }
/** /**