qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

ergotaco.c (1802B)


      1 #include "ergotaco.h"
      2 
      3 bool i2c_initialized = 0;
      4 i2c_status_t mcp23018_status = 0x20;
      5 
      6 void matrix_init_kb(void) {
      7     // (tied to Vcc for hardware convenience)
      8     //gpio_set_pin_input(B4);  // set B(4) as input, internal pull-up disabled
      9 
     10     // unused pins
     11     // set as input with internal pull-up enabled
     12     gpio_set_pin_input_high(B4);
     13     gpio_set_pin_input_high(B5);
     14     gpio_set_pin_input_high(B6);
     15     gpio_set_pin_input_high(B7);
     16 
     17     gpio_set_pin_input_high(C6);
     18     gpio_set_pin_input_high(C7);
     19 
     20     gpio_set_pin_input_high(D4);
     21     gpio_set_pin_input_high(D5);
     22     gpio_set_pin_input_high(D6);
     23     gpio_set_pin_input_high(D7);
     24 
     25     gpio_set_pin_input_high(E6);
     26 
     27     gpio_set_pin_input_high(D0);
     28     gpio_set_pin_input_high(D1);
     29     gpio_set_pin_input_high(D4);
     30     gpio_set_pin_input_high(D6);
     31     gpio_set_pin_input_high(D7);
     32 
     33     matrix_init_user();
     34 }
     35 
     36 
     37 uint8_t init_mcp23018(void) {
     38     print("starting init");
     39     mcp23018_status = 0x20;
     40 
     41     // I2C subsystem
     42 
     43     // uint8_t sreg_prev;
     44     // sreg_prev=SREG;
     45     // cli();
     46 
     47     if (i2c_initialized == 0) {
     48         i2c_init();  // on pins D(1,0)
     49         i2c_initialized = true;
     50         _delay_ms(1000);
     51     }
     52 
     53     // set pin direction
     54     // - unused  : input  : 1
     55     // - input   : input  : 1
     56     // - driving : output : 0
     57     uint8_t data[] = {0b00000000, 0b00111111};
     58     mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
     59 
     60     if (!mcp23018_status) {
     61         // set pull-up
     62         // - unused  : on  : 1
     63         // - input   : on  : 1
     64         // - driving : off : 0
     65         mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), ERGODOX_EZ_I2C_TIMEOUT);
     66     }
     67 
     68     // SREG=sreg_prev;
     69     //uprintf("Init %x\n", mcp23018_status);
     70     return mcp23018_status;
     71 }