Skip to content

Commit

Permalink
lis2mdl: fix read (betaflight#14227)
Browse files Browse the repository at this point in the history
* lis2mdl: revert reading status register, use measure/collect paradigm

* Update src/main/drivers/compass/compass_lis2mdl.c

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>

* fix typo

* fixed borked logic

---------

Co-authored-by: Mark Haslinghuis <mark@numloq.nl>
  • Loading branch information
dakejahl and haslinghuis authored Feb 4, 2025
1 parent f2e9dac commit 896bf03
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/main/drivers/compass/compass_lis2mdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,15 @@ static bool lis2mdlInit(magDev_t *mag)

static bool lis2mdlRead(magDev_t *mag, int16_t *magData)
{
uint8_t status = 0;
uint8_t buf[6];
static uint8_t buf[6];
static bool pendingRead = true;

extDevice_t *dev = &mag->dev;

if (!busReadRegisterBuffer(dev, LIS2MDL_ADDR_STATUS_REG, &status, sizeof(status))) {
return false;
}

if (!(status & LIS2MDL_STATUS_REG_READY)) {
return false;
}

if (!busReadRegisterBuffer(dev, LIS2MDL_ADDR_OUTX_L_REG, (uint8_t *)&buf, sizeof(buf))) {
if (pendingRead) {
if (busReadRegisterBufferStart(dev, LIS2MDL_ADDR_OUTX_L_REG, (uint8_t *)buf, sizeof(buf))) {
pendingRead = false;
}
return false;
}

Expand All @@ -107,6 +102,8 @@ static bool lis2mdlRead(magDev_t *mag, int16_t *magData)
magData[Y] = y;
magData[Z] = z;

pendingRead = true;

return true;
}

Expand Down

0 comments on commit 896bf03

Please sign in to comment.