4 bool i2c_initialized = 0;
5 uint8_t mcp23018_status = 0x20;
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
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
16 // unused pins - C7, D4, D5, D7, E6
17 // set as input with internal pull-ip enabled
19 DDRD &= ~(1<<7 | 1<<5 | 1<<4);
22 PORTD |= (1<<7 | 1<<5 | 1<<4);
25 ergodox_blink_all_leds();
30 void ergodox_blink_all_leds(void)
32 ergodox_led_all_off();
33 ergodox_led_all_set(LED_BRIGHTNESS_HI);
34 ergodox_right_led_1_on();
36 ergodox_right_led_2_on();
38 ergodox_right_led_3_on();
40 ergodox_right_led_1_off();
42 ergodox_right_led_2_off();
44 ergodox_right_led_3_off();
45 //ergodox_led_all_on();
47 ergodox_led_all_off();
50 uint8_t init_mcp23018(void) {
51 mcp23018_status = 0x20;
54 if (i2c_initialized == 0) {
55 i2c_init(); // on pins D(1,0)
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;
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;
82 return mcp23018_status;
87 __attribute__ ((weak))
88 // swap-hands action needs a matrix to define the swap
89 const keypos_t hand_swap_config[MATRIX_ROWS][MATRIX_COLS] = {
90 /* Left hand, matrix positions */
91 {{0,13}, {1,13}, {2,13}, {3,13}, {4,13}, {5,13}},
92 {{0,12}, {1,12}, {2,12}, {3,12}, {4,12}, {5,12}},
93 {{0,11}, {1,11}, {2,11}, {3,11}, {4,11}, {5,11}},
94 {{0,10}, {1,10}, {2,10}, {3,10}, {4,10}, {5,10}},
95 {{0,9}, {1,9}, {2,9}, {3,9}, {4,9}, {5,9}},
96 {{0,8}, {1,8}, {2,8}, {3,8}, {4,8}, {5,8}},
97 {{0,7}, {1,7}, {2,7}, {3,7}, {4,7}, {5,7}},
98 /* Right hand, matrix positions */
99 {{0,6}, {1,6}, {2,6}, {3,6}, {4,6}, {5,6}},
100 {{0,5}, {1,5}, {2,5}, {3,5}, {4,5}, {5,5}},
101 {{0,4}, {1,4}, {2,4}, {3,4}, {4,4}, {5,4}},
102 {{0,3}, {1,3}, {2,3}, {3,3}, {4,3}, {5,3}},
103 {{0,2}, {1,2}, {2,2}, {3,2}, {4,2}, {5,2}},
104 {{0,1}, {1,1}, {2,1}, {3,1}, {4,1}, {5,1}},
105 {{0,0}, {1,0}, {2,0}, {3,0}, {4,0}, {5,0}},