34 #define SBUS_START_BYTE 0x0f
35 #define SBUS_END_BYTE_0 0x00 // only possible end byte for SBUS v1
36 #define SBUS_END_BYTE_1 0x04 // with SBUS v2 and 14CH mode
37 #define SBUS_END_BYTE_2 0x14 // end byte is cycling
38 #define SBUS_END_BYTE_3 0x24 // through the following 4 types
39 #define SBUS_END_BYTE_4 0x34 // in order
40 #define SBUS_END_BYTE_5 0x08 // with SBUS v2 and 12CH mode
41 #define SBUS_BIT_PER_CHANNEL 11
42 #define SBUS_BIT_PER_BYTE 8
43 #define SBUS_FLAGS_BYTE 22
44 #define SBUS_FRAME_LOST_BIT 2
46 #define SBUS_STATUS_UNINIT 0
47 #define SBUS_STATUS_GOT_START 1
56 #ifndef RC_SET_POLARITY
57 #define RC_SET_POLARITY gpio_set
74 if (gpio_polarity_port != 0) {
84 uint16_t *dstppm __attribute__((unused)))
87 dst[0] = ((src[0]) | (src[1] << 8)) & 0x07FF;
88 dst[1] = ((src[1] >> 3) | (src[2] << 5)) & 0x07FF;
89 dst[2] = ((src[2] >> 6) | (src[3] << 2) | (src[4] << 10)) & 0x07FF;
90 dst[3] = ((src[4] >> 1) | (src[5] << 7)) & 0x07FF;
91 dst[4] = ((src[5] >> 4) | (src[6] << 4)) & 0x07FF;
92 dst[5] = ((src[6] >> 7) | (src[7] << 1) | (src[8] << 9)) & 0x07FF;
93 dst[6] = ((src[8] >> 2) | (src[9] << 6)) & 0x07FF;
94 dst[7] = ((src[9] >> 5) | (src[10] << 3)) & 0x07FF;
95 dst[8] = ((src[11]) | (src[12] << 8)) & 0x07FF;
96 dst[9] = ((src[12] >> 3) | (src[13] << 5)) & 0x07FF;
97 dst[10] = ((src[13] >> 6) | (src[14] << 2) | (src[15] << 10)) & 0x07FF;
98 dst[11] = ((src[15] >> 1) | (src[16] << 7)) & 0x07FF;
99 dst[12] = ((src[16] >> 4) | (src[17] << 4)) & 0x07FF;
100 dst[13] = ((src[17] >> 7) | (src[18] << 1) | (src[19] << 9)) & 0x07FF;
101 dst[14] = ((src[19] >> 2) | (src[20] << 6)) & 0x07FF;
102 dst[15] = ((src[20] >> 5) | (src[21] << 3)) & 0x07FF;
105 #if PERIODIC_TELEMETRY
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.
uint8_t uart_getch(struct uart_periph *p)
#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)
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)
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 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
static void decode_sbus_buffer(const uint8_t *src, uint16_t *dst, bool *available, uint16_t *dstppm)
Decode the raw buffer.
bool frame_available
new frame available
#define SBUS_FRAME_LOST_BIT