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"
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;
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
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
);
84 void ledToggle(int led
)
89 void ledSet(int led
, bool on
)
91 const bool inverted
= (1 << (led
)) & ledInversion
;
92 IOWrite(leds
[led
], on
? inverted
: !inverted
);