Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / drivers / light_led.c
blobc353e2072a2519be79d6705e53b75b22fedf0f06
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include "platform.h"
20 #include "build/debug.h"
21 #include "drivers/io.h"
22 #include "io_impl.h"
24 #include "drivers/light_led.h"
26 static const IO_t leds[] = {
27 #ifdef LED0
28 DEFIO_IO(LED0),
29 #else
30 DEFIO_IO(NONE),
31 #endif
32 #ifdef LED1
33 DEFIO_IO(LED1),
34 #else
35 DEFIO_IO(NONE),
36 #endif
37 #ifdef LED2
38 DEFIO_IO(LED2),
39 #else
40 DEFIO_IO(NONE),
41 #endif
42 #if defined(LED0_A) || defined(LED1_A) || defined(LED2_A)
43 #ifdef LED0_A
44 DEFIO_IO(LED0_A),
45 #else
46 DEFIO_IO(NONE),
47 #endif
48 #ifdef LED1_A
49 DEFIO_IO(LED1_A),
50 #else
51 DEFIO_IO(NONE),
52 #endif
53 #ifdef LED2_A
54 DEFIO_IO(LED2_A),
55 #else
56 DEFIO_IO(NONE),
57 #endif
58 #endif
61 uint8_t ledPolarity = 0
62 #ifdef LED0_INVERTED
63 | BIT(0)
64 #endif
65 #ifdef LED1_INVERTED
66 | BIT(1)
67 #endif
68 #ifdef LED2_INVERTED
69 | BIT(2)
70 #endif
71 #ifdef LED0_A_INVERTED
72 | BIT(3)
73 #endif
74 #ifdef LED1_A_INVERTED
75 | BIT(4)
76 #endif
77 #ifdef LED2_A_INVERTED
78 | BIT(5)
79 #endif
82 static uint8_t ledOffset = 0;
84 void ledInit(bool alternative_led)
86 #if defined(LED0_A) || defined(LED1_A) || defined(LED2_A)
87 if (alternative_led) {
88 ledOffset = LED_NUMBER;
90 #else
91 UNUSED(alternative_led);
92 #endif
94 LED0_OFF;
95 LED1_OFF;
96 LED2_OFF;
98 for (int i = 0; i < LED_NUMBER; i++) {
99 if (leds[i + ledOffset]) {
100 IOInit(leds[i + ledOffset], OWNER_LED, RESOURCE_OUTPUT, RESOURCE_INDEX(i));
101 IOConfigGPIO(leds[i + ledOffset], IOCFG_OUT_PP);
105 LED0_OFF;
106 LED1_OFF;
107 LED2_OFF;
110 void ledToggle(int led)
112 IOToggle(leds[led + ledOffset]);
115 void ledSet(int led, bool on)
117 const bool inverted = (1 << (led + ledOffset)) & ledPolarity;
118 IOWrite(leds[led + ledOffset], on ? inverted : !inverted);