#include "util.h"
#include "matrix.h"
#include QMK_KEYBOARD_H
-#include "i2cmaster.h"
#ifdef DEBUG_MATRIX_SCAN_RATE
#include "timer.h"
#endif
static void select_row(uint8_t row);
static uint8_t mcp23018_reset_loop;
+// static uint16_t mcp23018_reset_loop;
#ifdef DEBUG_MATRIX_SCAN_RATE
uint32_t matrix_timer;
{
if (mcp23018_status) { // if there was an error
if (++mcp23018_reset_loop == 0) {
+ // if (++mcp23018_reset_loop >= 1300) {
// since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
// this will be approx bit more frequent than once per second
print("trying to reset mcp23018\n");
return 0;
} else {
uint8_t data = 0;
- mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPIOB); if (mcp23018_status) goto out;
- mcp23018_status = i2c_start(I2C_ADDR_READ); if (mcp23018_status) goto out;
- data = i2c_readNak();
- data = ~data;
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, 0); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(GPIOB, 0); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_start(I2C_ADDR_READ, 0); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_read_nack(0); if (mcp23018_status < 0) goto out;
+ data = ~((uint8_t)mcp23018_status);
out:
- i2c_stop();
+ i2c_stop(0);
return data;
}
} else {
*/
static void unselect_rows(void)
{
- // unselect on mcp23018
- if (mcp23018_status) { // if there was an error
- // do nothing
- } else {
- // set all rows hi-Z : 1
- mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0xFF); if (mcp23018_status) goto out;
- out:
- i2c_stop();
- }
+ // no need to unselect on mcp23018, because the select step sets all
+ // the other row bits high, and it's not changing to a different
+ // direction
// unselect on teensy
// Hi-Z(DDR:0, PORT:0) to unselect
} else {
// set active row low : 0
// set other rows hi-Z : 1
- mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(GPIOA); if (mcp23018_status) goto out;
- mcp23018_status = i2c_write(0xFF & ~(1<<row)); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_start(I2C_ADDR_WRITE, 0); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(GPIOA, 0); if (mcp23018_status) goto out;
+ mcp23018_status = i2c_write(0xFF & ~(1<<row), 0); if (mcp23018_status) goto out;
out:
- i2c_stop();
+ i2c_stop(0);
}
} else {
// select on teensy