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_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) {
48  ledPin = IOGetByTag(rxSpiConfig->ledIoTag);
49  IOInit(ledPin, OWNER_LED, 0);
50  IOConfigGPIO(ledPin, IOCFG_OUT_PP);
51  ledInversion = rxSpiConfig->ledInversion;
52  rxSpiLedOff();
53  } else {
54  ledPin = IO_NONE;
55  }
56 
57  if (rxSpiConfig->bindIoTag) {
58  bindPin = IOGetByTag(rxSpiConfig->bindIoTag);
59  IOInit(bindPin, OWNER_RX_SPI_BIND, 0);
60  IOConfigGPIO(bindPin, IOCFG_IPU);
61  lastBindPinStatus = IORead(bindPin);
62  } else {
63  bindPin = IO_NONE;
64  }
65 }
66 
67 void rxSpiLedOn(void)
68 {
69  if (ledPin) {
70  ledInversion ? IOLo(ledPin) : IOHi(ledPin);
71  }
72 }
73 
74 void rxSpiLedOff(void)
75 {
76  if (ledPin) {
77  ledInversion ? IOHi(ledPin) : IOLo(ledPin);
78  }
79 }
80 
81 void rxSpiLedToggle(void)
82 {
83  if (ledPin) {
84  IOToggle(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 IO_t ledPin
#define IOHi(io)
const rxSpiConfig_t * rxSpiConfig(void)
void rxSpiBind(void)
void rxSpiLedBlinkRxLoss(rx_spi_received_e result)
#define IOToggle(io)
void rxSpiLedBlink(timeMs_t blinkMs)
#define INTERVAL_RX_LOSS_MS
rx_spi_received_e
Definition: cc2500_rx_spi.h:54
uint8_t ledInversion
#define IOLo(io)
#define IOInit(io, owner, index)
#define IOGetByTag(io)
uint32_t timeMs_t
Definition: cc2500_compat.h:92
#define RX_LOSS_COUNT
#define IO_NONE
static uint8_t reset[3]
Definition: baro_MS5534A.c:83
#define IORead(gpio)
#define INTERVAL_RX_BIND_MS
#define IOConfigGPIO(io, cfg)
void rxSpiLedBlinkBind(void)
static bool lastBindPinStatus
static IO_t bindPin
void rxSpiLedOn(void)
#define millis()
static bool bindRequested
bool rxSpiCheckBindRequested(bool reset)
void rxSpiLedOff(void)
void rxSpiCommonIOInit(const rxSpiConfig_t *rxSpiConfig)
void rxSpiLedToggle(void)
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
static bool ledInversion