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 "drivers/io.h"
23 #include "drivers/light_led.h"
25 static const IO_t leds
[] = {
41 #if defined(LED0_A) || defined(LED1_A) || defined(LED2_A)
60 uint8_t ledPolarity
= 0
70 #ifdef LED0_A_INVERTED
73 #ifdef LED1_A_INVERTED
76 #ifdef LED2_A_INVERTED
81 static uint8_t ledOffset
= 0;
83 void ledInit(bool alternative_led
)
85 #if defined(LED0_A) || defined(LED1_A) || defined(LED2_A)
86 if (alternative_led
) {
87 ledOffset
= LED_NUMBER
;
90 UNUSED(alternative_led
);
97 for (int i
= 0; i
< LED_NUMBER
; i
++) {
98 if (leds
[i
+ ledOffset
]) {
99 IOInit(leds
[i
+ ledOffset
], OWNER_LED
, RESOURCE_OUTPUT
, RESOURCE_INDEX(i
));
100 IOConfigGPIO(leds
[i
+ ledOffset
], IOCFG_OUT_PP
);
109 void ledToggle(int led
)
111 IOToggle(leds
[led
+ ledOffset
]);
114 void ledSet(int led
, bool on
)
116 const bool inverted
= (1 << (led
+ ledOffset
)) & ledPolarity
;
117 IOWrite(leds
[led
+ ledOffset
], on
? inverted
: !inverted
);