Support detaching & re-attaching the expander

Partly addresses #5. We still need to gracefully handle when the expander is not
coming back.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/427/head^2
Gergely Nagy 7 years ago
parent bbc38e7120
commit f8726905ea

@ -92,6 +92,8 @@ void ErgoDox::readMatrixRow(uint8_t row) {
void ErgoDox::readMatrix() {
do_scan_ = false;
scanner_.reattachExpanderOnError();
for (uint8_t row = 0; row < ROWS / 2; row++) {
scanner_.selectRow(row);
scanner_.selectRow(row + ROWS / 2);

@ -45,11 +45,7 @@ namespace hardware {
uint8_t ErgoDoxScanner::initExpander() {
uint8_t status = 0x20;
if (i2c_initialized_ == false) {
i2c_init();
i2c_initialized_ = true;
_delay_ms(1000);
}
i2c_init();
status = i2c_start(I2C_ADDR_WRITE);
if (status)
@ -187,5 +183,18 @@ out:
}
}
void
ErgoDoxScanner::reattachExpanderOnError() {
static uint8_t attach_counter;
if (!expander_error_)
return;
if (attach_counter++ != 0)
return;
expander_error_ = initExpander();
}
}
}

@ -40,8 +40,9 @@ class ErgoDoxScanner {
void unselectRows();
uint8_t readCols(int row);
void reattachExpanderOnError();
private:
bool i2c_initialized_ = false;
uint8_t expander_error_ = 0x20;
uint8_t initExpander();

Loading…
Cancel
Save