Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
cc2500_rx_spi_common.c
Go to the documentation of this file.
1 #include "cc2500_compat.h"
2 
3 #include "cc2500_rx_spi_common.h"
4 
5 // betaflight/src/main/rx/rx_spi_common.c @ afb2bf5
6 /*
7  * This file is part of Cleanflight and Betaflight.
8  *
9  * Cleanflight and Betaflight are free software. You can redistribute
10  * this software and/or modify this software under the terms of the
11  * GNU General Public License as published by the Free Software
12  * Foundation, either version 3 of the License, or (at your option)
13  * any later version.
14  *
15  * Cleanflight and Betaflight are distributed in the hope that they
16  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  * See the GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this software.
22  *
23  * If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #include <stdbool.h>
27 #include <stdint.h>
28 
29 //#include "platform.h"
30 
31 #ifdef USE_RX_SPI
32 
33 //#include "drivers/io.h"
34 //#include "drivers/time.h"
35 //#include "rx/rx_spi_common.h"
36 //#include "rx/rx_spi.h"
37 
38 static IO_t ledPin;
39 static bool ledInversion = false;
40 
41 static IO_t bindPin;
42 static bool bindRequested;
43 static bool lastBindPinStatus;
44 
46 {
47  if (rxSpiConfig->ledIoTag) {
49  IOInit(ledPin, OWNER_LED, 0);
52  rxSpiLedOff();
53  } else {
54  ledPin = IO_NONE;
55  }
56 
57  if (rxSpiConfig->bindIoTag) {
62  } else {
63  bindPin = IO_NONE;
64  }
65 }
66 
67 void rxSpiLedOn(void)
68 {
69  if (ledPin) {
71  }
72 }
73 
74 void rxSpiLedOff(void)
75 {
76  if (ledPin) {
78  }
79 }
80 
81 void rxSpiLedToggle(void)
82 {
83  if (ledPin) {
85  }
86 }
87 
88 void rxSpiLedBlink(timeMs_t blinkMs)
89 {
90  static timeMs_t ledBlinkMs = 0;
91 
92  if ((ledBlinkMs + blinkMs) > millis()) {
93  return;
94  }
95  ledBlinkMs = millis();
96 
98 }
99 
101 {
102  static uint16_t rxLossCount = 0;
103 
104  if (ledPin) {
105  if (result == RX_SPI_RECEIVED_DATA) {
106  rxLossCount = 0;
107  rxSpiLedOn();
108  } else {
109  if (rxLossCount < RX_LOSS_COUNT) {
110  rxLossCount++;
111  } else {
113  }
114  }
115  }
116 }
117 
119 {
121 }
122 
123 void rxSpiBind(void)
124 {
125  bindRequested = true;
126 }
127 
129 {
130  if (bindPin) {
131  bool bindPinStatus = IORead(bindPin);
132  if (lastBindPinStatus && !bindPinStatus) {
133  bindRequested = true;
134  }
135  lastBindPinStatus = bindPinStatus;
136  }
137 
138  if (!bindRequested) {
139  return false;
140  } else {
141  if (reset) {
142  bindRequested = false;
143  }
144 
145  return true;
146  }
147 }
148 #endif
uint16_t
unsigned short uint16_t
Definition: types.h:16
lastBindPinStatus
static bool lastBindPinStatus
Definition: cc2500_rx_spi_common.c:43
IOCFG_OUT_PP
@ IOCFG_OUT_PP
Definition: cc2500_compat.h:216
millis
#define millis()
Definition: cc2500_compat.h:176
bindPin
static IO_t bindPin
Definition: cc2500_rx_spi_common.c:41
rxSpiConfig_s::ledInversion
uint8_t ledInversion
Definition: cc2500_settings.h:109
bindRequested
static bool bindRequested
Definition: cc2500_rx_spi_common.c:42
rxSpiLedBlinkRxLoss
void rxSpiLedBlinkRxLoss(rx_spi_received_e result)
Definition: cc2500_rx_spi_common.c:100
IO_NONE
#define IO_NONE
Definition: cc2500_compat.h:207
rxSpiCheckBindRequested
bool rxSpiCheckBindRequested(bool reset)
Definition: cc2500_rx_spi_common.c:128
OWNER_LED
@ OWNER_LED
Definition: cc2500_compat.h:262
rxSpiCommonIOInit
void rxSpiCommonIOInit(const rxSpiConfig_t *rxSpiConfig)
Definition: cc2500_rx_spi_common.c:45
rxSpiBind
void rxSpiBind(void)
Definition: cc2500_rx_spi_common.c:123
IORead
#define IORead(gpio)
Definition: cc2500_compat.h:224
IOLo
#define IOLo(io)
Definition: cc2500_compat.h:229
rxSpiLedToggle
void rxSpiLedToggle(void)
Definition: cc2500_rx_spi_common.c:81
rxSpiLedOff
void rxSpiLedOff(void)
Definition: cc2500_rx_spi_common.c:74
rxSpiConfig_s::bindIoTag
ioTag_t bindIoTag
Definition: cc2500_settings.h:107
rxSpiLedBlinkBind
void rxSpiLedBlinkBind(void)
Definition: cc2500_rx_spi_common.c:118
IOHi
#define IOHi(io)
Definition: cc2500_compat.h:227
IOCFG_IPU
@ IOCFG_IPU
Definition: cc2500_compat.h:218
rxSpiConfig
const rxSpiConfig_t * rxSpiConfig(void)
Definition: cc2500_settings.c:87
INTERVAL_RX_LOSS_MS
#define INTERVAL_RX_LOSS_MS
Definition: cc2500_rx_spi_common.h:30
RX_SPI_RECEIVED_DATA
@ RX_SPI_RECEIVED_DATA
Definition: cc2500_rx_spi.h:57
IOToggle
#define IOToggle(io)
Definition: cc2500_compat.h:231
rxSpiLedOn
void rxSpiLedOn(void)
Definition: cc2500_rx_spi_common.c:67
gpio_t
Definition: cc2500_compat.h:199
IOInit
#define IOInit(io, owner, index)
Definition: cc2500_compat.h:213
IOConfigGPIO
#define IOConfigGPIO(io, cfg)
Definition: cc2500_compat.h:221
rxSpiConfig_s::ledIoTag
ioTag_t ledIoTag
Definition: cc2500_settings.h:108
reset
void reset(void)
ledPin
static IO_t ledPin
Definition: cc2500_rx_spi_common.c:38
INTERVAL_RX_BIND_MS
#define INTERVAL_RX_BIND_MS
Definition: cc2500_rx_spi_common.h:31
RX_LOSS_COUNT
#define RX_LOSS_COUNT
Definition: cc2500_rx_spi_common.h:32
OWNER_RX_SPI_BIND
@ OWNER_RX_SPI_BIND
Definition: cc2500_compat.h:261
ledInversion
static bool ledInversion
Definition: cc2500_rx_spi_common.c:39
rx_spi_received_e
rx_spi_received_e
Definition: cc2500_rx_spi.h:54
cc2500_rx_spi_common.h
rxSpiConfig_s
Definition: cc2500_settings.h:96
rxSpiLedBlink
void rxSpiLedBlink(timeMs_t blinkMs)
Definition: cc2500_rx_spi_common.c:88
cc2500_compat.h
timeMs_t
uint32_t timeMs_t
Definition: cc2500_compat.h:92
IOGetByTag
#define IOGetByTag(io)
Definition: cc2500_compat.h:210