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