Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cc2500_settings.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Tom van Dijk <tomvand@users.noreply.github.com>
3 *
4 * This code is based on the betaflight cc2500 and FrskyX implementation.
5 * https://github.com/betaflight/betaflight
6 *
7 * This file is part of paparazzi.
8 *
9 * paparazzi is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * paparazzi is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with paparazzi; see the file COPYING. If not, write to
21 * the Free Software Foundation, 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
23 */
24
25#include "cc2500_settings.h"
26
27#include "cc2500_rx_spi.h"
28
29#include BOARD_CONFIG
30#include "mcu_periph/gpio.h"
31#include "generated/airframe.h"
33
34#include <string.h>
35
36
37#define _LED_GPIO(l) l ## _GPIO
38#define LED_GPIO(l) _LED_GPIO(l)
39#define _LED_GPIO_PIN(l) l ## _GPIO_PIN
40#define LED_GPIO_PIN(l) _LED_GPIO_PIN(l)
41#define _LED_GPIO_ON(l) l ## _GPIO_ON
42#define LED_GPIO_ON(l) _LED_GPIO_ON(l)
43#define _LED_GPIO_OFF(l) l ## _GPIO_OFF
44#define LED_GPIO_OFF(l) _LED_GPIO_OFF(l)
45
46#define _BUTTON_GPIO(b) b ## _GPIO
47#define BUTTON_GPIO(b) _BUTTON_GPIO(b)
48#define _BUTTON_PIN(b) b ## _PIN
49#define BUTTON_PIN(b) _BUTTON_PIN(b)
50
51
52#ifndef CC2500_RX_SPI_PROTOCOL
53#define CC2500_RX_SPI_PROTOCOL RX_SPI_FRSKY_X_LBT
54#endif
55
56#ifndef CC2500_AUTOBIND
57#define CC2500_AUTOBIND FALSE
58#endif
59
60#ifndef CC2500_TELEMETRY_SENSORS
61#define CC2500_TELEMETRY_SENSORS (SENSOR_VOLTAGE | SENSOR_CURRENT | SENSOR_FUEL | SENSOR_ALTITUDE | SENSOR_VARIO)
62#endif
63
64static void cc2500_persistent_write(void);
65
66
67// main/config/config.h:
68void bf_writeEEPROM(void) {
69 // Settings storage handled by paparazzi's persistent settings
72}
73
74
75// main/pg/rx.h:
77const rxConfig_t* rxConfig(void) {
78 return &rxconfig;
79}
80
81
82// main/pg/rx_spi.h:
83static struct gpio_t extiIo;
84static struct gpio_t ledIo;
85static struct gpio_t bindIo;
88 return &spiconfig;
89}
90
91
92// main/pg/rx_spi_cc2500.h:
100
101
102// main/telemetry/telemetry.h:
104
106 return &telemetryconfig;
107}
108
109
110// main/telemetry/telemetry.h:
114
115
116// Paparazzi code
118
119static void cc2500_persistent_write(void) {
122 cc2500spiconfig.bindTxId[1] << 8 |
125 for (int i = 0; i < 48; i += 4) {
128 cc2500spiconfig.bindHopData[i + 1] << 8 |
129 cc2500spiconfig.bindHopData[i + 2] << 16 |
130 cc2500spiconfig.bindHopData[i + 3] << 24;
131 }
135 0xFF << 24;
136}
137
138static void cc2500_persistent_read(void) {
139 // Check that persistent data is loaded
140 // highest bindHopData byte is initialized 0 at boot
146 }
147 for (int i = 0; i < 48; i += 4) {
152 }
155}
156
157
158
160 // rxConfig
162 rxconfig.midrc = 1500;
163 rxconfig.max_aux_channel = 0; // TODO
165
166 // rxSpiConfig
171
172#ifdef CC2500_RX_LED
178#else
179 (void) ledIo;
181#endif
182 spiconfig.ledInversion = FALSE; // Handled by paparazzi LED_X_GPIO_ON|_OFF
183
184#ifdef CC2500_BIND_BUTTON
188#else
189 (void) bindIo;
191#endif
192
193 // rxCc2500SpiConfig
202
205
206 // telemetryConfig
209}
gpiofnptr_t lo
uint32_t port
uint16_t pin
gpiofnptr_t hi
const rxCc2500SpiConfig_t * rxCc2500SpiConfig(void)
void cc2500_settings_init(void)
#define CC2500_TELEMETRY_SENSORS
#define LED_GPIO_OFF(l)
static struct gpio_t ledIo
#define BUTTON_PIN(b)
#define CC2500_RX_SPI_PROTOCOL
#define LED_GPIO_ON(l)
#define LED_GPIO_PIN(l)
static void cc2500_persistent_write(void)
static struct gpio_t bindIo
#define LED_GPIO(l)
#define CC2500_AUTOBIND
bool telemetryIsSensorEnabled(sensor_e sensor)
rxCc2500SpiConfig_t * rxCc2500SpiConfigMutable(void)
const rxSpiConfig_t * rxSpiConfig(void)
static rxSpiConfig_t spiconfig
static struct gpio_t extiIo
void bf_writeEEPROM(void)
static rxConfig_t rxconfig
const telemetryConfig_t * telemetryConfig(void)
const rxConfig_t * rxConfig(void)
struct cc2500_settings_persistent_s cc2500_settings_persistent
static rxCc2500SpiConfig_t cc2500spiconfig
static telemetryConfig_t telemetryconfig
static void cc2500_persistent_read(void)
#define BUTTON_GPIO(b)
uint8_t rssi_src_frame_lpf_period
uint16_t midrc
uint8_t rssi_channel
@ FRSKY_SPI_A1_SOURCE_VBAT
uint8_t rx_spi_protocol
uint8_t max_aux_channel
#define CC2500_GDO0_PIN
#define CC2500_GDO0_GPIO
Some architecture independent helper functions for GPIOs.
uint16_t foo
Definition main_demo5.c:58
void settings_init(void)
Definition settings.c:46
Persistent settings interface.
#define settings_StoreSettings(_v)
Definition settings.h:44
#define TRUE
Definition std.h:4
#define FALSE
Definition std.h:5