You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

ledmap.c 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. Copyright 2014 Kai Ryu <[email protected]>
  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 <avr/pgmspace.h>
  15. #include "ledmap.h"
  16. #ifdef LEDMAP_ENABLE
  17. static const uint16_t ledmaps[LED_COUNT] PROGMEM = {
  18. [0] = LEDMAP_CAPS_LOCK, // CapsLock - PB2
  19. [1] = LEDMAP_BACKLIGHT, // PWM - PB7
  20. };
  21. ledmap_t ledmap_get_code(uint8_t index)
  22. {
  23. return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) };
  24. }
  25. void ledmap_led_init(void)
  26. {
  27. DDRB |= (1<<PB2 | 1<<PB7);
  28. PORTB |= (1<<PB2);
  29. PORTB &= ~(1<<PB7);
  30. }
  31. void ledmap_led_on(uint8_t index)
  32. {
  33. switch (index) {
  34. case 0:
  35. PORTB &= ~(1<<PB2);
  36. break;
  37. case 1:
  38. PORTB |= (1<<PB7);
  39. break;
  40. }
  41. }
  42. void ledmap_led_off(uint8_t index)
  43. {
  44. switch (index) {
  45. case 0:
  46. PORTB |= (1<<PB2);
  47. break;
  48. case 1:
  49. PORTB &= ~(1<<PB7);
  50. break;
  51. }
  52. }
  53. #endif