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/>.
20 #include "build/debug.h"
21 #include "drivers/io.h"
24 #include "drivers/light_led.h"
26 static const IO_t leds
[] = {
42 #if defined(LED0_A) || defined(LED1_A) || defined(LED2_A)
61 uint8_t ledPolarity
= 0
71 #ifdef LED0_A_INVERTED
74 #ifdef LED1_A_INVERTED
77 #ifdef LED2_A_INVERTED
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
;
91 UNUSED(alternative_led
);
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
);
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
);