diff --git a/firmware/src/main.c b/firmware/src/main.c index d51eb62..6c4379d 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -335,21 +335,24 @@ static void lcd_splash(void) { } } -static void twi_error(void) { - lcd_fill(0xFF); +static void twi_error(bool inverted) { + if (inverted) + lcd_fill(0xFF); + else + lcd_fill(0x00); for (uint8_t i = 0; i < 2; i++) { lcd_move_cursor(0, i); - lcd_write_string_page("TW_STATUS:\0", i, true); - lcd_write_kerning(2, true); - lcd_write_integer_page(TW_STATUS, 3, i, true); + lcd_write_string_page("TW_STATUS:\0", i, inverted); + lcd_write_kerning(2, inverted); + lcd_write_integer_page(TW_STATUS, 3, i, inverted); } for (uint8_t i = 0; i < 2; i++) { lcd_move_cursor(0, i + 2); - lcd_write_string_page("TW_DATA:\0", i, true); - lcd_write_kerning(16, true); - lcd_write_integer_page(TWDR, 3, i, true); + lcd_write_string_page("TW_DATA:\0", i, inverted); + lcd_write_kerning(16, inverted); + lcd_write_integer_page(TWDR, 3, i, inverted); } for (;;); @@ -360,7 +363,7 @@ static void twi_start(void) { while (!(TWCR & (1 << TWINT))); // Wait until start is transmitted if (TW_STATUS != TW_START) // Check status - twi_error(); + twi_error(true); } static uint8_t twi_transmit(const uint8_t data) { @@ -386,11 +389,11 @@ static uint8_t twi_read_register(const uint8_t address, const uint8_t reg) { twi_start(); - twi_error(); if (twi_transmit(address << 1) != TW_MT_SLA_ACK) + twi_error(true); if (twi_transmit(reg) != TW_MT_DATA_ACK) - twi_error(); + twi_error(true); twi_stop(); @@ -398,11 +401,11 @@ static uint8_t twi_read_register(const uint8_t address, twi_start(); - twi_error(); if (twi_transmit((address << 1) + 1) != TW_MR_SLA_ACK) + twi_error(true); if (twi_receive() != TW_MR_DATA_NACK) - twi_error(); + twi_error(true); twi_stop(); @@ -414,14 +417,14 @@ static void twi_write_register(const uint8_t address, const uint8_t data) { twi_start(); - twi_error(); if (twi_transmit(address << 1) != TW_MT_SLA_ACK) + twi_error(true); if (twi_transmit(reg) != TW_MT_DATA_ACK) - twi_error(); + twi_error(true); if (twi_transmit(data) != TW_MT_DATA_ACK) - twi_error(); + twi_error(true); twi_stop(); }