mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 19:40:31 +03:00
lis2mdl: fix read (#14227)
* 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>
This commit is contained in:
parent
f2e9dac322
commit
896bf03b4e
1 changed files with 8 additions and 11 deletions
|
@ -77,20 +77,15 @@ static bool lis2mdlInit(magDev_t *mag)
|
||||||
|
|
||||||
static bool lis2mdlRead(magDev_t *mag, int16_t *magData)
|
static bool lis2mdlRead(magDev_t *mag, int16_t *magData)
|
||||||
{
|
{
|
||||||
uint8_t status = 0;
|
static uint8_t buf[6];
|
||||||
uint8_t buf[6];
|
static bool pendingRead = true;
|
||||||
|
|
||||||
extDevice_t *dev = &mag->dev;
|
extDevice_t *dev = &mag->dev;
|
||||||
|
|
||||||
if (!busReadRegisterBuffer(dev, LIS2MDL_ADDR_STATUS_REG, &status, sizeof(status))) {
|
if (pendingRead) {
|
||||||
return false;
|
if (busReadRegisterBufferStart(dev, LIS2MDL_ADDR_OUTX_L_REG, (uint8_t *)buf, sizeof(buf))) {
|
||||||
|
pendingRead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(status & LIS2MDL_STATUS_REG_READY)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!busReadRegisterBuffer(dev, LIS2MDL_ADDR_OUTX_L_REG, (uint8_t *)&buf, sizeof(buf))) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +102,8 @@ static bool lis2mdlRead(magDev_t *mag, int16_t *magData)
|
||||||
magData[Y] = y;
|
magData[Y] = y;
|
||||||
magData[Z] = z;
|
magData[Z] = z;
|
||||||
|
|
||||||
|
pendingRead = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue