]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/ergodox/ez/ez.c
Merge branch 'master' into to_push
[qmk_firmware.git] / keyboards / ergodox / ez / ez.c
1 #include "ez.h"
2 #include "i2cmaster.h"
3
4 bool i2c_initialized = 0;
5 uint8_t mcp23018_status = 0x20;
6
7 void matrix_init_kb(void) {
8    // keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md")
9     TCCR1A = 0b10101001;  // set and configure fast PWM
10     TCCR1B = 0b00001001;  // set and configure fast PWM
11
12     // (tied to Vcc for hardware convenience)
13     DDRB  &= ~(1<<4);  // set B(4) as input
14     PORTB &= ~(1<<4);  // set B(4) internal pull-up disabled
15
16     // unused pins - C7, D4, D5, D7, E6
17     // set as input with internal pull-ip enabled
18     DDRC  &= ~(1<<7);
19     DDRD  &= ~(1<<5 | 1<<4);
20     DDRE  &= ~(1<<6);
21     PORTC |=  (1<<7);
22     PORTD |=  (1<<5 | 1<<4);
23     PORTE |=  (1<<6);
24
25     ergodox_blink_all_leds();
26
27     matrix_init_user();
28 }
29
30 void ergodox_blink_all_leds(void)
31 {
32     ergodox_led_all_off();
33     ergodox_led_all_set(LED_BRIGHTNESS_HI);
34     ergodox_right_led_1_on();
35     _delay_ms(50);
36     ergodox_right_led_2_on();
37     _delay_ms(50);
38     ergodox_right_led_3_on();
39     _delay_ms(50);
40     ergodox_right_led_1_off();
41     _delay_ms(50);
42     ergodox_right_led_2_off();
43     _delay_ms(50);
44     ergodox_right_led_3_off();
45     //ergodox_led_all_on();
46     //_delay_ms(333);
47     ergodox_led_all_off();
48 }
49
50 uint8_t init_mcp23018(void) {
51     mcp23018_status = 0x20;
52
53     // I2C subsystem
54
55     // uint8_t sreg_prev;
56     // sreg_prev=SREG;
57     // cli();
58     if (i2c_initialized == 0) {
59         i2c_init();  // on pins D(1,0)
60         i2c_initialized++;
61         _delay_ms(1000);
62     }
63
64     // set pin direction
65     // - unused  : input  : 1
66     // - input   : input  : 1
67     // - driving : output : 0
68     mcp23018_status = i2c_start(I2C_ADDR_WRITE);    if (mcp23018_status) goto out;
69     mcp23018_status = i2c_write(IODIRA);            if (mcp23018_status) goto out;
70     mcp23018_status = i2c_write(0b00000000);        if (mcp23018_status) goto out;
71     mcp23018_status = i2c_write(0b00111111);        if (mcp23018_status) goto out;
72     i2c_stop();
73
74     // set pull-up
75     // - unused  : on  : 1
76     // - input   : on  : 1
77     // - driving : off : 0
78     mcp23018_status = i2c_start(I2C_ADDR_WRITE);    if (mcp23018_status) goto out;
79     mcp23018_status = i2c_write(GPPUA);             if (mcp23018_status) goto out;
80     mcp23018_status = i2c_write(0b00000000);        if (mcp23018_status) goto out;
81     mcp23018_status = i2c_write(0b00111111);        if (mcp23018_status) goto out;
82
83 out:
84     i2c_stop();
85
86     // SREG=sreg_prev;
87
88     return mcp23018_status;
89 }
90
91 #ifdef ONEHAND_ENABLE
92 __attribute__ ((weak))
93 // swap-hands action needs a matrix to define the swap
94 const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
95     /* Left hand, matrix positions */
96     {{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}},
97     {{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}},
98     {{0,11}, {1,11}, {2,11}, {3,11}, {4,11}, {5,11}},
99     {{0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}},
100     {{0,9}, {1,9}, {2,9}, {3,9}, {4,9}, {5,9}},
101     {{0,8}, {1,8}, {2,8}, {3,8}, {4,8}, {5,8}},
102     {{0,7}, {1,7}, {2,7}, {3,7}, {4,7}, {5,7}},
103     /* Right hand, matrix positions */
104     {{0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}},
105     {{0,5}, {1,5}, {2,5}, {3,5}, {4,5}, {5,5}},
106     {{0,4}, {1,4}, {2,4}, {3,4}, {4,4}, {5,4}},
107     {{0,3}, {1,3}, {2,3}, {3,3}, {4,3}, {5,3}},
108     {{0,2}, {1,2}, {2,2}, {3,2}, {4,2}, {5,2}},
109     {{0,1}, {1,1}, {2,1}, {3,1}, {4,1}, {5,1}},
110     {{0,0}, {1,0}, {2,0}, {3,0}, {4,0}, {5,0}},
111 };
112 #endif