Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ICM20789 #7477

Closed
wants to merge 14 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 14 additions & 9 deletions libraries/AP_Baro/examples/ICM20789/ICM20789.cpp
Expand Up @@ -13,7 +13,7 @@ const AP_HAL::HAL& hal = AP_HAL::get_HAL();

static AP_HAL::OwnPtr<AP_HAL::Device> i2c_dev;
static AP_HAL::OwnPtr<AP_HAL::Device> spi_dev;
static AP_HAL::OwnPtr<AP_HAL::Device> lidar_dev;
static AP_HAL::OwnPtr<AP_HAL::Device> dev;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting this to be removed, not just renamed.


// SPI registers
#define MPUREG_WHOAMI 0x75
Expand Down Expand Up @@ -215,7 +215,7 @@ static bool read_calibration_data(void)
// initialise baro on i2c
static void i2c_init(void)
{
if (!i2c_dev->get_semaphore()->take(0)) {
if (!i2c_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
AP_HAL::panic("Failed to get baro semaphore");
}

Expand All @@ -242,18 +242,18 @@ static void i2c_init(void)

i2c_dev->get_semaphore()->give();

printf("checking lidar\n");
if (!lidar_dev->get_semaphore()->take(0)) {
AP_HAL::panic("Failed to get lidar semaphore");
printf("checking baro\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Baro? How is dev the baro?

if (!dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
AP_HAL::panic("Failed to get device semaphore");
}

uint8_t regs[3] = { 0xC0, 0xC1, 0xC2 };
for (uint8_t i=0; i<ARRAY_SIZE(regs); i++) {
uint8_t v = 0;
lidar_dev->read_registers(regs[i], &v, 1);
dev->read_registers(regs[i], &v, 1);
printf("0x%02x : 0x%02x\n", regs[i], v);
}
lidar_dev->get_semaphore()->give();
dev->get_semaphore()->give();
}

void setup()
Expand All @@ -267,19 +267,24 @@ void setup()
#ifdef HAL_INS_MPU60x0_NAME
spi_dev = std::move(hal.spi->get_device(HAL_INS_MPU60x0_NAME));

if (!spi_dev->get_semaphore()->take(0)) {
if (!spi_dev->get_semaphore()->take(HAL_SEMAPHORE_BLOCK_FOREVER)) {
AP_HAL::panic("Failed to get spi semaphore");
}


i2c_dev = std::move(hal.i2c_mgr->get_device(1, 0x63));
lidar_dev = std::move(hal.i2c_mgr->get_device(1, 0x29));
dev = std::move(hal.i2c_mgr->get_device(1, 0x29));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The i2c_dev uses an address that is defined the ICM20789 baro driver, the dev / lidar_dev uses an address that is supposedly the VL53L0X. So how are both baro?


while (true) {
spi_init();
i2c_init();
hal.scheduler->delay(1000);
}
#else
while (true) {
printf("HAL_INS_MPU60x0_NAME not defined for this board\n");
hal.scheduler->delay(1000);
}
#endif
}

Expand Down