BV I2C: use i2c_master_slave_read and print_xxd in dump8
This commit is contained in:
parent
a404e5ffc4
commit
c5dfa4371e
|
@ -15,7 +15,7 @@
|
|||
/** BusVoodoo I²C mode (code)
|
||||
* @file busvoodoo_i2c.c
|
||||
* @author King Kévin <kingkevin@cuvoodoo.info>
|
||||
* @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 */
|
||||
|
|
Loading…
Reference in New Issue