BV I2C: add bus error checks
This commit is contained in:
parent
ebcaf5723e
commit
e5b9d0fd85
|
@ -170,6 +170,9 @@ static void busvoodoo_i2c_read(void)
|
|||
case I2C_MASTER_RC_NOT_RECEIVE:
|
||||
printf("not in receive mode");
|
||||
break;
|
||||
case I2C_MASTER_RC_BUS_ERROR:
|
||||
printf("error detected on bus (flush I2C peripheral to correct)");
|
||||
break;
|
||||
default:
|
||||
printf("error");
|
||||
}
|
||||
|
@ -199,6 +202,9 @@ static void busvoodoo_i2c_write(uint8_t data)
|
|||
case I2C_MASTER_RC_NOT_TRANSMIT:
|
||||
printf("not in transmit mode");
|
||||
break;
|
||||
case I2C_MASTER_RC_BUS_ERROR:
|
||||
printf("error detected on bus (flush I2C peripheral to correct)");
|
||||
break;
|
||||
default:
|
||||
printf("error");
|
||||
}
|
||||
|
@ -235,6 +241,9 @@ static void busvoodoo_i2c_select(uint16_t slave, bool write)
|
|||
case I2C_MASTER_RC_NOT_TRANSMIT:
|
||||
printf("not in transmit mode");
|
||||
break;
|
||||
case I2C_MASTER_RC_BUS_ERROR:
|
||||
printf("error detected on bus (flush I2C peripheral to correct)");
|
||||
break;
|
||||
default:
|
||||
printf("error");
|
||||
}
|
||||
|
@ -386,6 +395,18 @@ static bool busvoodoo_i2c_action(const char* action, uint32_t repetition, bool p
|
|||
|
||||
// command handlers
|
||||
|
||||
/** command to reset I2C peripheral
|
||||
* @param[in] argument no argument required
|
||||
*/
|
||||
static void busvoodoo_i2c_command_reset(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
|
||||
i2c_master_setup(BUSVOODOO_I2C, busvoodoo_i2c_speed); // re-setup I2C
|
||||
printf("I2C peripheral reset\n");
|
||||
}
|
||||
|
||||
|
||||
/** command to perform actions
|
||||
* @param[in] argument actions to perform
|
||||
*/
|
||||
|
@ -448,29 +469,31 @@ static void busvoodoo_i2c_command_scan(void* argument)
|
|||
i2c_slaves++; // increase slave count
|
||||
break;
|
||||
case I2C_MASTER_RC_START_STOP_IN_PROGESS: // I2C peripheral error
|
||||
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
|
||||
printf("start condition failed\n"); // show error to user
|
||||
led_blink(0.5, 0.5); // show error on LEDs
|
||||
i2c_slaves = -2; // remember error
|
||||
break; // stop scanning
|
||||
case I2C_MASTER_RC_NOT_MASTER: // start condition failed
|
||||
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
|
||||
printf("start condition failed\n"); // show error to user
|
||||
led_blink(0.5, 0.5); // show error on LEDs
|
||||
i2c_slaves = -1; // remember error
|
||||
break; // stop scanning
|
||||
case I2C_MASTER_RC_NAK: // slave did not respond
|
||||
break; // nothing to do
|
||||
case I2C_MASTER_RC_BUS_ERROR:
|
||||
printf("error detected on bus\n");
|
||||
i2c_slaves = -2; // remember error
|
||||
break;
|
||||
default: // unexpected error
|
||||
printf("error occurred\n");
|
||||
i2c_slaves = -1; // remember error
|
||||
break;
|
||||
}
|
||||
if (i2c_slaves<0) { // error happend
|
||||
if (i2c_slaves<0) { // error happened
|
||||
led_blink(0.5, 0.5); // show error on LEDs
|
||||
if (-1==i2c_slaves) { // just end communication
|
||||
i2c_master_stop(BUSVOODOO_I2C); // send stop condition
|
||||
} else if (-2==i2c_slaves) { // reset peripheral
|
||||
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
|
||||
busvoodoo_i2c_command_reset(NULL);
|
||||
}
|
||||
break; // stop scan
|
||||
} else {
|
||||
|
@ -493,6 +516,14 @@ static void busvoodoo_i2c_command_scan(void* argument)
|
|||
|
||||
/** I2C menu commands */
|
||||
static const struct menu_command_t busvoodoo_i2c_commands[] = {
|
||||
{
|
||||
'f',
|
||||
"flush",
|
||||
"flush I2C peripheral",
|
||||
MENU_ARGUMENT_NONE,
|
||||
NULL,
|
||||
&busvoodoo_i2c_command_reset,
|
||||
},
|
||||
{
|
||||
'a',
|
||||
"action",
|
||||
|
|
Loading…
Reference in New Issue