Paparazzi UAS  v6.0_unstable-92-g17422e4-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
cc2500_rx_spi.c
Go to the documentation of this file.
1 #include "cc2500_compat.h"
2 
3 #include "cc2500_settings.h"
4 #include "cc2500_rx_spi.h"
5 #include "cc2500_frsky_common.h"
6 
7 #define UNUSED(x) (void)(x)
8 
9 // betaflight/src/main/rx/rx_spi.c @ 766c90b
10 /*
11  * This file is part of Cleanflight and Betaflight.
12  *
13  * Cleanflight and Betaflight are free software. You can redistribute
14  * this software and/or modify this software under the terms of the
15  * GNU General Public License as published by the Free Software
16  * Foundation, either version 3 of the License, or (at your option)
17  * any later version.
18  *
19  * Cleanflight and Betaflight are distributed in the hope that they
20  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
21  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22  * See the GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this software.
26  *
27  * If not, see <http://www.gnu.org/licenses/>.
28  */
29 
30 #include <stdbool.h>
31 #include <stdint.h>
32 
33 //#include "platform.h"
34 
35 #ifdef USE_RX_SPI
36 
37 //#include "build/build_config.h"
38 //
39 //#include "common/utils.h"
40 //
41 //#include "config/feature.h"
42 //
43 //#include "drivers/rx/rx_spi.h"
44 //#include "drivers/rx/rx_nrf24l01.h"
45 //
46 //#include "fc/config.h"
47 //
48 //#include "pg/rx_spi.h"
49 //
50 //#include "rx/rx_spi.h"
51 //#include "rx/cc2500_frsky_common.h"
52 //#include "rx/nrf24_cx10.h"
53 //#include "rx/nrf24_syma.h"
54 //#include "rx/nrf24_v202.h"
55 //#include "rx/nrf24_h8_3d.h"
56 //#include "rx/nrf24_inav.h"
57 //#include "rx/nrf24_kn.h"
58 //#include "rx/a7105_flysky.h"
59 //#include "rx/cc2500_sfhss.h"
60 //#include "rx/cyrf6936_spektrum.h"
61 
62 
65 STATIC_UNIT_TESTED uint8_t rxSpiNewPacketAvailable; // set true when a new packet is received
66 
70 typedef void (*protocolSetRcDataFromPayloadFnPtr)(uint16_t *rcData, const uint8_t *payload);
71 
76 
78 {
79  STATIC_ASSERT(NRF24L01_MAX_PAYLOAD_SIZE <= RX_SPI_MAX_PAYLOAD_SIZE, NRF24L01_MAX_PAYLOAD_SIZE_larger_than_RX_SPI_MAX_PAYLOAD_SIZE);
80 
81  if (channel >= rxRuntimeConfig->channelCount) {
82  return 0;
83  }
87  }
88  return rxSpiRcData[channel];
89 }
90 
92 {
93  switch (protocol) {
94  default:
95 #ifdef USE_RX_V202
98  protocolInit = v202Nrf24Init;
99  protocolDataReceived = v202Nrf24DataReceived;
100  protocolSetRcDataFromPayload = v202Nrf24SetRcDataFromPayload;
101  break;
102 #endif
103 #ifdef USE_RX_SYMA
104  case RX_SPI_NRF24_SYMA_X:
106  protocolInit = symaNrf24Init;
107  protocolDataReceived = symaNrf24DataReceived;
108  protocolSetRcDataFromPayload = symaNrf24SetRcDataFromPayload;
109  break;
110 #endif
111 #ifdef USE_RX_CX10
112  case RX_SPI_NRF24_CX10:
113  case RX_SPI_NRF24_CX10A:
114  protocolInit = cx10Nrf24Init;
115  protocolDataReceived = cx10Nrf24DataReceived;
116  protocolSetRcDataFromPayload = cx10Nrf24SetRcDataFromPayload;
117  break;
118 #endif
119 #ifdef USE_RX_H8_3D
120  case RX_SPI_NRF24_H8_3D:
121  protocolInit = h8_3dNrf24Init;
122  protocolDataReceived = h8_3dNrf24DataReceived;
123  protocolSetRcDataFromPayload = h8_3dNrf24SetRcDataFromPayload;
124  break;
125 #endif
126 #ifdef USE_RX_KN
127  case RX_SPI_NRF24_KN:
128  protocolInit = knNrf24Init;
129  protocolDataReceived = knNrf24DataReceived;
130  protocolSetRcDataFromPayload = knNrf24SetRcDataFromPayload;
131  break;
132 #endif
133 #ifdef USE_RX_INAV
134  case RX_SPI_NRF24_INAV:
135  protocolInit = inavNrf24Init;
136  protocolDataReceived = inavNrf24DataReceived;
137  protocolSetRcDataFromPayload = inavNrf24SetRcDataFromPayload;
138  break;
139 #endif
140 #if defined(USE_RX_FRSKY_SPI)
141 #if defined(USE_RX_FRSKY_SPI_D)
142  case RX_SPI_FRSKY_D:
143 #endif
144 #if defined(USE_RX_FRSKY_SPI_X)
145  case RX_SPI_FRSKY_X:
146  case RX_SPI_FRSKY_X_LBT:
147 #endif
152 
153  break;
154 #endif // USE_RX_FRSKY_SPI
155 #ifdef USE_RX_FLYSKY
156  case RX_SPI_A7105_FLYSKY:
158  protocolInit = flySkyInit;
159  protocolDataReceived = flySkyDataReceived;
160  protocolSetRcDataFromPayload = flySkySetRcDataFromPayload;
161  break;
162 #endif
163 #ifdef USE_RX_SFHSS_SPI
164  case RX_SPI_SFHSS:
165  protocolInit = sfhssSpiInit;
166  protocolDataReceived = sfhssSpiDataReceived;
167  protocolSetRcDataFromPayload = sfhssSpiSetRcData;
168  break;
169 #endif
170 #ifdef USE_RX_SPEKTRUM
171  case RX_SPI_CYRF6936_DSM:
172  protocolInit = spektrumSpiInit;
173  protocolDataReceived = spektrumSpiDataReceived;
174  protocolSetRcDataFromPayload = spektrumSpiSetRcDataFromPayload;
175  break;
176 #endif
177  }
178  return true;
179 }
180 
181 /*
182  * Returns true if the RX has received new data.
183  * Called from updateRx in rx.c, updateRx called from taskUpdateRxCheck.
184  * If taskUpdateRxCheck returns true, then taskUpdateRxMain will shortly be called.
185  */
187 {
188  UNUSED(rxRuntimeConfig);
189 
191 
193 
194  if (result & RX_SPI_RECEIVED_DATA) {
196  status = RX_FRAME_COMPLETE;
197  }
198 
199  if (result & RX_SPI_ROCESSING_REQUIRED) {
201  }
202 
203  return status;
204 }
205 
207 {
208  UNUSED(rxRuntimeConfig);
209 
210  if (protocolProcessFrame) {
212 
213  if (result & RX_SPI_RECEIVED_DATA) {
215  }
216 
217  if (result & RX_SPI_ROCESSING_REQUIRED) {
218  return false;
219  }
220  }
221 
222  return true;
223 }
224 
225 /*
226  * Set and initialize the RX protocol
227  */
229 {
230  bool ret = false;
231 
232  if (!rxSpiDeviceInit(rxSpiConfig)) {
233  return false;
234  }
235 
236  if (rxSpiSetProtocol(rxSpiConfig->rx_spi_protocol)) {
237  ret = protocolInit(rxSpiConfig, rxRuntimeConfig);
238  }
239  rxSpiNewPacketAvailable = false;
240  rxRuntimeConfig->rxRefreshRate = 20000;
241 
242  rxRuntimeConfig->rcReadRawFn = rxSpiReadRawRC;
243  rxRuntimeConfig->rcFrameStatusFn = rxSpiFrameStatus;
244  rxRuntimeConfig->rcProcessFrameFn = rxSpiProcessFrame;
245 
246  return ret;
247 }
248 #endif
#define rxSpiDeviceInit(rxSpiConfig)
uint8_t channelCount
Definition: cc2500_rx.h:145
const rxSpiConfig_t * rxSpiConfig(void)
static uint8_t rxSpiFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
rx_spi_received_e(* protocolDataReceivedFnPtr)(uint8_t *payload)
Definition: cc2500_rx_spi.c:68
uint8_t rx_spi_protocol
static protocolInitFnPtr protocolInit
Definition: cc2500_rx_spi.c:72
rxRuntimeConfig_t rxRuntimeConfig
Definition: cc2500_rx.c:131
rx_spi_received_e
Definition: cc2500_rx_spi.h:54
#define MAX_SUPPORTED_RC_CHANNEL_COUNT
Definition: cc2500_rx.h:78
rx_spi_protocol_e
Definition: cc2500_rx_spi.h:34
STATIC_UNIT_TESTED bool rxSpiSetProtocol(rx_spi_protocol_e protocol)
Definition: cc2500_rx_spi.c:91
#define STATIC_ASSERT(...)
Definition: cc2500_compat.h:63
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT]
Definition: cc2500_rx.c:118
void(* protocolSetRcDataFromPayloadFnPtr)(uint16_t *rcData, const uint8_t *payload)
Definition: cc2500_rx_spi.c:70
STATIC_UNIT_TESTED uint16_t rxSpiReadRawRC(const rxRuntimeConfig_t *rxRuntimeConfig, uint8_t channel)
Definition: cc2500_rx_spi.c:77
STATIC_UNIT_TESTED uint8_t rxSpiPayload[RX_SPI_MAX_PAYLOAD_SIZE]
Definition: cc2500_rx_spi.c:64
#define RX_SPI_MAX_PAYLOAD_SIZE
uint16_t rxRefreshRate
Definition: cc2500_rx.h:146
uint8_t status
static protocolSetRcDataFromPayloadFnPtr protocolSetRcDataFromPayload
Definition: cc2500_rx_spi.c:75
rcFrameStatusFnPtr rcFrameStatusFn
Definition: cc2500_rx.h:148
void frSkySpiSetRcData(uint16_t *rcData, const uint8_t *payload)
rcReadRawDataFnPtr rcReadRawFn
Definition: cc2500_rx.h:147
bool frSkySpiInit(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig)
rx_spi_received_e frSkySpiProcessFrame(uint8_t *packet)
static protocolDataReceivedFnPtr protocolDataReceived
Definition: cc2500_rx_spi.c:73
bool(* protocolInitFnPtr)(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig)
Definition: cc2500_rx_spi.c:67
rx_spi_received_e frSkySpiDataReceived(uint8_t *packet)
static protocolProcessFrameFnPtr protocolProcessFrame
Definition: cc2500_rx_spi.c:74
#define STATIC_UNIT_TESTED
Definition: cc2500_compat.h:64
rcProcessFrameFnPtr rcProcessFrameFn
Definition: cc2500_rx.h:149
#define UNUSED(x)
Definition: cc2500_rx_spi.c:7
rx_spi_received_e(* protocolProcessFrameFnPtr)(uint8_t *payload)
Definition: cc2500_rx_spi.c:69
bool rxSpiInit(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig)
uint16_t rxSpiRcData[MAX_SUPPORTED_RC_CHANNEL_COUNT]
Definition: cc2500_rx_spi.c:63
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
STATIC_UNIT_TESTED uint8_t rxSpiNewPacketAvailable
Definition: cc2500_rx_spi.c:65
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
static bool rxSpiProcessFrame(const rxRuntimeConfig_t *rxRuntimeConfig)