Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
spektrum.c File Reference

Spektrum sattelite receiver implementation. More...

+ 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 spektrum_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)
 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 334 of file spektrum.c.

◆ _UART_RX_PORT

#define _UART_RX_PORT (   i)    i ## _PORT_RX

Definition at line 332 of file spektrum.c.

◆ RC_SET_POLARITY

#define RC_SET_POLARITY   gpio_clear

Definition at line 66 of file spektrum.c.

◆ SPEKTRUM_BIND_WAIT

#define SPEKTRUM_BIND_WAIT   60000

Definition at line 73 of file spektrum.c.

◆ SPEKTRUM_MASTER_RECEIVER_PULSES

#define SPEKTRUM_MASTER_RECEIVER_PULSES   5

Definition at line 60 of file spektrum.c.

◆ SPEKTRUM_PRIMARY_BIND_CONF_PIN

#define SPEKTRUM_PRIMARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_PRIMARY_UART_UPPER)

Definition at line 345 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 342 of file spektrum.c.

◆ SPEKTRUM_SECONDARY_BIND_CONF_PIN

#define SPEKTRUM_SECONDARY_BIND_CONF_PIN   UART_RX(SPEKTRUM_SECONDARY_UART_UPPER)

Definition at line 351 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 348 of file spektrum.c.

◆ SPEKTRUM_SLAVE_RECEIVER_PULSES

#define SPEKTRUM_SLAVE_RECEIVER_PULSES   6

Definition at line 61 of file spektrum.c.

◆ SPEKTRUM_SYS_11_2048_2

#define SPEKTRUM_SYS_11_2048_2   0x12

Definition at line 100 of file spektrum.c.

◆ SPEKTRUM_SYS_11_2048_X

#define SPEKTRUM_SYS_11_2048_X   0xb2

Definition at line 102 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 99 of file spektrum.c.

◆ SPEKTRUM_SYS_22_2048_X

#define SPEKTRUM_SYS_22_2048_X   0xa2

Definition at line 101 of file spektrum.c.

◆ SPEKTRUM_SYS_TYPE

#define SPEKTRUM_SYS_TYPE   0

Definition at line 80 of file spektrum.c.

◆ UART_RX

#define UART_RX (   i)    _UART_RX(i)

Definition at line 335 of file spektrum.c.

◆ UART_RX_PORT

#define UART_RX_PORT (   i)    _UART_RX_PORT(i)

Definition at line 333 of file spektrum.c.

Function Documentation

◆ 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 357 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  )

◆ spektrum_init()

void spektrum_init ( void  )

◆ spektrum_init_sat()

static void spektrum_init_sat ( struct spektrum_sat_t sat)
inlinestatic

Initialize a spektrum sattelite.

Definition at line 107 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 spektrum_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 187 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 233 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, and spektrum_t::tx_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 127 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 259 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,
}
#define SPEKTRUM_SYS_TYPE
Definition: spektrum.c:80

Definition at line 84 of file spektrum.c.

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

◆ spektrum_signs

const int8_t spektrum_signs[] = RADIO_CONTROL_SPEKTRUM_SIGNS

Definition at line 84 of file spektrum.c.

Referenced by spektrum_init().