Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
spektrum.c File Reference
+ Include dependency graph for spektrum.c:

Go to the source code of this file.

Macros

#define SPEKTRUM_MASTER_RECEIVER_PULSES   5
 
#define SPEKTRUM_SLAVE_RECEIVER_PULSES   6
 
#define RC_SET_POLARITY   gpio_clear
 
#define SPEKTRUM_BIND_WAIT   60000
 
#define SPEKTRUM_SYS_TYPE   0
 
#define SPEKTRUM_SYS_22_1024_2   0x01
 Allowed system field valaues. More...
 
#define SPEKTRUM_SYS_11_2048_2   0x12
 
#define SPEKTRUM_SYS_22_2048_X   0xa2
 
#define SPEKTRUM_SYS_11_2048_X   0xb2
 
#define _UART_RX_PORT(i)   i ## _PORT_RX
 
#define UART_RX_PORT(i)   _UART_RX_PORT(i)
 
#define _UART_RX(i)   i ## _RX
 
#define UART_RX(i)   _UART_RX(i)
 
#define SPEKTRUM_PRIMARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_PRIMARY_UART_UPPER)
 By default, the same pin is used for pulse train and uart rx, but they can be different if needed. More...
 
#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)
 
#define SPEKTRUM_SECONDARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_SECONDARY_UART_UPPER)
 
#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)
 

Functions

static void spektrum_bind (void)
 This function puts the satellite in binding mode. More...
 
static void spektrum_init_sat (struct spektrum_sat_t *sat)
 Initialize a spektrum sattelite. More...
 
void spektrum_try_bind (void)
 
void radio_control_impl_init (void)
 Main Radio initialization. More...
 
static void spektrum_parse_channel (struct spektrum_sat_t *sat, uint16_t chan)
 
static void spektrum_parser (struct spektrum_sat_t *sat)
 
static void spektrum_uart_check (struct uart_periph *dev, struct spektrum_sat_t *sat)
 Check bytes on the UART. More...
 
void spektrum_event (void(*frame_handler)(void))
 Checks if there is one valid satellite and sets the radio_control structure. More...
 

Variables

const int8_t spektrum_signs [] = RADIO_CONTROL_SPEKTRUM_SIGNS
 
static struct spektrum_t spektrum
 

Detailed Description

Spektrum sattelite receiver implementation. For the protocol specification see: http://www.spektrumrc.com/ProdInfo/Files/Remote%20Receiver%20Interfacing%20Rev%20A.pdf

Definition in file spektrum.c.

Macro Definition Documentation

◆ _UART_RX

#define _UART_RX (   i)    i ## _RX

Definition at line 329 of file spektrum.c.

◆ _UART_RX_PORT

#define _UART_RX_PORT (   i)    i ## _PORT_RX

Definition at line 327 of file spektrum.c.

◆ RC_SET_POLARITY

#define RC_SET_POLARITY   gpio_clear

Definition at line 62 of file spektrum.c.

◆ SPEKTRUM_BIND_WAIT

#define SPEKTRUM_BIND_WAIT   60000

Definition at line 69 of file spektrum.c.

◆ SPEKTRUM_MASTER_RECEIVER_PULSES

#define SPEKTRUM_MASTER_RECEIVER_PULSES   5

Definition at line 56 of file spektrum.c.

◆ SPEKTRUM_PRIMARY_BIND_CONF_PIN

#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)

Definition at line 340 of file spektrum.c.

◆ SPEKTRUM_PRIMARY_BIND_CONF_PORT

#define SPEKTRUM_PRIMARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_PRIMARY_UART_UPPER)

By default, the same pin is used for pulse train and uart rx, but they can be different if needed.

Definition at line 337 of file spektrum.c.

◆ SPEKTRUM_SECONDARY_BIND_CONF_PIN

#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)

Definition at line 346 of file spektrum.c.

◆ SPEKTRUM_SECONDARY_BIND_CONF_PORT

#define SPEKTRUM_SECONDARY_BIND_CONF_PORT   UART_RX_PORT(SPEKTRUM_SECONDARY_UART_UPPER)

Definition at line 343 of file spektrum.c.

◆ SPEKTRUM_SLAVE_RECEIVER_PULSES

#define SPEKTRUM_SLAVE_RECEIVER_PULSES   6

Definition at line 57 of file spektrum.c.

◆ SPEKTRUM_SYS_11_2048_2

#define SPEKTRUM_SYS_11_2048_2   0x12

Definition at line 96 of file spektrum.c.

◆ SPEKTRUM_SYS_11_2048_X

#define SPEKTRUM_SYS_11_2048_X   0xb2

Definition at line 98 of file spektrum.c.

◆ SPEKTRUM_SYS_22_1024_2

#define SPEKTRUM_SYS_22_1024_2   0x01

Allowed system field valaues.

from datasheet, possible values for the frame format encoded in the system field of the internal remote frame (second byte). Only the first one is encoding values on 10bits, other ones on 11bits.

Definition at line 95 of file spektrum.c.

◆ SPEKTRUM_SYS_22_2048_X

#define SPEKTRUM_SYS_22_2048_X   0xa2

Definition at line 97 of file spektrum.c.

◆ SPEKTRUM_SYS_TYPE

#define SPEKTRUM_SYS_TYPE   0

Definition at line 76 of file spektrum.c.

◆ UART_RX

#define UART_RX (   i)    _UART_RX(i)

Definition at line 330 of file spektrum.c.

◆ UART_RX_PORT

#define UART_RX_PORT (   i)    _UART_RX_PORT(i)

Definition at line 328 of file spektrum.c.

Function Documentation

◆ radio_control_impl_init()

void radio_control_impl_init ( void  )

Main Radio initialization.

Definition at line 161 of file spektrum.c.

References gpio_setup_output(), RADIO_CONTROL_NB_CHANNEL, RC_POLARITY_GPIO_PIN, RC_POLARITY_GPIO_PORT, RC_SET_POLARITY, spektrum_t::satellites, spektrum_t::signs, spektrum, spektrum_init_sat(), and spektrum_signs.

+ Here is the call graph for this function:

◆ spektrum_bind()

static void UNUSED spektrum_bind ( void  )
static

This function puts the satellite in binding mode.

The requirement of this are that this needs to be done while powering up.

Definition at line 352 of file spektrum.c.

References gpio_set(), gpio_setup_input(), gpio_setup_output(), gpio_toggle(), SPEKTRUM_BIND_WAIT, SPEKTRUM_MASTER_RECEIVER_PULSES, SPEKTRUM_PRIMARY_BIND_CONF_PIN, SPEKTRUM_PRIMARY_BIND_CONF_PORT, SPEKTRUM_SECONDARY_BIND_CONF_PIN, SPEKTRUM_SECONDARY_BIND_CONF_PORT, SPEKTRUM_SLAVE_RECEIVER_PULSES, and sys_time_usleep().

Referenced by spektrum_try_bind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spektrum_event()

void spektrum_event ( void(*)(void)  frame_handler)

◆ spektrum_init_sat()

static void spektrum_init_sat ( struct spektrum_sat_t sat)
inlinestatic

Initialize a spektrum sattelite.

Definition at line 103 of file spektrum.c.

References get_sys_time_msec(), spektrum_sat_t::idx, SPEKTRUM_MAX_CHANNELS, spektrum_sat_t::timer, spektrum_sat_t::valid, and spektrum_sat_t::values.

Referenced by radio_control_impl_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spektrum_parse_channel()

static void spektrum_parse_channel ( struct spektrum_sat_t sat,
uint16_t  chan 
)
inlinestatic

Definition at line 182 of file spektrum.c.

References MAX_PPRZ, RADIO_THROTTLE, spektrum, SPEKTRUM_SYS_22_1024_2, spektrum_t::tx_type, spektrum_sat_t::valid, spektrum_t::valid, and spektrum_sat_t::values.

Referenced by spektrum_parser().

+ Here is the caller graph for this function:

◆ spektrum_parser()

static void spektrum_parser ( struct spektrum_sat_t sat)
inlinestatic

Definition at line 228 of file spektrum.c.

References spektrum_sat_t::buf, spektrum_sat_t::lost_frame_cnt, spektrum, SPEKTRUM_CHANNELS_PER_FRAME, spektrum_parse_channel(), SPEKTRUM_SYS_11_2048_2, SPEKTRUM_SYS_11_2048_X, SPEKTRUM_SYS_22_1024_2, SPEKTRUM_SYS_22_2048_X, spektrum_t::tx_type, and type().

Referenced by spektrum_uart_check().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spektrum_try_bind()

void spektrum_try_bind ( void  )

Definition at line 123 of file spektrum.c.

References gpio_get(), gpio_setup_input_pulldown(), gpio_setup_input_pullup(), spektrum_bind(), SPEKTRUM_BIND_PIN, SPEKTRUM_BIND_PIN_PORT, and sys_time_usleep().

+ Here is the call graph for this function:

◆ spektrum_uart_check()

static void spektrum_uart_check ( struct uart_periph dev,
struct spektrum_sat_t sat 
)
static

Check bytes on the UART.

Definition at line 254 of file spektrum.c.

References spektrum_sat_t::buf, dev, get_sys_time_msec(), spektrum_sat_t::idx, SPEKTRUM_FRAME_LEN, SPEKTRUM_MIN_FRAME_SPACE, spektrum_parser(), spektrum_sat_t::timer, uart_char_available(), and uart_getch().

Referenced by spektrum_event().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ spektrum

struct spektrum_t spektrum
static
Initial value:
= {
.valid = false,
.tx_type = SPEKTRUM_SYS_TYPE,
}

Definition at line 83 of file spektrum.c.

Referenced by radio_control_impl_init(), spektrum_event(), spektrum_parse_channel(), and spektrum_parser().

◆ spektrum_signs

const int8_t spektrum_signs[] = RADIO_CONTROL_SPEKTRUM_SIGNS

Definition at line 80 of file spektrum.c.

Referenced by radio_control_impl_init().

SPEKTRUM_SYS_TYPE
#define SPEKTRUM_SYS_TYPE
Definition: spektrum.c:76