40 #ifndef SPEKTRUM_PRIMARY_UART
41 #error "You must at least define the primary Spektrum satellite receiver."
45 INFO(
"Radio-Control now follows PPRZ sign convention: this means you might need to reverese some channels in your transmitter: RollRight / PitchUp / YawRight / FullThrottle / Auto2 are positive deflections")
56 #define SPEKTRUM_MASTER_RECEIVER_PULSES 9 // only one receiver should be in master mode
57 #define SPEKTRUM_SLAVE_RECEIVER_PULSES 10
59 #define SPEKTRUM_MASTER_RECEIVER_PULSES 5 // only one receiver should be in master mode
60 #define SPEKTRUM_SLAVE_RECEIVER_PULSES 6
64 #ifndef RC_SET_POLARITY
65 #define RC_SET_POLARITY gpio_clear
71 #ifndef SPEKTRUM_BIND_WAIT
72 #define SPEKTRUM_BIND_WAIT 60000
78 #ifndef SPEKTRUM_SYS_TYPE
79 #define SPEKTRUM_SYS_TYPE 0 // unknown type, determined from incoming frame
98 #define SPEKTRUM_SYS_22_1024_2 0x01 // 22ms 1024 DSM2
99 #define SPEKTRUM_SYS_11_2048_2 0x12 // 11ms 2048 DSM2
100 #define SPEKTRUM_SYS_22_2048_X 0xa2 // 22ms 2048 DSMX
101 #define SPEKTRUM_SYS_11_2048_X 0xb2 // 11ms 2048 DSMX
128 #ifdef SPEKTRUM_BIND_PIN_PORT
129 #ifdef SPEKTRUM_BIND_PIN_HIGH
168 spektrum.
signs[i] = spektrum_signs[i];
172 #ifdef RC_POLARITY_GPIO_PORT
179 #ifdef SPEKTRUM_SECONDARY_UART
188 if (chan == 0xFFFF) {
194 uint8_t chan_num = (chan & 0xFC00) >> 10;
195 sat->
values[chan_num] = chan & 0x03FF;
202 sat->
values[chan_num] -= (1 << 9);
210 uint8_t chan_num = (chan & 0x7800) >> 11;
211 sat->
values[chan_num] = chan & 0x07FF;
218 sat->
values[chan_num] -= (1 << 10);
227 spektrum.
valid =
true;
266 for (
uint8_t i = 0; i < bytes_cnt; i++) {
289 #ifdef SPEKTRUM_SECONDARY_UART
294 if (spektrum.
valid) {
296 spektrum.
valid =
false;
309 if (sat_id >= SPEKTRUM_SATELLITES_NB) {
330 #define _UART_RX_PORT(i) i ## _PORT_RX
331 #define UART_RX_PORT(i) _UART_RX_PORT(i)
332 #define _UART_RX(i) i ## _RX
333 #define UART_RX(i) _UART_RX(i)
339 #ifndef SPEKTRUM_PRIMARY_BIND_CONF_PORT
340 #define SPEKTRUM_PRIMARY_BIND_CONF_PORT UART_RX_PORT(SPEKTRUM_PRIMARY_UART_UPPER)
342 #ifndef SPEKTRUM_PRIMARY_BIND_CONF_PIN
343 #define SPEKTRUM_PRIMARY_BIND_CONF_PIN UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)
345 #ifndef SPEKTRUM_SECONDARY_BIND_CONF_PORT
346 #define SPEKTRUM_SECONDARY_BIND_CONF_PORT UART_RX_PORT(SPEKTRUM_SECONDARY_UART_UPPER)
348 #ifndef SPEKTRUM_SECONDARY_BIND_CONF_PIN
349 #define SPEKTRUM_SECONDARY_BIND_CONF_PIN UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)
363 #ifdef SPEKTRUM_SECONDARY_UART
373 #if SPEKTRUM_BIND_WAIT
382 #ifdef SPEKTRUM_SECONDARY_UART
391 #ifdef SPEKTRUM_SECONDARY_UART
void radio_control_impl_init(void)
Main Radio initialization.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static void spektrum_uart_check(struct uart_periph *dev, struct spektrum_sat_t *sat)
Check bytes on the UART.
#define SPEKTRUM_MAX_CHANNELS
#define RC_POLARITY_GPIO_PORT
#define SPEKTRUM_SECONDARY_BIND_CONF_PORT
#define SPEKTRUM_SYS_22_1024_2
Allowed system field valaues.
uint8_t uart_getch(struct uart_periph *p)
uint32_t get_sys_time_msec(void)
Get the time in milliseconds since startup.
struct spektrum_sat_t satellites[SPEKTRUM_SATELLITES_NB]
All the satellites connected.
Some architecture independent helper functions for GPIOs.
uint16_t uart_char_available(struct uart_periph *p)
Check UART for available chars in receive buffer.
#define SPEKTRUM_PRIMARY_BIND_CONF_PIN
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
void gpio_setup_output(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as outputs.
static void gpio_toggle(ioportid_t port, uint16_t pin)
Toggle a gpio output to low level.
const int8_t spektrum_signs[]
#define RC_POLARITY_GPIO_PIN
#define SPEKTRUM_SYS_11_2048_X
void spektrum_try_bind(void)
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.
#define RADIO_CONTROL_NB_CHANNEL
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
void spektrum_event(void(*frame_handler)(void))
Checks if there is one valid satellite and sets the radio_control structure.
static void spektrum_parse_channel(struct spektrum_sat_t *sat, uint16_t chan)
#define SPEKTRUM_MASTER_RECEIVER_PULSES
Architecture independent timing functions.
#define SPEKTRUM_SYS_11_2048_2
uint8_t buf[SPEKTRUM_FRAME_LEN]
input buffer
bool valid
True when we received a packet else false.
uint32_t timer
Timer to keep track of the UART synchronisation.
struct RadioControl radio_control
#define SPEKTRUM_FRAME_LEN
16 bytes in a standard frame
uint8_t lost_frame_cnt
Amount of RC frames lost.
uint8_t tx_type
Transmitter type encoded (see wiki)
#define SPEKTRUM_SYS_TYPE
#define SPEKTRUM_SECONDARY_BIND_CONF_PIN
#define SPEKTRUM_BIND_PIN
#define SPEKTRUM_SATELLITES_NB
#define RADIO_CONTROL_SPEKTRUM_SIGNS
static const struct usb_device_descriptor dev
int8_t signs[RADIO_CONTROL_NB_CHANNEL]
Signs for the RC channels.
static void spektrum_bind(void)
This function puts the satellite in binding mode.
static uint8_t gpio_get(ioportid_t port, uint16_t pin)
Get level of a gpio.
int16_t values[SPEKTRUM_MAX_CHANNELS]
RC channel values.
#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...
#define SPEKTRUM_BIND_PIN_PORT
bool valid
True when we received a packet else false.
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.
uint8_t time_since_last_frame
uint8_t idx
input buffer index
Radio control spektrum interface.
#define SPEKTRUM_MIN_FRAME_SPACE
Minum amount of time between frames (7ms), in fact either 11 or 22 ms.
void gpio_setup_input(ioportid_t port, uint16_t gpios)
Setup one or more pins of the given GPIO port as inputs.
static void spektrum_parser(struct spektrum_sat_t *sat)
static void gpio_set(ioportid_t port, uint16_t pin)
Set a gpio output to high level.
#define SPEKTRUM_BIND_WAIT
#define SPEKTRUM_SLAVE_RECEIVER_PULSES
#define SPEKTRUM_CHANNELS_PER_FRAME
Maximum amount of RC channels per frame.
static struct spektrum_t spektrum
#define SPEKTRUM_SYS_22_2048_X
static void spektrum_init_sat(struct spektrum_sat_t *sat)
Initialize a spektrum sattelite.