From: Oleg Kostyuk Date: Thu, 17 Oct 2013 01:11:24 +0000 (+0300) Subject: Refactor mcp23018_status and give possibility to re-attach left side X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=33c4f039d1fa31f9cb2aac57b16bb6e532cd1b78;p=max%2Ftmk_keyboard.git Refactor mcp23018_status and give possibility to re-attach left side --- diff --git a/keyboard/ergodox/ergodox.c b/keyboard/ergodox/ergodox.c index c6a83148..494d13c1 100644 --- a/keyboard/ergodox/ergodox.c +++ b/keyboard/ergodox/ergodox.c @@ -38,6 +38,7 @@ Most used files are located at #include "i2cmaster.h" bool i2c_initialized = 0; +uint8_t mcp23018_status = 0x20; bool ergodox_left_led_1 = 0; // left top bool ergodox_left_led_2 = 0; // left middle @@ -74,7 +75,7 @@ void ergodox_blink_all_leds(void) } uint8_t init_mcp23018(void) { - uint8_t err = 0x20; + mcp23018_status = 0x20; // I2C subsystem if (i2c_initialized == 0) { @@ -87,48 +88,50 @@ uint8_t init_mcp23018(void) { // - unused : input : 1 // - input : input : 1 // - driving : output : 0 - err = i2c_start(I2C_ADDR_WRITE); if (err) goto out; - err = i2c_write(IODIRA); if (err) goto out; - err = i2c_write(0b00000000); if (err) goto out; - err = i2c_write(0b00111111); if (err) goto out; + mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(IODIRA); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out; i2c_stop(); // set pull-up // - unused : on : 1 // - input : on : 1 // - driving : off : 0 - err = i2c_start(I2C_ADDR_WRITE); if (err) goto out; - err = i2c_write(GPPUA); if (err) goto out; - err = i2c_write(0b00000000); if (err) goto out; - err = i2c_write(0b00111111); if (err) goto out; + mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(GPPUA); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00000000); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b00111111); if (mcp23018_status) goto out; out: i2c_stop(); - if (!err) err = ergodox_left_leds_update(); + if (!mcp23018_status) mcp23018_status = ergodox_left_leds_update(); - return err; + return mcp23018_status; } uint8_t ergodox_left_leds_update(void) { - uint8_t err = 0x20; + if (mcp23018_status) { // if there was an error + return mcp23018_status; + } // set logical value (doesn't matter on inputs) // - unused : hi-Z : 1 // - input : hi-Z : 1 // - driving : hi-Z : 1 - err = i2c_start(I2C_ADDR_WRITE); if (err) goto out; - err = i2c_write(OLATA); if (err) goto out; - err = i2c_write(0b11111111 + mcp23018_status = i2c_start(I2C_ADDR_WRITE); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(OLATA); if (mcp23018_status) goto out; + mcp23018_status = i2c_write(0b11111111 & ~(ergodox_left_led_3<