2 Copyright 2015 Jun Wako <wakojun@gmail.com>
3 Copyright 2017 jpetermans <tibcmhhm@gmail.com>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "led_controller.h"
25 /* WARNING! This function needs to be callable from
26 * both regular threads and ISRs, unlocked (during resume-from-sleep).
27 * In particular, I2C functions (interrupt-driven) should NOT be called from here.
29 void led_set(uint8_t usb_led) {
32 if (usb_led & (1<<USB_LED_NUM_LOCK)) {
33 chSysUnconditionalLock();
34 msg=(1 << 8) | TOGGLE_NUM_LOCK;
35 chMBPostI(&led_mailbox, msg);
36 chSysUnconditionalUnlock();
38 chSysUnconditionalLock();
39 msg=(0 << 8) | TOGGLE_NUM_LOCK;
40 chMBPostI(&led_mailbox, msg);
41 chSysUnconditionalUnlock();
43 if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
44 chSysUnconditionalLock();
45 msg=(1 << 8) | TOGGLE_CAPS_LOCK;
46 chMBPostI(&led_mailbox, msg);
47 chSysUnconditionalUnlock();
49 chSysUnconditionalLock();
50 msg=(0 << 8) | TOGGLE_CAPS_LOCK;
51 chMBPostI(&led_mailbox, msg);
52 chSysUnconditionalUnlock();