Skip to content

Commit

Permalink
a failed attempt at hot-plugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ezuk committed May 24, 2018
1 parent 682555f commit c009571
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions keyboards/ergodox_ez/ergodox_ez.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,14 @@ uint8_t init_mcp23018(void) {
// uint8_t sreg_prev;
// sreg_prev=SREG;
// cli();
if (i2c_initialized == 0) {
i2c_init(); // on pins D(1,0)
i2c_initialized = true;
_delay_ms(1000);
}

// if (i2c_initialized == 0) {
// i2c_init(); // on pins D(1,0)
// i2c_initialized = true;
// _delay_ms(1000);
// }
i2c_init(); // on pins D(1,0)
_delay_ms(1000);

// set pin direction
// - unused : input : 1
Expand Down
6 changes: 4 additions & 2 deletions keyboards/ergodox_ez/matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ static void init_cols(void);
static void unselect_rows(void);
static void select_row(uint8_t row);

static uint8_t mcp23018_reset_loop;
// static uint8_t mcp23018_reset_loop;
static uint16_t mcp23018_reset_loop;

#ifdef DEBUG_MATRIX_SCAN_RATE
uint32_t matrix_timer;
Expand Down Expand Up @@ -175,7 +176,8 @@ void debounce_report(matrix_row_t change, uint8_t row) {
uint8_t matrix_scan(void)
{
if (mcp23018_status) { // if there was an error
if (++mcp23018_reset_loop == 0) {
// 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");
Expand Down

0 comments on commit c009571

Please sign in to comment.