Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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 
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 {
189 
191 
193 
194  if (result & RX_SPI_RECEIVED_DATA) {
197  }
198 
199  if (result & RX_SPI_ROCESSING_REQUIRED) {
201  }
202 
203  return status;
204 }
205 
207 {
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 
233  return false;
234  }
235 
238  }
239  rxSpiNewPacketAvailable = false;
241 
245 
246  return ret;
247 }
248 #endif
uint16_t
unsigned short uint16_t
Definition: types.h:16
rxRuntimeConfig_s::rcProcessFrameFn
rcProcessFrameFnPtr rcProcessFrameFn
Definition: cc2500_rx.h:149
rxSpiSetProtocol
STATIC_UNIT_TESTED bool rxSpiSetProtocol(rx_spi_protocol_e protocol)
Definition: cc2500_rx_spi.c:91
channel
static uint8_t channel
Definition: ADS8344.c:80
rxSpiConfig_s::rx_spi_protocol
uint8_t rx_spi_protocol
Definition: cc2500_settings.h:98
RX_SPI_SFHSS
@ RX_SPI_SFHSS
Definition: cc2500_rx_spi.h:48
RX_SPI_MAX_PAYLOAD_SIZE
#define RX_SPI_MAX_PAYLOAD_SIZE
Definition: cc2500_compat.h:186
frSkySpiInit
bool frSkySpiInit(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig)
Definition: cc2500_frsky_shared.c:433
status
uint8_t status
Definition: nps_radio_control_spektrum.c:101
cc2500_rx_spi.h
RX_SPI_NRF24_CX10
@ RX_SPI_NRF24_CX10
Definition: cc2500_rx_spi.h:39
protocolSetRcDataFromPayload
static protocolSetRcDataFromPayloadFnPtr protocolSetRcDataFromPayload
Definition: cc2500_rx_spi.c:75
RX_SPI_NRF24_INAV
@ RX_SPI_NRF24_INAV
Definition: cc2500_rx_spi.h:42
RX_SPI_NRF24_SYMA_X5C
@ RX_SPI_NRF24_SYMA_X5C
Definition: cc2500_rx_spi.h:38
rcData
int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT]
Definition: cc2500_rx.c:118
RX_SPI_FRSKY_D
@ RX_SPI_FRSKY_D
Definition: cc2500_rx_spi.h:43
RX_SPI_ROCESSING_REQUIRED
@ RX_SPI_ROCESSING_REQUIRED
Definition: cc2500_rx_spi.h:58
protocolSetRcDataFromPayloadFnPtr
void(* protocolSetRcDataFromPayloadFnPtr)(uint16_t *rcData, const uint8_t *payload)
Definition: cc2500_rx_spi.c:70
RX_SPI_A7105_FLYSKY
@ RX_SPI_A7105_FLYSKY
Definition: cc2500_rx_spi.h:45
protocolInitFnPtr
bool(* protocolInitFnPtr)(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig)
Definition: cc2500_rx_spi.c:67
RX_SPI_FRSKY_X_LBT
@ RX_SPI_FRSKY_X_LBT
Definition: cc2500_rx_spi.h:50
protocolDataReceivedFnPtr
rx_spi_received_e(* protocolDataReceivedFnPtr)(uint8_t *payload)
Definition: cc2500_rx_spi.c:68
rxSpiProcessFrame
static bool rxSpiProcessFrame(const rxRuntimeConfig_t *rxRuntimeConfig)
Definition: cc2500_rx_spi.c:206
rxSpiReadRawRC
STATIC_UNIT_TESTED uint16_t rxSpiReadRawRC(const rxRuntimeConfig_t *rxRuntimeConfig, uint8_t channel)
Definition: cc2500_rx_spi.c:77
STATIC_UNIT_TESTED
#define STATIC_UNIT_TESTED
Definition: cc2500_compat.h:64
MAX_SUPPORTED_RC_CHANNEL_COUNT
#define MAX_SUPPORTED_RC_CHANNEL_COUNT
Definition: cc2500_rx.h:78
RX_FRAME_COMPLETE
@ RX_FRAME_COMPLETE
Definition: cc2500_rx.h:53
rxRuntimeConfig
rxRuntimeConfig_t rxRuntimeConfig
Definition: cc2500_rx.c:131
rxSpiRcData
uint16_t rxSpiRcData[MAX_SUPPORTED_RC_CHANNEL_COUNT]
Definition: cc2500_rx_spi.c:63
RX_SPI_NRF24_KN
@ RX_SPI_NRF24_KN
Definition: cc2500_rx_spi.h:47
frSkySpiSetRcData
void frSkySpiSetRcData(uint16_t *rcData, const uint8_t *payload)
Definition: cc2500_frsky_shared.c:407
rxSpiDeviceInit
#define rxSpiDeviceInit(rxSpiConfig)
Definition: cc2500_compat.h:189
cc2500_frsky_common.h
protocolDataReceived
static protocolDataReceivedFnPtr protocolDataReceived
Definition: cc2500_rx_spi.c:73
cc2500_settings.h
frSkySpiDataReceived
rx_spi_received_e frSkySpiDataReceived(uint8_t *packet)
Definition: cc2500_frsky_shared.c:327
rxRuntimeConfig_s::rxRefreshRate
uint16_t rxRefreshRate
Definition: cc2500_rx.h:146
RX_SPI_NRF24_SYMA_X
@ RX_SPI_NRF24_SYMA_X
Definition: cc2500_rx_spi.h:37
uint8_t
unsigned char uint8_t
Definition: types.h:14
rxRuntimeConfig_s::rcFrameStatusFn
rcFrameStatusFnPtr rcFrameStatusFn
Definition: cc2500_rx.h:148
RX_SPI_NRF24_CX10A
@ RX_SPI_NRF24_CX10A
Definition: cc2500_rx_spi.h:40
rxSpiConfig
const rxSpiConfig_t * rxSpiConfig(void)
Definition: cc2500_settings.c:87
protocolProcessFrameFnPtr
rx_spi_received_e(* protocolProcessFrameFnPtr)(uint8_t *payload)
Definition: cc2500_rx_spi.c:69
RX_SPI_RECEIVED_DATA
@ RX_SPI_RECEIVED_DATA
Definition: cc2500_rx_spi.h:57
RX_SPI_NRF24_V202_250K
@ RX_SPI_NRF24_V202_250K
Definition: cc2500_rx_spi.h:35
rxSpiPayload
STATIC_UNIT_TESTED uint8_t rxSpiPayload[RX_SPI_MAX_PAYLOAD_SIZE]
Definition: cc2500_rx_spi.c:64
rxRuntimeConfig_s::rcReadRawFn
rcReadRawDataFnPtr rcReadRawFn
Definition: cc2500_rx.h:147
rxSpiInit
bool rxSpiInit(const rxSpiConfig_t *rxSpiConfig, rxRuntimeConfig_t *rxRuntimeConfig)
Definition: cc2500_rx_spi.c:228
protocolInit
static protocolInitFnPtr protocolInit
Definition: cc2500_rx_spi.c:72
rxRuntimeConfig_s
Definition: cc2500_rx.h:142
rx_spi_protocol_e
rx_spi_protocol_e
Definition: cc2500_rx_spi.h:34
rxSpiNewPacketAvailable
STATIC_UNIT_TESTED uint8_t rxSpiNewPacketAvailable
Definition: cc2500_rx_spi.c:65
UNUSED
#define UNUSED(x)
Definition: cc2500_rx_spi.c:7
rxRuntimeConfig_s::channelCount
uint8_t channelCount
Definition: cc2500_rx.h:145
RX_FRAME_PENDING
@ RX_FRAME_PENDING
Definition: cc2500_rx.h:52
protocolProcessFrame
static protocolProcessFrameFnPtr protocolProcessFrame
Definition: cc2500_rx_spi.c:74
RX_SPI_CYRF6936_DSM
@ RX_SPI_CYRF6936_DSM
Definition: cc2500_rx_spi.h:49
RX_SPI_FRSKY_X
@ RX_SPI_FRSKY_X
Definition: cc2500_rx_spi.h:44
rx_spi_received_e
rx_spi_received_e
Definition: cc2500_rx_spi.h:54
RX_FRAME_PROCESSING_REQUIRED
@ RX_FRAME_PROCESSING_REQUIRED
Definition: cc2500_rx.h:55
rxSpiConfig_s
Definition: cc2500_settings.h:96
RX_SPI_A7105_FLYSKY_2A
@ RX_SPI_A7105_FLYSKY_2A
Definition: cc2500_rx_spi.h:46
RX_SPI_NRF24_H8_3D
@ RX_SPI_NRF24_H8_3D
Definition: cc2500_rx_spi.h:41
rxSpiFrameStatus
static uint8_t rxSpiFrameStatus(rxRuntimeConfig_t *rxRuntimeConfig)
Definition: cc2500_rx_spi.c:186
frSkySpiProcessFrame
rx_spi_received_e frSkySpiProcessFrame(uint8_t *packet)
Definition: cc2500_frsky_shared.c:398
cc2500_compat.h
RX_SPI_NRF24_V202_1M
@ RX_SPI_NRF24_V202_1M
Definition: cc2500_rx_spi.h:36
STATIC_ASSERT
#define STATIC_ASSERT(...)
Definition: cc2500_compat.h:63