1 #include QMK_KEYBOARD_H
5 extern inline void ergodox_board_led_on(void);
6 extern inline void ergodox_right_led_1_on(void);
7 extern inline void ergodox_right_led_2_on(void);
8 extern inline void ergodox_right_led_3_on(void);
9 extern inline void ergodox_right_led_on(uint8_t led);
11 extern inline void ergodox_board_led_off(void);
12 extern inline void ergodox_right_led_1_off(void);
13 extern inline void ergodox_right_led_2_off(void);
14 extern inline void ergodox_right_led_3_off(void);
15 extern inline void ergodox_right_led_off(uint8_t led);
17 extern inline void ergodox_led_all_on(void);
18 extern inline void ergodox_led_all_off(void);
20 extern inline void ergodox_right_led_1_set(uint8_t n);
21 extern inline void ergodox_right_led_2_set(uint8_t n);
22 extern inline void ergodox_right_led_3_set(uint8_t n);
23 extern inline void ergodox_right_led_set(uint8_t led, uint8_t n);
25 extern inline void ergodox_led_all_set(uint8_t n);
28 bool i2c_initialized = 0;
29 uint8_t mcp23018_status = 0x20;
31 void matrix_init_kb(void) {
32 // keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md")
33 TCCR1A = 0b10101001; // set and configure fast PWM
34 TCCR1B = 0b00001001; // set and configure fast PWM
36 // (tied to Vcc for hardware convenience)
37 DDRB &= ~(1<<4); // set B(4) as input
38 PORTB &= ~(1<<4); // set B(4) internal pull-up disabled
40 // unused pins - C7, D4, D5, D7, E6
41 // set as input with internal pull-ip enabled
43 DDRD &= ~(1<<5 | 1<<4);
46 PORTD |= (1<<5 | 1<<4);
49 ergodox_blink_all_leds();
54 void ergodox_blink_all_leds(void)
56 ergodox_led_all_off();
57 ergodox_led_all_set(LED_BRIGHTNESS_HI);
58 ergodox_right_led_1_on();
60 ergodox_right_led_2_on();
62 ergodox_right_led_3_on();
64 ergodox_right_led_1_off();
66 ergodox_right_led_2_off();
68 ergodox_right_led_3_off();
69 //ergodox_led_all_on();
71 ergodox_led_all_off();
74 uint8_t init_mcp23018(void) {
75 mcp23018_status = 0x20;
82 if (i2c_initialized == 0) {
83 i2c_init(); // on pins D(1,0)
84 i2c_initialized = true;
89 // - unused : input : 1
90 // - input : input : 1
91 // - driving : output : 0
92 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
93 mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out;
94 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
95 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
101 // - driving : off : 0
102 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
103 mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out;
104 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
105 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
112 return mcp23018_status;
115 #ifdef ONEHAND_ENABLE
116 __attribute__ ((weak))
117 // swap-hands action needs a matrix to define the swap
118 const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
119 /* Left hand, matrix positions */
120 {{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}},
121 {{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}},
122 {{0,11}, {1,11}, {2,11}, {3,11}, {4,11}, {5,11}},
123 {{0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}},
124 {{0,9}, {1,9}, {2,9}, {3,9}, {4,9}, {5,9}},
125 {{0,8}, {1,8}, {2,8}, {3,8}, {4,8}, {5,8}},
126 {{0,7}, {1,7}, {2,7}, {3,7}, {4,7}, {5,7}},
127 /* Right hand, matrix positions */
128 {{0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}},
129 {{0,5}, {1,5}, {2,5}, {3,5}, {4,5}, {5,5}},
130 {{0,4}, {1,4}, {2,4}, {3,4}, {4,4}, {5,4}},
131 {{0,3}, {1,3}, {2,3}, {3,3}, {4,3}, {5,3}},
132 {{0,2}, {1,2}, {2,2}, {3,2}, {4,2}, {5,2}},
133 {{0,1}, {1,1}, {2,1}, {3,1}, {4,1}, {5,1}},
134 {{0,0}, {1,0}, {2,0}, {3,0}, {4,0}, {5,0}},