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();
40 void matrix_scan_kb(void) {
45 void ergodox_blink_all_leds(void)
47 ergodox_led_all_off();
48 ergodox_led_all_set(LED_BRIGHTNESS_HI);
49 ergodox_right_led_1_on();
51 ergodox_right_led_2_on();
53 ergodox_right_led_3_on();
55 ergodox_right_led_1_off();
57 ergodox_right_led_2_off();
59 ergodox_right_led_3_off();
60 //ergodox_led_all_on();
62 ergodox_led_all_off();
65 uint8_t init_mcp23018(void) {
66 mcp23018_status = 0x20;
69 if (i2c_initialized == 0) {
70 i2c_init(); // on pins D(1,0)
76 // - unused : input : 1
77 // - input : input : 1
78 // - driving : output : 0
79 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
80 mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out;
81 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
82 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
88 // - driving : off : 0
89 mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
90 mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out;
91 mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out;
92 mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out;
97 return mcp23018_status;