39#if RADIO_CONTROL_NB_CHANNEL < SPEKTRUM_NB_CHANNEL
40#warning "RADIO_CONTROL_NB_CHANNEL mustn't be lower than 14. X-Plus channel expansion is not (yet) usable"
44#ifndef SPEKTRUM_PRIMARY_UART
45#error "You must at least define the primary Spektrum satellite receiver."
57#define SPEKTRUM_MASTER_RECEIVER_PULSES 9
58#define SPEKTRUM_SLAVE_RECEIVER_PULSES 10
60#define SPEKTRUM_MASTER_RECEIVER_PULSES 5
61#define SPEKTRUM_SLAVE_RECEIVER_PULSES 6
65#ifndef RC_SET_POLARITY
66#define RC_SET_POLARITY gpio_clear
72#ifndef SPEKTRUM_BIND_WAIT
73#define SPEKTRUM_BIND_WAIT 60000
79#ifndef SPEKTRUM_SYS_TYPE
80#define SPEKTRUM_SYS_TYPE 0
99#define SPEKTRUM_SYS_22_1024_2 0x01
100#define SPEKTRUM_SYS_11_2048_2 0x12
101#define SPEKTRUM_SYS_22_2048_X 0xa2
102#define SPEKTRUM_SYS_11_2048_X 0xb2
129#ifdef SPEKTRUM_BIND_PIN_PORT
130#ifdef SPEKTRUM_BIND_PIN_HIGH
174#ifdef RC_POLARITY_GPIO_PORT
181#ifdef SPEKTRUM_SECONDARY_UART
190 if (
chan == 0xFFFF) {
236 sat->lost_frame_cnt =
sat->buf[0];
291#ifdef SPEKTRUM_SECONDARY_UART
332#define _UART_RX_PORT(i) i ## _PORT_RX
333#define UART_RX_PORT(i) _UART_RX_PORT(i)
334#define _UART_RX(i) i ## _RX
335#define UART_RX(i) _UART_RX(i)
341#ifndef SPEKTRUM_PRIMARY_BIND_CONF_PORT
342#define SPEKTRUM_PRIMARY_BIND_CONF_PORT UART_RX_PORT(SPEKTRUM_PRIMARY_UART_UPPER)
344#ifndef SPEKTRUM_PRIMARY_BIND_CONF_PIN
345#define SPEKTRUM_PRIMARY_BIND_CONF_PIN UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)
347#ifndef SPEKTRUM_SECONDARY_BIND_CONF_PORT
348#define SPEKTRUM_SECONDARY_BIND_CONF_PORT UART_RX_PORT(SPEKTRUM_SECONDARY_UART_UPPER)
350#ifndef SPEKTRUM_SECONDARY_BIND_CONF_PIN
351#define SPEKTRUM_SECONDARY_BIND_CONF_PIN UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)
365#ifdef SPEKTRUM_SECONDARY_UART
375#if SPEKTRUM_BIND_WAIT
384#ifdef SPEKTRUM_SECONDARY_UART
393#ifdef SPEKTRUM_SECONDARY_UART
Main include for ABI (AirBorneInterface).
#define RADIO_CONTROL_SPEKTRUM_ID
#define RC_POLARITY_GPIO_PORT
#define RC_POLARITY_GPIO_PIN
#define SPEKTRUM_BIND_PIN_PORT
#define SPEKTRUM_BIND_PIN
void gpio_setup_input_pullup(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull up resistor enabled.
void gpio_setup_input_pulldown(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs with pull down resistors enabled.
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
static void gpio_toggle(ioportid_t port, uint16_t pin)
Toggle a gpio output to low level.
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
Some architecture independent helper functions for GPIOs.
int uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
uint8_t uart_getch(struct uart_periph *p)
struct RadioControl radio_control
Generic interface for radio control modules.
uint8_t time_since_last_frame
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
#define SPEKTRUM_SYS_TYPE
const int8_t spektrum_signs[]
static void spektrum_bind(void)
This function puts the satellite in binding mode.
void spektrum_event(void)
Checks if there is one valid satellite and sets the radio_control structure.
#define SPEKTRUM_SYS_11_2048_2
#define SPEKTRUM_SYS_11_2048_X
#define SPEKTRUM_PRIMARY_BIND_CONF_PIN
#define SPEKTRUM_MASTER_RECEIVER_PULSES
#define SPEKTRUM_SYS_22_2048_X
#define SPEKTRUM_SLAVE_RECEIVER_PULSES
static void spektrum_parse_channel(struct spektrum_sat_t *sat, uint16_t chan)
static void spektrum_parser(struct spektrum_sat_t *sat)
#define SPEKTRUM_SECONDARY_BIND_CONF_PIN
#define SPEKTRUM_SECONDARY_BIND_CONF_PORT
#define SPEKTRUM_PRIMARY_BIND_CONF_PORT
By default, the same pin is used for pulse train and uart rx, but they can be different if needed.
static struct spektrum_t spektrum
#define SPEKTRUM_SYS_22_1024_2
Allowed system field valaues.
#define SPEKTRUM_BIND_WAIT
void spektrum_init(void)
Main Radio initialization.
static void spektrum_init_sat(struct spektrum_sat_t *sat)
Initialize a spektrum sattelite.
static void spektrum_uart_check(struct uart_periph *dev, struct spektrum_sat_t *sat)
Check bytes on the UART.
void spektrum_try_bind(void)
Radio control spektrum interface.
#define SPEKTRUM_MAX_CHANNELS
int8_t signs[SPEKTRUM_NB_CHANNEL]
Signs for the RC channels.
bool valid
True when we received a packet else false.
#define SPEKTRUM_SATELLITES_NB
struct spektrum_sat_t satellites[SPEKTRUM_SATELLITES_NB]
All the satellites connected.
#define SPEKTRUM_FRAME_LEN
16 bytes in a standard frame
#define SPEKTRUM_CHANNELS_PER_FRAME
Maximum amount of RC channels per frame.
bool valid
True when we received a packet else false.
int16_t values[SPEKTRUM_MAX_CHANNELS]
RC channel values.
#define SPEKTRUM_MIN_FRAME_SPACE
Minum amount of time between frames (7ms), in fact either 11 or 22 ms.
uint8_t tx_type
Transmitter type encoded (see wiki)
#define RADIO_CONTROL_SPEKTRUM_SIGNS
#define SPEKTRUM_NB_CHANNEL
static const struct usb_device_descriptor dev
Architecture independent timing functions.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.