1 #include "ergodox_ez.h"
4 bool i2c_initialized = 0;
5 uint8_t mcp23018_status = 0x20;
8 void * matrix_init_user(void) {
12 __attribute__ ((weak))
13 void * matrix_scan_user(void) {
17 void * matrix_init_kb(void) {
18 // keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md")
19 TCCR1A = 0b10101001; // set and configure fast PWM
20 TCCR1B = 0b00001001; // set and configure fast PWM
22 // (tied to Vcc for hardware convenience)
23 DDRB &= ~(1<<4); // set B(4) as input
24 PORTB &= ~(1<<4); // set B(4) internal pull-up disabled
26 // unused pins - C7, D4, D5, D7, E6
27 // set as input with internal pull-ip enabled
29 DDRD &= ~(1<<7 | 1<<5 | 1<<4);
32 PORTD |= (1<<7 | 1<<5 | 1<<4);
35 ergodox_blink_all_leds();
37 if (matrix_init_user) {
38 (*matrix_init_user)();
44 void * matrix_scan_kb(void) {
46 if (matrix_scan_user) {
47 (*matrix_scan_user)();
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;
78 if (i2c_initialized == 0) {
79 i2c_init(); // on pins D(1,0)
85 // - unused : input : 1
86 // - input : input : 1
87 // - driving : output : 0
88 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
89 mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out;
90 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
91 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
97 // - driving : off : 0
98 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
99 mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out;
100 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
101 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
106 return mcp23018_status;