format src/systemcmds/i2c

This commit is contained in:
Daniel Agar 2015-09-05 12:21:11 -04:00
parent 2c95a905c4
commit 329ff0e036
1 changed files with 11 additions and 5 deletions

View File

@ -75,21 +75,25 @@ int i2c_main(int argc, char *argv[])
/* find the right I2C */
i2c = up_i2cinitialize(PX4_I2C_BUS_ONBOARD);
if (i2c == NULL)
if (i2c == NULL) {
errx(1, "failed to locate I2C bus");
}
usleep(100000);
uint8_t buf[] = { 0, 4};
int ret = transfer(PX4_I2C_OBDEV_PX4IO, buf, sizeof(buf), NULL, 0);
if (ret)
if (ret) {
errx(1, "send failed - %d", ret);
}
uint32_t val;
ret = transfer(PX4_I2C_OBDEV_PX4IO, NULL, 0, (uint8_t *)&val, sizeof(val));
if (ret)
if (ret) {
errx(1, "recive failed - %d", ret);
}
errx(0, "got 0x%08x", val);
}
@ -121,8 +125,9 @@ transfer(uint8_t address, uint8_t *send, unsigned send_len, uint8_t *recv, unsig
msgs++;
}
if (msgs == 0)
if (msgs == 0) {
return -1;
}
/*
* I2C architecture means there is an unavoidable race here
@ -133,8 +138,9 @@ transfer(uint8_t address, uint8_t *send, unsigned send_len, uint8_t *recv, unsig
ret = I2C_TRANSFER(i2c, &msgv[0], msgs);
// reset the I2C bus to unwedge on error
if (ret != OK)
if (ret != OK) {
up_i2creset(i2c);
}
return ret;
}