From c5dfa4371e810ea343d140866cba63ea19827b33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Wed, 27 Mar 2019 19:09:36 +0100 Subject: [PATCH] BV I2C: use i2c_master_slave_read and print_xxd in dump8 --- lib/busvoodoo_i2c.c | 48 +++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/lib/busvoodoo_i2c.c b/lib/busvoodoo_i2c.c index 8779215..6743ca5 100644 --- a/lib/busvoodoo_i2c.c +++ b/lib/busvoodoo_i2c.c @@ -15,7 +15,7 @@ /** BusVoodoo I²C mode (code) * @file busvoodoo_i2c.c * @author King Kévin - * @date 2018 + * @date 2018-2019 * @note peripherals used: I2C @ref busvoodoo_i2c */ /* standard libraries */ @@ -591,38 +591,26 @@ static void busvoodoo_i2c_command_dump8(void* argument) uint16_t address = *(uint32_t*)argument; // use argument as device address printf("reading bytes from 8-bit memory device at I2C address "); // display explanation printf((busvoodoo_i2c_addressbits > 7) ? "%+03x\n" : "%+02x\n", address); // display address - bool rc = (I2C_MASTER_RC_NONE == i2c_master_start(BUSVOODOO_I2C)); // send start condition - printf("start condition: %s\n", rc ? "sent" : "error"); - if (!rc) { + + uint8_t memory_address = 0; + if (I2C_MASTER_RC_NONE != i2c_master_slave_write(BUSVOODOO_I2C, address, busvoodoo_i2c_addressbits > 7, &memory_address, 1)) { + busvoodoo_text_style(BUSVOODOO_TEXT_STYLE_ERROR); + printf("writing memory address failed\n"); // show error to user + busvoodoo_text_style(BUSVOODOO_TEXT_STYLE_WARNING); + printf("use actions to debug communication\n"); // show solution + busvoodoo_text_style(BUSVOODOO_TEXT_STYLE_RESET); return; } - rc = busvoodoo_i2c_select(address, true); // select device to write address - if (!rc) { - goto error; + uint8_t memory_data[256]; + if (I2C_MASTER_RC_NONE != i2c_master_slave_read(BUSVOODOO_I2C, address, busvoodoo_i2c_addressbits > 7, memory_data, LENGTH(memory_data))) { + busvoodoo_text_style(BUSVOODOO_TEXT_STYLE_ERROR); + printf("reading memory data failed\n"); // show error to user + busvoodoo_text_style(BUSVOODOO_TEXT_STYLE_WARNING); + printf("use actions to debug communication\n"); // show solution + busvoodoo_text_style(BUSVOODOO_TEXT_STYLE_RESET); + return; } - rc = busvoodoo_i2c_write(0); // write start address - if (!rc) { - goto error; - } - rc = (I2C_MASTER_RC_NONE == i2c_master_start(BUSVOODOO_I2C)); // send start condition - printf("re-start condition: %s\n", rc ? "sent" : "error"); - if (!rc) { - goto error; - } - rc = busvoodoo_i2c_select(address, false); // select device to write address - if (!rc) { - goto error; - } - rc = busvoodoo_i2c_read(256); // read bytes - if (!rc) { - goto error; - } - rc = (I2C_MASTER_RC_NONE == i2c_master_stop(BUSVOODOO_I2C)); // send start condition - printf("stop condition: %s\n", rc ? "sent" : "error"); - - return; -error: - i2c_master_stop(BUSVOODOO_I2C); // send transaction + print_xxd(0, memory_data, LENGTH(memory_data)); } /** I2C menu commands */