gergoplex.c (1621B)
1 /* Copyright 2021 Jane Bernhardt 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #include "gergoplex.h" 18 19 bool i2c_initialized = 0; 20 i2c_status_t mcp23018_status = 0x20; 21 22 void matrix_init_kb(void) { 23 matrix_init_user(); 24 } 25 26 uint8_t init_mcp23018(void) { 27 print("starting init"); 28 mcp23018_status = 0x20; 29 30 // I2C subsystem 31 32 if (i2c_initialized == 0) { 33 i2c_init(); // on pins D(1,0) 34 i2c_initialized = true; 35 _delay_ms(1000); 36 } 37 38 // set pin direction 39 // - unused : input : 1 40 // - input : input : 1 41 // - driving : output : 0 42 uint8_t data[] = {0b11000001, 0b11111111}; 43 mcp23018_status = i2c_write_register(I2C_ADDR, IODIRA, data, sizeof(data), I2C_TIMEOUT); 44 45 if (!mcp23018_status) { 46 // set pull-up 47 // - unused : on : 1 48 // - input : on : 1 49 // - driving : off : 0 50 mcp23018_status = i2c_write_register(I2C_ADDR, GPPUA, data, sizeof(data), I2C_TIMEOUT); 51 } 52 53 return mcp23018_status; 54 }