feat(voxl2): Added i2cdetect system command to voxl2-slpi build. Needed to implement the required i2c API for it.

Also, changed the printf into PX4_INFO so the output can be seen for Qurt platforms.
This commit is contained in:
Eric Katzfey
2026-04-08 08:52:25 -07:00
committed by Eric Katzfey
parent c0633d89ff
commit 4917b17116
7 changed files with 212 additions and 12 deletions
+4 -2
View File
@@ -158,10 +158,12 @@ out:
}
void
I2C::set_device_address(int address)
I2C::set_device_address(int address, bool log)
{
if ((_i2c_fd != PX4_ERROR) && (_set_i2c_address != NULL)) {
PX4_INFO("Set i2c address 0x%x, fd %d", address, _i2c_fd);
if (log) {
PX4_INFO("Set i2c address 0x%x, fd %d", address, _i2c_fd);
}
pthread_mutex_lock(_mutex);
_set_i2c_address(_i2c_fd, address);
+1 -1
View File
@@ -103,7 +103,7 @@ protected:
*/
virtual int probe() { return PX4_OK; }
virtual void set_device_address(int address);
virtual void set_device_address(int address, bool log = true);
/**
* Perform an I2C transaction to the device.
+10 -8
View File
@@ -50,7 +50,7 @@ namespace i2cdetect
int detect(int bus)
{
printf("Scanning I2C bus: %d\n", bus);
PX4_INFO("Scanning I2C bus: %d", bus);
int ret = PX4_ERROR;
@@ -62,15 +62,17 @@ int detect(int bus)
return PX4_ERROR;
}
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
// Line buffer for building up output
char line[80];
int pos = 0;
PX4_INFO(" 0 1 2 3 4 5 6 7 8 9 a b c d e f");
for (int i = 0; i < 128; i += 16) {
printf("%02x: ", i);
pos = snprintf(line, sizeof(line), "%02x: ", i);
for (int j = 0; j < 16; j++) {
fflush(stdout);
uint8_t addr = i + j;
unsigned retry_count = 0;
@@ -115,14 +117,14 @@ int detect(int bus)
} while (retry_count++ < retries);
if (found) {
printf("%02x ", addr);
pos += snprintf(line + pos, sizeof(line) - pos, "%02x ", addr);
} else {
printf("-- ");
pos += snprintf(line + pos, sizeof(line) - pos, "-- ");
}
}
printf("\n");
PX4_INFO("%s", line);
}
px4_i2cbus_uninitialize(i2c_dev);