[sbus] use uart functions instead of macros

This commit is contained in:
Felix Ruess
2013-07-23 13:31:22 +02:00
parent f9be3ce38d
commit a2a3031570
2 changed files with 19 additions and 21 deletions
@@ -6,8 +6,15 @@ $(TARGET).CFLAGS += -DRADIO_CONTROL
ifneq ($(RADIO_CONTROL_LED),none) ifneq ($(RADIO_CONTROL_LED),none)
ap.CFLAGS += -DRADIO_CONTROL_LED=$(RADIO_CONTROL_LED) ap.CFLAGS += -DRADIO_CONTROL_LED=$(RADIO_CONTROL_LED)
endif endif
$(TARGET).CFLAGS += -DUSE_$(SBUS_PORT) -DSBUS_LINK=$(SBUS_PORT) -D$(SBUS_PORT)_BAUD=B100000
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_H=\"subsystems/radio_control/sbus.h\" # convert SBUS_PORT to upper and lower case strings:
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_SBUS SBUS_PORT_UPPER=$(shell echo $(SBUS_PORT) | tr a-z A-Z)
SBUS_PORT_LOWER=$(shell echo $(SBUS_PORT) | tr A-Z a-z)
$(TARGET).CFLAGS += -DUSE_$(SBUS_PORT_UPPER) -D$(SBUS_PORT_UPPER)_BAUD=B100000
$(TARGET).CFLAGS += -DSBUS_UART_DEV=$(SBUS_PORT_LOWER)
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_H=\"subsystems/radio_control/sbus.h\"
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_SBUS
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control.c $(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control.c
$(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control/sbus.c $(TARGET).srcs += $(SRC_SUBSYSTEMS)/radio_control/sbus.c
+9 -18
View File
@@ -53,13 +53,8 @@
#define RC_SET_POLARITY LED_ON #define RC_SET_POLARITY LED_ON
#endif #endif
/** UART selecting
*/
#define __SBusLink(dev, _x) dev##_x
#define _SBusLink(dev, _x) __SBusLink(dev, _x)
#define SBusLink(_x) _SBusLink(SBUS_LINK, _x)
/* SBUS struct */ /** SBUS struct */
struct _sbus sbus; struct _sbus sbus;
// Init function // Init function
@@ -68,8 +63,8 @@ void radio_control_impl_init(void) {
sbus.status = SBUS_STATUS_UNINIT; sbus.status = SBUS_STATUS_UNINIT;
// Set UART parameters (100K, 8 bits, 2 stops, even parity) // Set UART parameters (100K, 8 bits, 2 stops, even parity)
SBusLink(SetBitsStopParity(UBITS_8, USTOP_2, UPARITY_EVEN)); uart_periph_set_bits_stop_parity(&SBUS_UART_DEV, UBITS_8, USTOP_2, UPARITY_EVEN);
SBusLink(SetBaudrate(B100000)); uart_periph_set_baudrate(&SBUS_UART_DEV, B100000);
// Set polarity // Set polarity
#ifdef RC_POLARITY_LED #ifdef RC_POLARITY_LED
@@ -77,13 +72,8 @@ void radio_control_impl_init(void) {
#endif #endif
} }
/*
* This part is used by the autopilot to read data from a uart
*/
#define SBusBuffer() SBusLink(ChAvailable())
#define SBusGet() SBusLink(Getch())
// Decode the raw buffer /** Decode the raw buffer */
static void decode_sbus_buffer (const uint8_t *src, uint16_t *dst, bool_t *available) static void decode_sbus_buffer (const uint8_t *src, uint16_t *dst, bool_t *available)
{ {
// reset counters // reset counters
@@ -113,16 +103,16 @@ static void decode_sbus_buffer (const uint8_t *src, uint16_t *dst, bool_t *avail
} }
} }
// test frame lost flag // test frame lost flag
*available = !bit_is_set(src[SBUS_FLAGS_BYTE],SBUS_FRAME_LOST_BIT); *available = !bit_is_set(src[SBUS_FLAGS_BYTE], SBUS_FRAME_LOST_BIT);
} }
// Decoding event function // Decoding event function
// Reading from UART // Reading from UART
void sbus_decode_event(void) { void sbus_decode_event(void) {
uint8_t rbyte; uint8_t rbyte;
if (SBusBuffer()) { if (uart_char_available(&SBUS_UART_DEV)) {
do { do {
rbyte = SBusGet(); rbyte = uart_getch(&SBUS_UART_DEV);
switch (sbus.status) { switch (sbus.status) {
case SBUS_STATUS_UNINIT: case SBUS_STATUS_UNINIT:
// Wait for the start byte // Wait for the start byte
@@ -146,6 +136,7 @@ void sbus_decode_event(void) {
default: default:
break; break;
} }
} while (SBusBuffer()); } while (uart_char_available(&SBUS_UART_DEV));
} }
} }