/* Copyright 2016 Kai Ryu This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "action.h" #include "i2cmaster.h" #include "expander.h" #include "debug.h" static uint8_t expander_status = 0; static uint8_t expander_input = 0; void expander_config(void); uint8_t expander_write(uint8_t reg, uint8_t data); uint8_t expander_read(uint8_t reg, uint8_t *data); void expander_init(void) { i2c_init(); expander_scan(); } void expander_scan(void) { dprintf("expander status: %d ... ", expander_status); uint8_t ret = i2c_start(EXPANDER_ADDR | I2C_WRITE); if (ret == 0) { i2c_stop(); if (expander_status == 0) { dprintf("attached\n"); expander_status = 1; expander_config(); clear_keyboard(); } } else { if (expander_status == 1) { dprintf("detached\n"); expander_status = 0; clear_keyboard(); } } dprintf("%d\n", expander_status); } void expander_read_cols(void) { expander_read(EXPANDER_REG_GPIOA, &expander_input); } uint8_t expander_get_col(uint8_t col) { if (col > 4) { col++; } return expander_input & (1<