Paparazzi UAS  v7.0_unstable
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 "modules/core/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 }
gpiofnptr_t lo
uint32_t port
uint16_t pin
gpiofnptr_t hi
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)
const rxSpiConfig_t * rxSpiConfig(void)
static void cc2500_persistent_write(void)
static struct gpio_t bindIo
const telemetryConfig_t * telemetryConfig(void)
#define LED_GPIO(l)
#define CC2500_AUTOBIND
bool telemetryIsSensorEnabled(sensor_e sensor)
static rxSpiConfig_t spiconfig
static struct gpio_t extiIo
void bf_writeEEPROM(void)
const rxCc2500SpiConfig_t * rxCc2500SpiConfig(void)
static rxConfig_t rxconfig
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)
rxCc2500SpiConfig_t * rxCc2500SpiConfigMutable(void)
const rxConfig_t * rxConfig(void)
uint8_t rssi_src_frame_lpf_period
sensor_e
uint16_t midrc
uint8_t ledInversion
uint8_t rssi_channel
uint8_t pidValuesAsTelemetry
@ 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.
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