]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/ergodox/ez/ez.c
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
[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<<7 | 1<<5 | 1<<4);
20     DDRE  &= ~(1<<6);
21     PORTC |=  (1<<7);
22     PORTD |=  (1<<7 | 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     if (i2c_initialized == 0) {
55         i2c_init();  // on pins D(1,0)
56         i2c_initialized++;
57         _delay_ms(1000);
58     }
59
60     // set pin direction
61     // - unused  : input  : 1
62     // - input   : input  : 1
63     // - driving : output : 0
64     mcp23018_status = i2c_start(I2C_ADDR_WRITE);    if (mcp23018_status) goto out;
65     mcp23018_status = i2c_write(IODIRA);            if (mcp23018_status) goto out;
66     mcp23018_status = i2c_write(0b00000000);        if (mcp23018_status) goto out;
67     mcp23018_status = i2c_write(0b00111111);        if (mcp23018_status) goto out;
68     i2c_stop();
69
70     // set pull-up
71     // - unused  : on  : 1
72     // - input   : on  : 1
73     // - driving : off : 0
74     mcp23018_status = i2c_start(I2C_ADDR_WRITE);    if (mcp23018_status) goto out;
75     mcp23018_status = i2c_write(GPPUA);             if (mcp23018_status) goto out;
76     mcp23018_status = i2c_write(0b00000000);        if (mcp23018_status) goto out;
77     mcp23018_status = i2c_write(0b00111111);        if (mcp23018_status) goto out;
78
79 out:
80     i2c_stop();
81
82     return mcp23018_status;
83 }
84
85 #ifdef ONEHAND_ENABLE
86 __attribute__ ((weak))
87 // swap-hands action needs a matrix to define the swap
88 const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
89     /* Left hand, matrix positions */
90     {{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}},
91     {{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}},
92     {{0,11}, {1,11}, {2,11}, {3,11}, {4,11}, {5,11}},
93     {{0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}},
94     {{0,9}, {1,9}, {2,9}, {3,9}, {4,9}, {5,9}},
95     {{0,8}, {1,8}, {2,8}, {3,8}, {4,8}, {5,8}},
96     {{0,7}, {1,7}, {2,7}, {3,7}, {4,7}, {5,7}},
97     /* Right hand, matrix positions */
98     {{0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}},
99     {{0,5}, {1,5}, {2,5}, {3,5}, {4,5}, {5,5}},
100     {{0,4}, {1,4}, {2,4}, {3,4}, {4,4}, {5,4}},
101     {{0,3}, {1,3}, {2,3}, {3,3}, {4,3}, {5,3}},
102     {{0,2}, {1,2}, {2,2}, {3,2}, {4,2}, {5,2}},
103     {{0,1}, {1,1}, {2,1}, {3,1}, {4,1}, {5,1}},
104     {{0,0}, {1,0}, {2,0}, {3,0}, {4,0}, {5,0}},
105 };
106 #endif