Add 'x' command (bus reset) to C common header and i2ccl.

[#30]
This commit is contained in:
James Bowman 2020-01-21 10:37:51 -08:00
parent 036902b032
commit 23b12eec6e
1 changed files with 19 additions and 0 deletions

View File

@ -312,6 +312,15 @@ void i2c_scan(I2CDriver *sd, uint8_t devices[128])
(void)readFromSerialPort(sd->port, devices + 8, 112);
}
uint8_t i2c_reset(I2CDriver *sd)
{
charCommand(sd, 'x');
uint8_t a[1];
if (readFromSerialPort(sd->port, a, 1) != 1)
return 0;
return a[0];
}
int i2c_start(I2CDriver *sd, uint8_t dev, uint8_t op)
{
uint8_t start[2] = {'s', (dev << 1) | op};
@ -382,6 +391,15 @@ int i2c_commands(I2CDriver *sd, int argc, char *argv[])
);
break;
case 'x':
{
uint8_t sda_scl = i2c_reset(sd);
printf("Bus reset. SDA = %d, SCL = %d\n",
1 & (sda_scl >> 1),
1 & sda_scl);
}
break;
case 'd':
{
uint8_t devices[128];
@ -468,6 +486,7 @@ int i2c_commands(I2CDriver *sd, int argc, char *argv[])
fprintf(stderr, "Commands are:");
fprintf(stderr, "\n");
fprintf(stderr, " i display status information (uptime, voltage, current, temperature)\n");
fprintf(stderr, " x I2C bus reset\n");
fprintf(stderr, " d device scan\n");
fprintf(stderr, " w dev <bytes> write bytes to I2C device dev\n");
fprintf(stderr, " p send a STOP\n");