Permalink
Browse files

Convert spektrum receiver code to use UART callbacks instead of block…

…ing serial code
  • Loading branch information...
grantmd committed Mar 21, 2012
1 parent 9ce411d commit c411a57c9c7831ab61cdb16fcde8da042852aa5b
Showing with 19 additions and 20 deletions.
  1. +16 −14 Spektrum.c
  2. +0 −1 Spektrum.h
  3. +1 −1 halconf.h
  4. +0 −2 main.c
  5. +2 −2 mcuconf.h
View
@@ -10,8 +10,22 @@
#include "Spektrum.h"
+static void rxchar(UARTDriver *uartp, uint16_t c) {
+
+ (void)uartp;
+ chSysLockFromIsr();
+ if (_SpektrumParse(c)){
+ }
+ chSysUnlockFromIsr();
+}
+
// Our config for the serial connection to the RX
-static const SerialConfig sd3cfg = {
+static UARTConfig uart3cfg = {
+ NULL,
+ NULL,
+ NULL,
+ rxchar,
+ NULL, // TODO: We may need this
115200,
0,
USART_CR2_STOP1_BITS | USART_CR2_LINEN,
@@ -40,7 +54,7 @@ spektrum_t rx_state;
void SpektrumInit(void){
- sdStart(&SD3, &sd3cfg);
+ uartStart(&UARTD3, &uart3cfg);
palSetPadMode(GPIOD, 8, PAL_MODE_ALTERNATE(7)); // not currently connected
palSetPadMode(GPIOD, 9, PAL_MODE_ALTERNATE(7)); // incoming data from the receiver
@@ -54,18 +68,6 @@ void SpektrumInit(void){
rx_state.frameNum = 0L;
}
-/*
- * Reads data off of the serial connection and runs it through the parser
- * TODO: This should be a thread, or we should switch to UART and just use the callbacks
- */
-
-void SpektrumRead(void){
- // Read a byte off the receiver
- uint8_t c = chIOGet((BaseChannel *)&SD3);
- if (_SpektrumParse(c)){
- }
-}
-
/*
* Returns the most recent data for the given channel
*/
View
@@ -20,7 +20,6 @@
// Public functions
void SpektrumInit(void);
-void SpektrumRead(void);
int getChannelData(int channel);
// Private functions
View
@@ -150,7 +150,7 @@
* @brief Enables the UART subsystem.
*/
#if !defined(HAL_USE_UART) || defined(__DOXYGEN__)
-#define HAL_USE_UART FALSE
+#define HAL_USE_UART TRUE
#endif
/**
View
2 main.c
@@ -188,8 +188,6 @@ int main(void){
//chprintf(chp, "Throttle: %d.\r\n", ReceiverGetThrottle());
//MotorsSetSpeed(0, ReceiverGetThrottle());
- //SpektrumRead();
-
chprintf(chp, "Setting motor speed to: %d", speed);
MotorsSetSpeed(0, speed);
chprintf(chp, " OK\r\n");
View
@@ -159,7 +159,7 @@
*/
#define STM32_SERIAL_USE_USART1 TRUE
#define STM32_SERIAL_USE_USART2 TRUE
-#define STM32_SERIAL_USE_USART3 TRUE
+#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USE_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
#define STM32_SERIAL_USE_USART6 FALSE
@@ -195,7 +195,7 @@
*/
#define STM32_UART_USE_USART1 FALSE
#define STM32_UART_USE_USART2 FALSE
-#define STM32_UART_USE_USART3 FALSE
+#define STM32_UART_USE_USART3 TRUE
#define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)

0 comments on commit c411a57

Please sign in to comment.