Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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"
32 #include "subsystems/settings.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 
64 static void cc2500_persistent_write(void);
65 
66 
67 // main/config/config.h:
68 void bf_writeEEPROM(void) {
69  // Settings storage handled by paparazzi's persistent settings
72 }
73 
74 
75 // main/pg/rx.h:
77 const rxConfig_t* rxConfig(void) {
78  return &rxconfig;
79 }
80 
81 
82 // main/pg/rx_spi.h:
83 static struct gpio_t extiIo;
84 static struct gpio_t ledIo;
85 static struct gpio_t bindIo;
87 const rxSpiConfig_t* rxSpiConfig(void) {
88  return &spiconfig;
89 }
90 
91 
92 // main/pg/rx_spi_cc2500.h:
95  return &cc2500spiconfig;
96 }
98  return &cc2500spiconfig;
99 }
100 
101 
102 // main/telemetry/telemetry.h:
104 
106  return &telemetryconfig;
107 }
108 
109 
110 // main/telemetry/telemetry.h:
112  return sensor & CC2500_TELEMETRY_SENSORS;
113 }
114 
115 
116 // Paparazzi code
118 
119 static void cc2500_persistent_write(void) {
122  cc2500spiconfig.bindTxId[1] << 8 |
124  cc2500spiconfig.rxNum << 24;
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  }
134  cc2500spiconfig.bindHopData[49] << 8 |
135  0xFF << 24;
136 }
137 
138 static void cc2500_persistent_read(void) {
139  // Check that persistent data is loaded
140  // highest bindHopData byte is initialized 0 at boot
141  if (cc2500_settings_persistent.bindHopData[12] >> 24) {
146  }
147  for (int i = 0; i < 48; i += 4) {
150  cc2500spiconfig.bindHopData[i + 2] = (cc2500_settings_persistent.bindHopData[i / 4] >> 16) & 0xFF;
151  cc2500spiconfig.bindHopData[i + 3] = (cc2500_settings_persistent.bindHopData[i / 4] >> 24) & 0xFF;
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
173  ledIo.port = LED_GPIO(CC2500_RX_LED);
174  ledIo.pin = LED_GPIO_PIN(CC2500_RX_LED);
175  ledIo.hi = LED_GPIO_ON(CC2500_RX_LED);
176  ledIo.lo = LED_GPIO_OFF(CC2500_RX_LED);
178 #else
179  (void) ledIo;
180  spiconfig.ledIoTag = NULL;
181 #endif
182  spiconfig.ledInversion = FALSE; // Handled by paparazzi LED_X_GPIO_ON|_OFF
183 
184 #ifdef CC2500_BIND_BUTTON
185  bindIo.port = BUTTON_GPIO(CC2500_BIND_BUTTON);
186  bindIo.pin = BUTTON_PIN(CC2500_BIND_BUTTON);
188 #else
189  (void) bindIo;
190  spiconfig.bindIoTag = NULL;
191 #endif
192 
193  // rxCc2500SpiConfig
195  cc2500spiconfig.bindTxId[0] = 0;
196  cc2500spiconfig.bindTxId[1] = 0;
202 
203  settings_init();
205 
206  // telemetryConfig
209 }
cc2500_persistent_read
static void cc2500_persistent_read(void)
Definition: cc2500_settings.c:138
rxCc2500SpiConfig_s::a1Source
uint8_t a1Source
Definition: cc2500_settings.h:130
rxSpiConfig_s::rx_spi_protocol
uint8_t rx_spi_protocol
Definition: cc2500_settings.h:98
cc2500_settings_persistent_s::bindHopData
uint32_t bindHopData[13]
Definition: cc2500_settings.h:37
rxConfig_s::midrc
uint16_t midrc
Definition: cc2500_settings.h:65
settings.h
cc2500_rx_spi.h
LED_GPIO_PIN
#define LED_GPIO_PIN(l)
Definition: cc2500_settings.c:40
rxCc2500SpiConfig
const rxCc2500SpiConfig_t * rxCc2500SpiConfig(void)
Definition: cc2500_settings.c:94
BUTTON_GPIO
#define BUTTON_GPIO(b)
Definition: cc2500_settings.c:47
CC2500_TELEMETRY_SENSORS
#define CC2500_TELEMETRY_SENSORS
Definition: cc2500_settings.c:61
rxSpiConfig_s::ledInversion
uint8_t ledInversion
Definition: cc2500_settings.h:109
rxCc2500SpiConfig_s::bindOffset
int8_t bindOffset
Definition: cc2500_settings.h:127
gpio_t::pin
uint16_t pin
Definition: cc2500_compat.h:201
rxSpiConfig_s::extiIoTag
ioTag_t extiIoTag
Definition: cc2500_settings.h:111
rxconfig
static rxConfig_t rxconfig
Definition: cc2500_settings.c:76
CC2500_GDO0_GPIO
#define CC2500_GDO0_GPIO
Definition: crazybee_f4_1.0.h:181
rxCc2500SpiConfig_s::chipDetectEnabled
uint8_t chipDetectEnabled
Definition: cc2500_settings.h:131
telemetryConfig
const telemetryConfig_t * telemetryConfig(void)
Definition: cc2500_settings.c:105
bindIo
static struct gpio_t bindIo
Definition: cc2500_settings.c:85
rxCc2500SpiConfig_s::bindHopData
uint8_t bindHopData[50]
Definition: cc2500_settings.h:128
rxCc2500SpiConfig_s
Definition: cc2500_settings.h:124
CC2500_AUTOBIND
#define CC2500_AUTOBIND
Definition: cc2500_settings.c:57
cc2500_settings_persistent_s
Definition: cc2500_settings.h:35
rxConfig_s::rssi_src_frame_lpf_period
uint8_t rssi_src_frame_lpf_period
Definition: cc2500_settings.h:86
CC2500_RX_SPI_PROTOCOL
#define CC2500_RX_SPI_PROTOCOL
Definition: cc2500_settings.c:53
LED_GPIO_ON
#define LED_GPIO_ON(l)
Definition: cc2500_settings.c:42
rxConfig_s
Definition: cc2500_settings.h:53
BUTTON_PIN
#define BUTTON_PIN(b)
Definition: cc2500_settings.c:49
cc2500_settings_persistent
struct cc2500_settings_persistent_s cc2500_settings_persistent
Definition: cc2500_settings.c:117
settings_init
void settings_init(void)
Definition: settings.c:43
gpio_t::lo
gpiofnptr_t lo
Definition: cc2500_compat.h:203
cc2500_settings.h
rxSpiConfig_s::bindIoTag
ioTag_t bindIoTag
Definition: cc2500_settings.h:107
gpio_t::hi
gpiofnptr_t hi
Definition: cc2500_compat.h:202
CC2500_GDO0_PIN
#define CC2500_GDO0_PIN
Definition: crazybee_f4_1.0.h:182
rxConfig_s::max_aux_channel
uint8_t max_aux_channel
Definition: cc2500_settings.h:76
rxConfig
const rxConfig_t * rxConfig(void)
Definition: cc2500_settings.c:77
sensor_e
sensor_e
Definition: cc2500_settings.h:160
settings_StoreSettings
#define settings_StoreSettings(_v)
Definition: settings.h:40
rxSpiConfig
const rxSpiConfig_t * rxSpiConfig(void)
Definition: cc2500_settings.c:87
telemetryIsSensorEnabled
bool telemetryIsSensorEnabled(sensor_e sensor)
Definition: cc2500_settings.c:111
rxConfig_s::rssi_channel
uint8_t rssi_channel
Definition: cc2500_settings.h:62
cc2500_persistent_write
static void cc2500_persistent_write(void)
Definition: cc2500_settings.c:119
telemetryConfig_s::pidValuesAsTelemetry
uint8_t pidValuesAsTelemetry
Definition: cc2500_settings.h:151
gpio_t
Definition: cc2500_compat.h:199
rxCc2500SpiConfig_s::bindTxId
uint8_t bindTxId[2]
Definition: cc2500_settings.h:126
cc2500spiconfig
static rxCc2500SpiConfig_t cc2500spiconfig
Definition: cc2500_settings.c:93
cc2500_settings_persistent_s::bindVars
uint32_t bindVars
Definition: cc2500_settings.h:36
rxSpiConfig_s::ledIoTag
ioTag_t ledIoTag
Definition: cc2500_settings.h:108
gpio.h
spiconfig
static rxSpiConfig_t spiconfig
Definition: cc2500_settings.c:86
telemetryconfig
static telemetryConfig_t telemetryconfig
Definition: cc2500_settings.c:103
extiIo
static struct gpio_t extiIo
Definition: cc2500_settings.c:83
LED_GPIO_OFF
#define LED_GPIO_OFF(l)
Definition: cc2500_settings.c:44
gpio_t::port
uint32_t port
Definition: cc2500_compat.h:200
bf_writeEEPROM
void bf_writeEEPROM(void)
Definition: cc2500_settings.c:68
telemetryConfig_s
Definition: cc2500_settings.h:142
rxCc2500SpiConfig_s::rxNum
uint8_t rxNum
Definition: cc2500_settings.h:129
FALSE
#define FALSE
Definition: std.h:5
telemetryConfig_s::report_cell_voltage
uint8_t report_cell_voltage
Definition: cc2500_settings.h:152
TRUE
#define TRUE
Definition: std.h:4
rxCc2500SpiConfigMutable
rxCc2500SpiConfig_t * rxCc2500SpiConfigMutable(void)
Definition: cc2500_settings.c:97
rxSpiConfig_s
Definition: cc2500_settings.h:96
FRSKY_SPI_A1_SOURCE_VBAT
@ FRSKY_SPI_A1_SOURCE_VBAT
Definition: cc2500_settings.h:119
cc2500_settings_init
void cc2500_settings_init(void)
Definition: cc2500_settings.c:159
LED_GPIO
#define LED_GPIO(l)
Definition: cc2500_settings.c:38
rxCc2500SpiConfig_s::autoBind
uint8_t autoBind
Definition: cc2500_settings.h:125
ledIo
static struct gpio_t ledIo
Definition: cc2500_settings.c:84