ICM20689 conversion
This commit is contained in:
parent
79589f99ca
commit
aedfa1e49c
|
@ -276,12 +276,13 @@ static bool detectSPISensorsAndUpdateDetectionResult(gyroDev_t *gyro)
|
|||
#endif
|
||||
|
||||
#ifdef USE_GYRO_SPI_ICM20689
|
||||
gyro->bus.spi.instance = ICM20689_SPI_INSTANCE;
|
||||
gyro->bus.spi.csnPin = gyro->bus.spi.csnPin == IO_NONE ? IOGetByTag(IO_TAG(ICM20689_CS_PIN)) : gyro->bus.spi.csnPin;
|
||||
if (icm20689SpiDetect(&gyro->bus)) {
|
||||
gyro->mpuDetectionResult.sensor = ICM_20689_SPI;
|
||||
gyro->mpuConfiguration.gyroReadXRegister = MPU_RA_GYRO_XOUT_H;
|
||||
gyro->mpuConfiguration.readFn = icm20689SpiReadRegister;
|
||||
gyro->mpuConfiguration.writeFn = icm20689SpiWriteRegister;
|
||||
gyro->mpuConfiguration.readFn = spiReadRegister;
|
||||
gyro->mpuConfiguration.writeFn = spiWriteRegister;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -36,29 +36,6 @@
|
|||
#include "accgyro_mpu.h"
|
||||
#include "accgyro_spi_icm20689.h"
|
||||
|
||||
#define DISABLE_ICM20689(spiCsnPin) IOHi(spiCsnPin)
|
||||
#define ENABLE_ICM20689(spiCsnPin) IOLo(spiCsnPin)
|
||||
|
||||
bool icm20689SpiWriteRegister(const busDevice_t *bus, uint8_t reg, uint8_t data)
|
||||
{
|
||||
ENABLE_ICM20689(bus->spi.csnPin);
|
||||
spiTransferByte(ICM20689_SPI_INSTANCE, reg);
|
||||
spiTransferByte(ICM20689_SPI_INSTANCE, data);
|
||||
DISABLE_ICM20689(bus->spi.csnPin);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool icm20689SpiReadRegister(const busDevice_t *bus, uint8_t reg, uint8_t length, uint8_t *data)
|
||||
{
|
||||
ENABLE_ICM20689(bus->spi.csnPin);
|
||||
spiTransferByte(ICM20689_SPI_INSTANCE, reg | 0x80); // read transaction
|
||||
spiTransfer(ICM20689_SPI_INSTANCE, data, NULL, length);
|
||||
DISABLE_ICM20689(bus->spi.csnPin);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void icm20689SpiInit(const busDevice_t *bus)
|
||||
{
|
||||
static bool hardwareInitialised = false;
|
||||
|
@ -71,7 +48,7 @@ static void icm20689SpiInit(const busDevice_t *bus)
|
|||
IOConfigGPIO(bus->spi.csnPin, SPI_IO_CS_CFG);
|
||||
IOHi(bus->spi.csnPin);
|
||||
|
||||
spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_STANDARD);
|
||||
spiSetDivisor(bus->spi.instance, SPI_CLOCK_STANDARD);
|
||||
|
||||
hardwareInitialised = true;
|
||||
}
|
||||
|
@ -83,14 +60,14 @@ bool icm20689SpiDetect(const busDevice_t *bus)
|
|||
|
||||
icm20689SpiInit(bus);
|
||||
|
||||
spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_INITIALIZATON); //low speed
|
||||
spiSetDivisor(bus->spi.instance, SPI_CLOCK_INITIALIZATON); //low speed
|
||||
|
||||
icm20689SpiWriteRegister(bus, MPU_RA_PWR_MGMT_1, ICM20689_BIT_RESET);
|
||||
spiWriteRegister(bus, MPU_RA_PWR_MGMT_1, ICM20689_BIT_RESET);
|
||||
|
||||
do {
|
||||
delay(150);
|
||||
|
||||
icm20689SpiReadRegister(bus, MPU_RA_WHO_AM_I, 1, &tmp);
|
||||
spiReadRegister(bus, MPU_RA_WHO_AM_I, 1, &tmp);
|
||||
if (tmp == ICM20689_WHO_AM_I_CONST) {
|
||||
break;
|
||||
}
|
||||
|
@ -99,7 +76,7 @@ bool icm20689SpiDetect(const busDevice_t *bus)
|
|||
}
|
||||
} while (attemptsRemaining--);
|
||||
|
||||
spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_STANDARD);
|
||||
spiSetDivisor(bus->spi.instance, SPI_CLOCK_STANDARD);
|
||||
|
||||
return true;
|
||||
|
||||
|
@ -126,7 +103,7 @@ void icm20689GyroInit(gyroDev_t *gyro)
|
|||
{
|
||||
mpuGyroInit(gyro);
|
||||
|
||||
spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_INITIALIZATON);
|
||||
spiSetDivisor(gyro->bus.spi.instance, SPI_CLOCK_INITIALIZATON);
|
||||
|
||||
gyro->mpuConfiguration.writeFn(&gyro->bus, MPU_RA_PWR_MGMT_1, ICM20689_BIT_RESET);
|
||||
delay(100);
|
||||
|
@ -156,7 +133,7 @@ void icm20689GyroInit(gyroDev_t *gyro)
|
|||
gyro->mpuConfiguration.writeFn(&gyro->bus, MPU_RA_INT_ENABLE, 0x01); // RAW_RDY_EN interrupt enable
|
||||
#endif
|
||||
|
||||
spiSetDivisor(ICM20689_SPI_INSTANCE, SPI_CLOCK_STANDARD);
|
||||
spiSetDivisor(gyro->bus.spi.instance, SPI_CLOCK_STANDARD);
|
||||
}
|
||||
|
||||
bool icm20689SpiGyroDetect(gyroDev_t *gyro)
|
||||
|
|
|
@ -31,6 +31,3 @@ bool icm20689SpiDetect(const busDevice_t *bus);
|
|||
|
||||
bool icm20689SpiAccDetect(accDev_t *acc);
|
||||
bool icm20689SpiGyroDetect(gyroDev_t *gyro);
|
||||
|
||||
bool icm20689SpiWriteRegister(const busDevice_t *bus, uint8_t reg, uint8_t data);
|
||||
bool icm20689SpiReadRegister(const busDevice_t *bus, uint8_t reg, uint8_t length, uint8_t *data);
|
||||
|
|
Loading…
Reference in New Issue