I'll put this in a pull request with some of these helper test functions
later, but I'm just starting to poke at a manufacturing test app that
can be used to validate all the pins, etc.
This will scan the entire I2C bus for devices, which is always a useful
sanity check before working on drivers, following the Linux 'i2cdetect'
model:
static int
shell_i2cscan_cmd(int argc, char **argv)
{
uint8_t addr;
int32_t timeout = OS_TICKS_PER_SEC / 10
uint8_t dev_count = 0;
console_printf("Scanning I2C bus 0\n"
" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n"
"00: ");
/* Scan all valid I2C addresses (0x03..0x77) */
for (addr = 0x03; addr < 0x78; addr++) {
int rc = hal_i2c_master_probe(0, addr, timeout);
if (!(addr % 16)) {
console_printf("\n%02x: ", addr);
}
if (!rc) {
console_printf("%02x ", addr);
dev_count++;
} else {
console_printf("-- ");
}
}
console_printf("\nFound %u devices on I2C bus 0\n", dev_count);
return 0;
}
This results in the following output on the shell:
5594:Scanning I2C bus 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1f
20: -- 21 -- -- -- -- -- -- -- 29 -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
Found 4 devices on I2C bus 0
My question is ... is there a way to optionally suppress the tick
counter on 'console_printf' calls for individual instances???
It might get in the way of formatting output with multiple printf lines.
I had to limit the number of times I used console_printf to avoid the
tick counter messing the output up.
K.