Add flag to invert output of twi_error()
This is only for convinience for the eye to be able to print "debugging" information not inverted.
This commit is contained in:
parent
2beecbe722
commit
144da8d7f2
1 changed files with 19 additions and 16 deletions
|
@ -335,21 +335,24 @@ static void lcd_splash(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void twi_error(void) {
|
static void twi_error(bool inverted) {
|
||||||
lcd_fill(0xFF);
|
if (inverted)
|
||||||
|
lcd_fill(0xFF);
|
||||||
|
else
|
||||||
|
lcd_fill(0x00);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
lcd_move_cursor(0, i);
|
lcd_move_cursor(0, i);
|
||||||
lcd_write_string_page("TW_STATUS:\0", i, true);
|
lcd_write_string_page("TW_STATUS:\0", i, inverted);
|
||||||
lcd_write_kerning(2, true);
|
lcd_write_kerning(2, inverted);
|
||||||
lcd_write_integer_page(TW_STATUS, 3, i, true);
|
lcd_write_integer_page(TW_STATUS, 3, i, inverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 2; i++) {
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
lcd_move_cursor(0, i + 2);
|
lcd_move_cursor(0, i + 2);
|
||||||
lcd_write_string_page("TW_DATA:\0", i, true);
|
lcd_write_string_page("TW_DATA:\0", i, inverted);
|
||||||
lcd_write_kerning(16, true);
|
lcd_write_kerning(16, inverted);
|
||||||
lcd_write_integer_page(TWDR, 3, i, true);
|
lcd_write_integer_page(TWDR, 3, i, inverted);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;);
|
for (;;);
|
||||||
|
@ -360,7 +363,7 @@ static void twi_start(void) {
|
||||||
while (!(TWCR & (1 << TWINT))); // Wait until start is transmitted
|
while (!(TWCR & (1 << TWINT))); // Wait until start is transmitted
|
||||||
|
|
||||||
if (TW_STATUS != TW_START) // Check status
|
if (TW_STATUS != TW_START) // Check status
|
||||||
twi_error();
|
twi_error(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t twi_transmit(const uint8_t data) {
|
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) {
|
const uint8_t reg) {
|
||||||
twi_start();
|
twi_start();
|
||||||
|
|
||||||
twi_error();
|
|
||||||
if (twi_transmit(address << 1) != TW_MT_SLA_ACK)
|
if (twi_transmit(address << 1) != TW_MT_SLA_ACK)
|
||||||
|
twi_error(true);
|
||||||
|
|
||||||
if (twi_transmit(reg) != TW_MT_DATA_ACK)
|
if (twi_transmit(reg) != TW_MT_DATA_ACK)
|
||||||
twi_error();
|
twi_error(true);
|
||||||
|
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
|
@ -398,11 +401,11 @@ static uint8_t twi_read_register(const uint8_t address,
|
||||||
|
|
||||||
twi_start();
|
twi_start();
|
||||||
|
|
||||||
twi_error();
|
|
||||||
if (twi_transmit((address << 1) + 1) != TW_MR_SLA_ACK)
|
if (twi_transmit((address << 1) + 1) != TW_MR_SLA_ACK)
|
||||||
|
twi_error(true);
|
||||||
|
|
||||||
if (twi_receive() != TW_MR_DATA_NACK)
|
if (twi_receive() != TW_MR_DATA_NACK)
|
||||||
twi_error();
|
twi_error(true);
|
||||||
|
|
||||||
twi_stop();
|
twi_stop();
|
||||||
|
|
||||||
|
@ -414,14 +417,14 @@ static void twi_write_register(const uint8_t address,
|
||||||
const uint8_t data) {
|
const uint8_t data) {
|
||||||
twi_start();
|
twi_start();
|
||||||
|
|
||||||
twi_error();
|
|
||||||
if (twi_transmit(address << 1) != TW_MT_SLA_ACK)
|
if (twi_transmit(address << 1) != TW_MT_SLA_ACK)
|
||||||
|
twi_error(true);
|
||||||
|
|
||||||
if (twi_transmit(reg) != TW_MT_DATA_ACK)
|
if (twi_transmit(reg) != TW_MT_DATA_ACK)
|
||||||
twi_error();
|
twi_error(true);
|
||||||
|
|
||||||
if (twi_transmit(data) != TW_MT_DATA_ACK)
|
if (twi_transmit(data) != TW_MT_DATA_ACK)
|
||||||
twi_error();
|
twi_error(true);
|
||||||
|
|
||||||
twi_stop();
|
twi_stop();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue