36 #define SBUS_START_BYTE 0x0f
37 #define SBUS_END_BYTE_0 0x00 // only possible end byte for SBUS v1
38 #define SBUS_END_BYTE_1 0x04 // with SBUS v2 and 14CH mode
39 #define SBUS_END_BYTE_2 0x14 // end byte is cycling
40 #define SBUS_END_BYTE_3 0x24 // through the following 4 types
41 #define SBUS_END_BYTE_4 0x34 // in order
42 #define SBUS_END_BYTE_5 0x08 // with SBUS v2 and 12CH mode
43 #define SBUS_BIT_PER_CHANNEL 11
44 #define SBUS_BIT_PER_BYTE 8
45 #define SBUS_FLAGS_BYTE 22
46 #define SBUS_FRAME_LOST_BIT 2
47 #define SBUS_RC_FAILSAFE_BIT 4
48 #define SBUS_RC_LOST_BIT 5
50 #define SBUS_STATUS_UNINIT 0
51 #define SBUS_STATUS_GOT_START 1
57 #define SBUS_TIMEOUT_MS 4
66 #ifndef RC_SET_POLARITY
67 #define RC_SET_POLARITY gpio_set
87 if (gpio_polarity_port != 0) {
96 bool *is_frame_available,
bool *is_rc_failsafe,
bool *is_rc_lost,
97 uint16_t *dstppm __attribute__((unused)))
100 dst[0] = ((src[0]) | (src[1] << 8)) & 0x07FF;
101 dst[1] = ((src[1] >> 3) | (src[2] << 5)) & 0x07FF;
102 dst[2] = ((src[2] >> 6) | (src[3] << 2) | (src[4] << 10)) & 0x07FF;
103 dst[3] = ((src[4] >> 1) | (src[5] << 7)) & 0x07FF;
104 dst[4] = ((src[5] >> 4) | (src[6] << 4)) & 0x07FF;
105 dst[5] = ((src[6] >> 7) | (src[7] << 1) | (src[8] << 9)) & 0x07FF;
106 dst[6] = ((src[8] >> 2) | (src[9] << 6)) & 0x07FF;
107 dst[7] = ((src[9] >> 5) | (src[10] << 3)) & 0x07FF;
108 dst[8] = ((src[11]) | (src[12] << 8)) & 0x07FF;
109 dst[9] = ((src[12] >> 3) | (src[13] << 5)) & 0x07FF;
110 dst[10] = ((src[13] >> 6) | (src[14] << 2) | (src[15] << 10)) & 0x07FF;
111 dst[11] = ((src[15] >> 1) | (src[16] << 7)) & 0x07FF;
112 dst[12] = ((src[16] >> 4) | (src[17] << 4)) & 0x07FF;
113 dst[13] = ((src[17] >> 7) | (src[18] << 1) | (src[19] << 9)) & 0x07FF;
114 dst[14] = ((src[19] >> 2) | (src[20] << 6)) & 0x07FF;
115 dst[15] = ((src[20] >> 5) | (src[21] << 3)) & 0x07FF;
118 #if PERIODIC_TELEMETRY
#define SBUS_RC_FAILSAFE_BIT
void sbus_common_decode_event(struct Sbus *sbus_p, struct uart_periph *dev)
Decoding event function.
void uart_periph_set_baudrate(struct uart_periph *p, uint32_t baud)
Set baudrate.
static void decode_sbus_buffer(const uint8_t *src, uint16_t *dst, bool *is_frame_available, bool *is_rc_failsafe, bool *is_rc_lost, uint16_t *dstppm)
Decode the raw buffer.
uint32_t start_time
Decoder start time.
uint8_t uart_getch(struct uart_periph *p)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
#define RC_SET_POLARITY
Set polarity using RC_POLARITY_GPIO.
uint16_t pulses[SBUS_NB_CHANNEL]
Decoded values.
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
ioportid_t gpio_port_t
Abstract gpio port type for hardware independent part.
#define SBUS_STATUS_UNINIT
void WEAK uart_periph_invert_data_logic(struct uart_periph *p, bool invert_rx, bool invert_tx)
bool rc_lost
RC reception is lost.
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
uint8_t status
Decoder state-machine status.
#define USEC_OF_RC_PPM_TICKS(_v)
Architecture independent timing functions.
void sbus_common_init(struct Sbus *sbus_p, struct uart_periph *dev, gpio_port_t gpio_polarity_port, uint16_t gpio_polarity_pin)
Init function.
#define SBUS_BUF_LENGTH
Generated code holding the description of a given transmitter.
Common sbus structs and defines.
uint16_t ppm[SBUS_NB_CHANNEL]
Decoded and converted to ppm values.
static const struct usb_device_descriptor dev
#define SBUS_STATUS_GOT_START
void uart_periph_set_bits_stop_parity(struct uart_periph *p, uint8_t bits, uint8_t stop, uint8_t parity)
Set parity and stop bits.
uint8_t buffer[SBUS_BUF_LENGTH]
Input buffer.
bool rc_failsafe
Receiver set to in failsafe mode.
bool frame_available
A data frame is available.
#define SBUS_FRAME_LOST_BIT
#define SBUS_TIMEOUT_MS
Time before timeout when receiving a full SBUS frame.