mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 15:30:08 +08:00
[sbus] use uart functions instead of macros
This commit is contained in:
@@ -6,8 +6,15 @@ $(TARGET).CFLAGS += -DRADIO_CONTROL
|
||||
ifneq ($(RADIO_CONTROL_LED),none)
|
||||
ap.CFLAGS += -DRADIO_CONTROL_LED=$(RADIO_CONTROL_LED)
|
||||
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\"
|
||||
$(TARGET).CFLAGS += -DRADIO_CONTROL_TYPE_SBUS
|
||||
|
||||
# convert SBUS_PORT to upper and lower case strings:
|
||||
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/sbus.c
|
||||
|
||||
|
||||
@@ -53,13 +53,8 @@
|
||||
#define RC_SET_POLARITY LED_ON
|
||||
#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;
|
||||
|
||||
// Init function
|
||||
@@ -68,8 +63,8 @@ void radio_control_impl_init(void) {
|
||||
sbus.status = SBUS_STATUS_UNINIT;
|
||||
|
||||
// Set UART parameters (100K, 8 bits, 2 stops, even parity)
|
||||
SBusLink(SetBitsStopParity(UBITS_8, USTOP_2, UPARITY_EVEN));
|
||||
SBusLink(SetBaudrate(B100000));
|
||||
uart_periph_set_bits_stop_parity(&SBUS_UART_DEV, UBITS_8, USTOP_2, UPARITY_EVEN);
|
||||
uart_periph_set_baudrate(&SBUS_UART_DEV, B100000);
|
||||
|
||||
// Set polarity
|
||||
#ifdef RC_POLARITY_LED
|
||||
@@ -77,13 +72,8 @@ void radio_control_impl_init(void) {
|
||||
#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)
|
||||
{
|
||||
// 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
|
||||
*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
|
||||
// Reading from UART
|
||||
void sbus_decode_event(void) {
|
||||
uint8_t rbyte;
|
||||
if (SBusBuffer()) {
|
||||
if (uart_char_available(&SBUS_UART_DEV)) {
|
||||
do {
|
||||
rbyte = SBusGet();
|
||||
rbyte = uart_getch(&SBUS_UART_DEV);
|
||||
switch (sbus.status) {
|
||||
case SBUS_STATUS_UNINIT:
|
||||
// Wait for the start byte
|
||||
@@ -146,6 +136,7 @@ void sbus_decode_event(void) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (SBusBuffer());
|
||||
} while (uart_char_available(&SBUS_UART_DEV));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user