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/>.
23 #include "pg/pg_ids.h"
25 #include "drivers/io.h"
26 #include "drivers/io_impl.h"
28 #include "light_led.h"
30 #if !(defined(UNIT_TEST) || defined(USE_VIRTUAL_LED))
32 PG_REGISTER_WITH_RESET_FN(statusLedConfig_t
, statusLedConfig
, PG_STATUS_LED_CONFIG
, 0);
34 static IO_t leds
[STATUS_LED_NUMBER
];
35 static uint8_t ledInversion
= 0;
49 void pgResetFn_statusLedConfig(statusLedConfig_t
*statusLedConfig
)
51 statusLedConfig
->ioTags
[0] = IO_TAG(LED0_PIN
);
52 statusLedConfig
->ioTags
[1] = IO_TAG(LED1_PIN
);
53 statusLedConfig
->ioTags
[2] = IO_TAG(LED2_PIN
);
55 statusLedConfig
->inversion
= 0
68 void ledInit(const statusLedConfig_t
*statusLedConfig
)
70 ledInversion
= statusLedConfig
->inversion
;
71 for (int i
= 0; i
< STATUS_LED_NUMBER
; i
++) {
72 if (statusLedConfig
->ioTags
[i
]) {
73 leds
[i
] = IOGetByTag(statusLedConfig
->ioTags
[i
]);
74 IOInit(leds
[i
], OWNER_LED
, RESOURCE_INDEX(i
));
75 IOConfigGPIO(leds
[i
], IOCFG_OUT_PP
);
86 void ledToggle(int led
)
91 void ledSet(int led
, bool on
)
93 const bool inverted
= (1 << (led
)) & ledInversion
;
94 IOWrite(leds
[led
], on
? inverted
: !inverted
);