led.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Copyright 2012 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "hal.h"
  15. #include "led.h"
  16. void led_set(uint8_t usb_led) {
  17. // The LCD backlight functionality conflicts with this simple
  18. // red backlight
  19. #if !defined(LCD_BACKLIGHT_ENABLE) && defined(STATUS_LED_ENABLE)
  20. // PTC1: LCD Backlight Red(0:on/1:off)
  21. GPIOC->PDDR |= (1<<1);
  22. PORTC->PCR[1] |= PORTx_PCRn_DSE | PORTx_PCRn_MUX(1);
  23. if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
  24. GPIOC->PCOR |= (1<<1);
  25. } else {
  26. GPIOC->PSOR |= (1<<1);
  27. }
  28. #elif !defined(LCD_BACKLIGHT_ENABLE)
  29. (void)usb_led;
  30. GPIOC->PDDR |= (1<<1);
  31. PORTC->PCR[1] |= PORTx_PCRn_DSE | PORTx_PCRn_MUX(1);
  32. GPIOC->PSOR |= (1<<1);
  33. GPIOC->PDDR |= (1<<2);
  34. PORTC->PCR[2] |= PORTx_PCRn_DSE | PORTx_PCRn_MUX(1);
  35. GPIOC->PSOR |= (1<<2);
  36. GPIOC->PDDR |= (1<<3);
  37. PORTC->PCR[3] |= PORTx_PCRn_DSE | PORTx_PCRn_MUX(1);
  38. GPIOC->PSOR |= (1<<3);
  39. #else
  40. (void)usb_led;
  41. #endif
  42. }