2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
28 #include "drivers/io.h"
29 #include "drivers/time.h"
31 #include "rx/rx_spi.h"
33 #include "rx_spi_common.h"
36 static bool ledInversion
= false;
39 static bool bindRequested
;
40 static bool lastBindPinStatus
;
42 void rxSpiCommonIOInit(const rxSpiConfig_t
*rxSpiConfig
)
44 if (rxSpiConfig
->ledIoTag
) {
45 ledPin
= IOGetByTag(rxSpiConfig
->ledIoTag
);
46 IOInit(ledPin
, OWNER_LED
, 0);
47 IOConfigGPIO(ledPin
, IOCFG_OUT_PP
);
48 ledInversion
= rxSpiConfig
->ledInversion
;
54 if (rxSpiConfig
->bindIoTag
) {
55 bindPin
= IOGetByTag(rxSpiConfig
->bindIoTag
);
56 IOInit(bindPin
, OWNER_RX_SPI_BIND
, 0);
57 IOConfigGPIO(bindPin
, IOCFG_IPU
);
58 lastBindPinStatus
= IORead(bindPin
);
67 ledInversion
? IOLo(ledPin
) : IOHi(ledPin
);
71 void rxSpiLedOff(void)
74 ledInversion
? IOHi(ledPin
) : IOLo(ledPin
);
78 void rxSpiLedToggle(void)
85 void rxSpiLedBlink(timeMs_t blinkMs
)
87 static timeMs_t ledBlinkMs
= 0;
89 if ((ledBlinkMs
+ blinkMs
) > millis()) {
92 ledBlinkMs
= millis();
97 void rxSpiLedBlinkRxLoss(rx_spi_received_e result
)
99 static timeMs_t rxLossMs
= 0;
102 if (result
== RX_SPI_RECEIVED_DATA
) {
105 if ((rxLossMs
+ INTERVAL_RX_LOSS_MS
) > millis()) {
114 void rxSpiLedBlinkBind(void)
116 rxSpiLedBlink(INTERVAL_RX_BIND_MS
);
121 bindRequested
= true;
124 bool rxSpiCheckBindRequested(bool reset
)
127 bool bindPinStatus
= IORead(bindPin
);
128 if (lastBindPinStatus
&& !bindPinStatus
) {
129 bindRequested
= true;
131 lastBindPinStatus
= bindPinStatus
;
134 if (!bindRequested
) {
138 bindRequested
= false;