led.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright 2015 Jun Wako <wakojun@gmail.com>
  3. Copyright 2017 jpetermans <tibcmhhm@gmail.com>
  4. This program 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 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "hal.h"
  16. #include "led.h"
  17. #include "led_controller.h"
  18. /* WARNING! This function needs to be callable from
  19. * both regular threads and ISRs, unlocked (during resume-from-sleep).
  20. * In particular, I2C functions (interrupt-driven) should NOT be called from here.
  21. */
  22. void led_set(uint8_t usb_led) {
  23. msg_t msg;
  24. if (usb_led & (1<<USB_LED_NUM_LOCK)) {
  25. chSysUnconditionalLock();
  26. msg=(1 << 8) | TOGGLE_NUM_LOCK;
  27. chMBPostI(&led_mailbox, msg);
  28. chSysUnconditionalUnlock();
  29. } else {
  30. chSysUnconditionalLock();
  31. msg=(0 << 8) | TOGGLE_NUM_LOCK;
  32. chMBPostI(&led_mailbox, msg);
  33. chSysUnconditionalUnlock();
  34. }
  35. if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
  36. chSysUnconditionalLock();
  37. msg=(1 << 8) | TOGGLE_CAPS_LOCK;
  38. chMBPostI(&led_mailbox, msg);
  39. chSysUnconditionalUnlock();
  40. } else {
  41. chSysUnconditionalLock();
  42. msg=(0 << 8) | TOGGLE_CAPS_LOCK;
  43. chMBPostI(&led_mailbox, msg);
  44. chSysUnconditionalUnlock();
  45. }
  46. }