FIX CONFIG: BARO (#12476)
[betaflight.git] / src / main / drivers / light_led.c
blob6c15b34dcf25ce1c0cb061873c3f650c9062d1ff
1 /*
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)
8 * any later version.
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/>.
21 #include "platform.h"
23 #include "pg/pg_ids.h"
25 #include "drivers/io.h"
26 #include "io_impl.h"
28 #include "light_led.h"
30 PG_REGISTER_WITH_RESET_FN(statusLedConfig_t, statusLedConfig, PG_STATUS_LED_CONFIG, 0);
32 static IO_t leds[STATUS_LED_NUMBER];
33 static uint8_t ledInversion = 0;
35 #ifndef LED0_PIN
36 #define LED0_PIN NONE
37 #endif
39 #ifndef LED1_PIN
40 #define LED1_PIN NONE
41 #endif
43 #ifndef LED2_PIN
44 #define LED2_PIN NONE
45 #endif
47 void pgResetFn_statusLedConfig(statusLedConfig_t *statusLedConfig)
49 statusLedConfig->ioTags[0] = IO_TAG(LED0_PIN);
50 statusLedConfig->ioTags[1] = IO_TAG(LED1_PIN);
51 statusLedConfig->ioTags[2] = IO_TAG(LED2_PIN);
53 statusLedConfig->inversion = 0
54 #ifdef LED0_INVERTED
55 | BIT(0)
56 #endif
57 #ifdef LED1_INVERTED
58 | BIT(1)
59 #endif
60 #ifdef LED2_INVERTED
61 | BIT(2)
62 #endif
66 void ledInit(const statusLedConfig_t *statusLedConfig)
68 ledInversion = statusLedConfig->inversion;
69 for (int i = 0; i < STATUS_LED_NUMBER; i++) {
70 if (statusLedConfig->ioTags[i]) {
71 leds[i] = IOGetByTag(statusLedConfig->ioTags[i]);
72 IOInit(leds[i], OWNER_LED, RESOURCE_INDEX(i));
73 IOConfigGPIO(leds[i], IOCFG_OUT_PP);
74 } else {
75 leds[i] = IO_NONE;
79 LED0_OFF;
80 LED1_OFF;
81 LED2_OFF;
84 void ledToggle(int led)
86 IOToggle(leds[led]);
89 void ledSet(int led, bool on)
91 const bool inverted = (1 << (led)) & ledInversion;
92 IOWrite(leds[led], on ? inverted : !inverted);