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.

97 lines
2.7 KiB

  1. #ifdef ISSI_ENABLE
  2. #include <avr/sfr_defs.h>
  3. #include <avr/timer_avr.h>
  4. #include <avr/wdt.h>
  5. #include "meira.h"
  6. #include "issi.h"
  7. #include "TWIlib.h"
  8. #include "lighting.h"
  9. #include "debug.h"
  10. #include "audio.h"
  11. const uint8_t backlight_pwm_map[BACKLIGHT_LEVELS] = BACKLIGHT_PWM_MAP;
  12. const uint8_t switch_matrices[] = {0, 1};
  13. // Maps switch LEDs from Row/Col to ISSI matrix.
  14. // Value breakdown:
  15. // Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  16. // | | ISSI Col | ISSI Row |
  17. // / |
  18. // Device
  19. // const uint8_t switch_leds[MATRIX_ROWS][MATRIX_COLS] =
  20. // KEYMAP(
  21. // 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0xA9, 0xA8, 0xA7, 0xA6, 0xA5,
  22. // 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0xB9, 0xB8, 0xB7, 0xB6, 0xB5,
  23. // 0x49, 0x48, 0x47, 0x45, 0x44, 0x43, 0x42, 0x41, 0xC9, 0xC8, 0xC7, 0xC6,
  24. // 0x59, 0x58, 0x57, 0x56, 0x55, 0x51, 0xD6, 0xE5, 0xE4, 0xE3, 0xE2);
  25. void backlight_set(uint8_t level){
  26. #ifdef BACKLIGHT_ENABLE
  27. uint8_t pwm_value = 0;
  28. if(level >= BACKLIGHT_LEVELS){
  29. level = BACKLIGHT_LEVELS;
  30. }
  31. if(level > 0){
  32. pwm_value = backlight_pwm_map[level-1];
  33. }
  34. xprintf("BACKLIGHT_LEVELS: %d\n", BACKLIGHT_LEVELS);
  35. xprintf("backlight_set level: %d pwm: %d\n", level, pwm_value);
  36. for(int x = 1; x <= 9; x++){
  37. for(int y = 1; y <= 9; y++){
  38. activateLED(switch_matrices[0], x, y, pwm_value);
  39. activateLED(switch_matrices[1], x, y, pwm_value);
  40. }
  41. }
  42. #endif
  43. }
  44. void set_backlight_by_keymap(uint8_t col, uint8_t row){
  45. // dprintf("LED: %02X, %d %d %d\n", lookup_value, matrix, led_col, led_row);
  46. // activateLED(matrix, led_col, led_row, 255);
  47. }
  48. void force_issi_refresh(){
  49. issi_devices[0]->led_dirty = true;
  50. update_issi(0, true);
  51. issi_devices[3]->led_dirty = true;
  52. update_issi(3, true);
  53. }
  54. void led_test(){
  55. #ifdef WATCHDOG_ENABLE
  56. // This test take a long time to run, disable the WTD until its complete
  57. wdt_disable();
  58. #endif
  59. backlight_set(0);
  60. force_issi_refresh();
  61. // for(uint8_t x = 0; x < sizeof(rgb_sequence); x++){
  62. // set_rgb(rgb_sequence[x], 255, 0, 0);
  63. // force_issi_refresh();
  64. // _delay_ms(250);
  65. // set_rgb(rgb_sequence[x], 0, 255, 0);
  66. // force_issi_refresh();
  67. // _delay_ms(250);
  68. // set_rgb(rgb_sequence[x], 0, 0, 255);
  69. // force_issi_refresh();
  70. // _delay_ms(250);
  71. // set_rgb(rgb_sequence[x], 0, 0, 0);
  72. // force_issi_refresh();
  73. // }
  74. #ifdef WATCHDOG_ENABLE
  75. wdt_enable(WDTO_250MS);
  76. #endif
  77. }
  78. void backlight_init_ports(void){
  79. xprintf("backlight_init_ports\n");
  80. issi_init();
  81. }
  82. #endif