Paparazzi UAS  v7.0_unstable
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
static uint8_t reset[3]
Definition: baro_MS5534A.c:83
@ IOCFG_IPU
@ IOCFG_OUT_PP
#define IOHi(io)
#define IOInit(io, owner, index)
uint32_t timeMs_t
Definition: cc2500_compat.h:92
#define IOGetByTag(io)
@ OWNER_RX_SPI_BIND
@ OWNER_LED
#define IO_NONE
#define IORead(gpio)
#define IOLo(io)
#define IOConfigGPIO(io, cfg)
#define millis()
#define IOToggle(io)
rx_spi_received_e
Definition: cc2500_rx_spi.h:54
@ RX_SPI_RECEIVED_DATA
Definition: cc2500_rx_spi.h:57
static bool lastBindPinStatus
void rxSpiLedOn(void)
void rxSpiLedOff(void)
static bool bindRequested
static bool ledInversion
static IO_t ledPin
void rxSpiLedBlinkRxLoss(rx_spi_received_e result)
void rxSpiBind(void)
void rxSpiLedToggle(void)
void rxSpiCommonIOInit(const rxSpiConfig_t *rxSpiConfig)
void rxSpiLedBlinkBind(void)
static IO_t bindPin
void rxSpiLedBlink(timeMs_t blinkMs)
bool rxSpiCheckBindRequested(bool reset)
#define INTERVAL_RX_LOSS_MS
#define INTERVAL_RX_BIND_MS
#define RX_LOSS_COUNT
const rxSpiConfig_t * rxSpiConfig(void)
uint8_t ledInversion
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88