From 5cfac3665ccd6a331ddf69bc274717106c9809c9 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Wolle) Ewald" Date: Wed, 26 Oct 2022 20:31:22 +0200 Subject: [PATCH] Add files via upload --- src/ICM20948_WE.cpp | 78 ++----- src/ICM20948_WE.h | 500 ++++++++++++++++++++++---------------------- 2 files changed, 267 insertions(+), 311 deletions(-) diff --git a/src/ICM20948_WE.cpp b/src/ICM20948_WE.cpp index 2d4c8e6..f6316b3 100644 --- a/src/ICM20948_WE.cpp +++ b/src/ICM20948_WE.cpp @@ -19,47 +19,7 @@ #include "ICM20948_WE.h" -/************ Constructors ************/ - -ICM20948_WE::ICM20948_WE(int addr){ - useSPI = false; - _wire = &Wire; - i2cAddress = addr; -} - -ICM20948_WE::ICM20948_WE(){ - useSPI = false; - _wire = &Wire; - i2cAddress = 0x68; -} - -ICM20948_WE::ICM20948_WE(TwoWire *w, int addr){ - useSPI = false; - _wire = w; - i2cAddress = addr; -} - -ICM20948_WE::ICM20948_WE(TwoWire *w){ - useSPI = false; - _wire = w; - i2cAddress = 0x68; -} - -ICM20948_WE::ICM20948_WE(SPIClass *s, int cs, bool spi){ - useSPI = spi; - _spi = s; - csPin = cs; -} - -ICM20948_WE::ICM20948_WE(int cs, bool spi){ - useSPI = spi; - _spi = &SPI; - csPin = cs; -} - - -/************ Basic Settings ************/ - +/************ Basic Settings ************/ bool ICM20948_WE::init(){ if(useSPI){ @@ -252,9 +212,9 @@ void ICM20948_WE::readSensor(){ xyzFloat ICM20948_WE::getAccRawValues(){ xyzFloat accRawVal; - accRawVal.x = (int16_t)(((buffer[0]) << 8) | buffer[1]) * 1.0; - accRawVal.y = (int16_t)(((buffer[2]) << 8) | buffer[3]) * 1.0; - accRawVal.z = (int16_t)(((buffer[4]) << 8) | buffer[5]) * 1.0; + accRawVal.x = static_cast(((buffer[0]) << 8) | buffer[1]) * 1.0; + accRawVal.y = static_cast(((buffer[2]) << 8) | buffer[3]) * 1.0; + accRawVal.z = static_cast(((buffer[4]) << 8) | buffer[5]) * 1.0; return accRawVal; } @@ -305,7 +265,7 @@ float ICM20948_WE::getResultantG(xyzFloat gVal){ } float ICM20948_WE::getTemperature(){ - int16_t rawTemp = (int16_t)(((buffer[12]) << 8) | buffer[13]); + int16_t rawTemp = static_cast(((buffer[12]) << 8) | buffer[13]); float tmp = (rawTemp*1.0 - ICM20948_ROOM_TEMP_OFFSET)/ICM20948_T_SENSITIVITY + 21.0; return tmp; } @@ -352,9 +312,9 @@ xyzFloat ICM20948_WE::getMagValues(){ int16_t x,y,z; xyzFloat mag; - x = (int16_t)((buffer[15]) << 8) | buffer[14]; - y = (int16_t)((buffer[17]) << 8) | buffer[16]; - z = (int16_t)((buffer[19]) << 8) | buffer[18]; + x = static_cast((buffer[15]) << 8) | buffer[14]; + y = static_cast((buffer[17]) << 8) | buffer[16]; + z = static_cast((buffer[19]) << 8) | buffer[18]; mag.x = x * AK09916_MAG_LSB; mag.y = y * AK09916_MAG_LSB; @@ -703,7 +663,7 @@ void ICM20948_WE::resetFifo(){ } int16_t ICM20948_WE::getFifoCount(){ - int16_t regVal16 = (int16_t) readRegister16(0, ICM20948_FIFO_COUNT); + int16_t regVal16 = static_cast(readRegister16(0, ICM20948_FIFO_COUNT)); return regVal16; } @@ -760,8 +720,8 @@ bool ICM20948_WE::initMagnetometer(){ return true; } -int16_t ICM20948_WE::whoAmIMag(){ - return readAK09916Register16(AK09916_WIA_1); +uint16_t ICM20948_WE::whoAmIMag(){ + return static_cast(readAK09916Register16(AK09916_WIA_1)); } void ICM20948_WE::setMagOpMode(AK09916_opMode opMode){ @@ -845,7 +805,7 @@ void ICM20948_WE::writeRegister8(uint8_t bank, uint8_t reg, uint8_t val){ void ICM20948_WE::writeRegister16(uint8_t bank, uint8_t reg, int16_t val){ switchBank(bank); - int8_t MSByte = (int8_t)((val>>8) & 0xFF); + int8_t MSByte = static_cast((val>>8) & 0xFF); uint8_t LSByte = val & 0xFF; if(!useSPI){ @@ -873,7 +833,7 @@ uint8_t ICM20948_WE::readRegister8(uint8_t bank, uint8_t reg){ _wire->beginTransmission(i2cAddress); _wire->write(reg); _wire->endTransmission(false); - _wire->requestFrom(i2cAddress,1); + _wire->requestFrom(i2cAddress, static_cast(1)); if(_wire->available()){ regValue = _wire->read(); } @@ -899,7 +859,7 @@ int16_t ICM20948_WE::readRegister16(uint8_t bank, uint8_t reg){ _wire->beginTransmission(i2cAddress); _wire->write(reg); _wire->endTransmission(false); - _wire->requestFrom(i2cAddress,2); + _wire->requestFrom(i2cAddress, static_cast(2)); if(_wire->available()){ MSByte = _wire->read(); LSByte = _wire->read(); @@ -926,7 +886,7 @@ void ICM20948_WE::readAllData(uint8_t* data){ _wire->beginTransmission(i2cAddress); _wire->write(ICM20948_ACCEL_OUT); _wire->endTransmission(false); - _wire->requestFrom(i2cAddress,20); + _wire->requestFrom(i2cAddress, static_cast(20)); if(_wire->available()){ for(int i=0; i<20; i++){ data[i] = _wire->read(); @@ -955,7 +915,7 @@ xyzFloat ICM20948_WE::readICM20948xyzValFromFifo(){ _wire->beginTransmission(i2cAddress); _wire->write(ICM20948_FIFO_R_W); _wire->endTransmission(false); - _wire->requestFrom(i2cAddress,6); + _wire->requestFrom(i2cAddress, static_cast(6)); if(_wire->available()){ for(int i=0; i<6; i++){ fifoTriple[i] = _wire->read(); @@ -974,9 +934,9 @@ xyzFloat ICM20948_WE::readICM20948xyzValFromFifo(){ _spi->endTransaction(); } - xyzResult.x = ((int16_t)((fifoTriple[0]<<8) + fifoTriple[1])) * 1.0; - xyzResult.y = ((int16_t)((fifoTriple[2]<<8) + fifoTriple[3])) * 1.0; - xyzResult.z = ((int16_t)((fifoTriple[4]<<8) + fifoTriple[5])) * 1.0; + xyzResult.x = (static_cast((fifoTriple[0]<<8) + fifoTriple[1])) * 1.0; + xyzResult.y = (static_cast((fifoTriple[2]<<8) + fifoTriple[3])) * 1.0; + xyzResult.z = (static_cast((fifoTriple[4]<<8) + fifoTriple[5])) * 1.0; return xyzResult; } diff --git a/src/ICM20948_WE.h b/src/ICM20948_WE.h index d23eb87..497c967 100644 --- a/src/ICM20948_WE.h +++ b/src/ICM20948_WE.h @@ -32,134 +32,8 @@ #include #include "xyzFloat.h" - -#define AK09916_ADDRESS 0x0C - -/* Registers ICM20948 USER BANK 0*/ -#define ICM20948_WHO_AM_I 0x00 -#define ICM20948_USER_CTRL 0x03 -#define ICM20948_LP_CONFIG 0x05 -#define ICM20948_PWR_MGMT_1 0x06 -#define ICM20948_PWR_MGMT_2 0x07 -#define ICM20948_INT_PIN_CFG 0x0F -#define ICM20948_INT_ENABLE 0x10 -#define ICM20948_INT_ENABLE_1 0x11 -#define ICM20948_INT_ENABLE_2 0x12 -#define ICM20948_INT_ENABLE_3 0x13 -#define ICM20948_I2C_MST_STATUS 0x17 -#define ICM20948_INT_STATUS 0x19 -#define ICM20948_INT_STATUS_1 0x1A -#define ICM20948_INT_STATUS_2 0x1B -#define ICM20948_INT_STATUS_3 0x1C -#define ICM20948_DELAY_TIME_H 0x28 -#define ICM20948_DELAY_TIME_L 0x29 -#define ICM20948_ACCEL_OUT 0x2D // accel data registers begin -#define ICM20948_GYRO_OUT 0x33 // gyro data registers begin -#define ICM20948_TEMP_OUT 0x39 -#define ICM20948_EXT_SLV_SENS_DATA_00 0x3B -#define ICM20948_EXT_SLV_SENS_DATA_01 0x3C -#define ICM20948_FIFO_EN_1 0x66 -#define ICM20948_FIFO_EN_2 0x67 -#define ICM20948_FIFO_RST 0x68 -#define ICM20948_FIFO_MODE 0x69 -#define ICM20948_FIFO_COUNT 0x70 -#define ICM20948_FIFO_R_W 0x72 -#define ICM20948_DATA_RDY_STATUS 0x74 -#define ICM20948_FIFO_CFG 0x76 - -/* Registers ICM20948 USER BANK 1*/ -#define ICM20948_SELF_TEST_X_GYRO 0x02 -#define ICM20948_SELF_TEST_Y_GYRO 0x03 -#define ICM20948_SELF_TEST_Z_GYRO 0x04 -#define ICM20948_SELF_TEST_X_ACCEL 0x0E -#define ICM20948_SELF_TEST_Y_ACCEL 0x0F -#define ICM20948_SELF_TEST_Z_ACCEL 0x10 -#define ICM20948_XA_OFFS_H 0x14 -#define ICM20948_XA_OFFS_L 0x15 -#define ICM20948_YA_OFFS_H 0x17 -#define ICM20948_YA_OFFS_L 0x18 -#define ICM20948_ZA_OFFS_H 0x1A -#define ICM20948_ZA_OFFS_L 0x1B -#define ICM20948_TIMEBASE_CORR_PLL 0x28 - -/* Registers ICM20948 USER BANK 2*/ -#define ICM20948_GYRO_SMPLRT_DIV 0x00 -#define ICM20948_GYRO_CONFIG_1 0x01 -#define ICM20948_GYRO_CONFIG_2 0x02 -#define ICM20948_XG_OFFS_USRH 0x03 -#define ICM20948_XG_OFFS_USRL 0x04 -#define ICM20948_YG_OFFS_USRH 0x05 -#define ICM20948_YG_OFFS_USRL 0x06 -#define ICM20948_ZG_OFFS_USRH 0x07 -#define ICM20948_ZG_OFFS_USRL 0x08 -#define ICM20948_ODR_ALIGN_EN 0x09 -#define ICM20948_ACCEL_SMPLRT_DIV_1 0x10 -#define ICM20948_ACCEL_SMPLRT_DIV_2 0x11 -#define ICM20948_ACCEL_INTEL_CTRL 0x12 -#define ICM20948_ACCEL_WOM_THR 0x13 -#define ICM20948_ACCEL_CONFIG 0x14 -#define ICM20948_ACCEL_CONFIG_2 0x15 -#define ICM20948_FSYNC_CONFIG 0x52 -#define ICM20948_TEMP_CONFIG 0x53 -#define ICM20948_MOD_CTRL_USR 0x54 - -/* Registers ICM20948 USER BANK 3*/ -#define ICM20948_I2C_MST_ODR_CFG 0x00 -#define ICM20948_I2C_MST_CTRL 0x01 -#define ICM20948_I2C_MST_DELAY_CTRL 0x02 -#define ICM20948_I2C_SLV0_ADDR 0x03 -#define ICM20948_I2C_SLV0_REG 0x04 -#define ICM20948_I2C_SLV0_CTRL 0x05 -#define ICM20948_I2C_SLV0_DO 0x06 - -/* Registers ICM20948 ALL BANKS */ -#define ICM20948_REG_BANK_SEL 0x7F - - -/* Registers AK09916 */ -#define AK09916_WIA_1 0x00 // Who I am, Company ID -#define AK09916_WIA_2 0x01 // Who I am, Device ID -#define AK09916_STATUS_1 0x10 -#define AK09916_HXL 0x11 -#define AK09916_HXH 0x12 -#define AK09916_HYL 0x13 -#define AK09916_HYH 0x14 -#define AK09916_HZL 0x15 -#define AK09916_HZH 0x16 -#define AK09916_STATUS_2 0x18 -#define AK09916_CNTL_2 0x31 -#define AK09916_CNTL_3 0x32 - -/* Register Bits */ -#define ICM20948_RESET 0x80 -#define ICM20948_I2C_MST_EN 0x20 -#define ICM20948_SLEEP 0x40 -#define ICM20948_LP_EN 0x20 -#define ICM20948_BYPASS_EN 0x02 -#define ICM20948_GYR_EN 0x07 -#define ICM20948_ACC_EN 0x38 -#define ICM20948_FIFO_EN 0x40 -#define ICM20948_INT1_ACTL 0x80 -#define ICM20948_INT_1_LATCH_EN 0x20 -#define ICM20948_ACTL_FSYNC 0x08 -#define ICM20948_INT_ANYRD_2CLEAR 0x10 -#define ICM20948_FSYNC_INT_MODE_EN 0x06 -#define AK09916_16_BIT 0x10 -#define AK09916_OVF 0x08 -#define AK09916_READ 0x80 - -/* Others */ -#define AK09916_WHO_AM_I_1 0x4809 -#define AK09916_WHO_AM_I_2 0x0948 -#define ICM20948_WHO_AM_I_CONTENT 0xEA -#define ICM20948_ROOM_TEMP_OFFSET 0.0f -#define ICM20948_T_SENSITIVITY 333.87f -#define AK09916_MAG_LSB 0.1495f - - /* Enums */ - typedef enum ICM20948_CYCLE { ICM20948_NO_CYCLE = 0x00, ICM20948_GYR_CYCLE = 0x10, @@ -232,137 +106,259 @@ typedef enum ICM20948_ORIENTATION { class ICM20948_WE { -public: - - /* Constructors */ + public: + /* constants */ + + static constexpr uint8_t AK09916_ADDRESS {0x0C}; + + /* Registers ICM20948 USER BANK 0*/ + static constexpr uint8_t ICM20948_WHO_AM_I {0x00}; + static constexpr uint8_t ICM20948_USER_CTRL {0x03}; + static constexpr uint8_t ICM20948_LP_CONFIG {0x05}; + static constexpr uint8_t ICM20948_PWR_MGMT_1 {0x06}; + static constexpr uint8_t ICM20948_PWR_MGMT_2 {0x07}; + static constexpr uint8_t ICM20948_INT_PIN_CFG {0x0F}; + static constexpr uint8_t ICM20948_INT_ENABLE {0x10}; + static constexpr uint8_t ICM20948_INT_ENABLE_1 {0x11}; + static constexpr uint8_t ICM20948_INT_ENABLE_2 {0x12}; + static constexpr uint8_t ICM20948_INT_ENABLE_3 {0x13}; + static constexpr uint8_t ICM20948_I2C_MST_STATUS {0x17}; + static constexpr uint8_t ICM20948_INT_STATUS {0x19}; + static constexpr uint8_t ICM20948_INT_STATUS_1 {0x1A}; + static constexpr uint8_t ICM20948_INT_STATUS_2 {0x1B}; + static constexpr uint8_t ICM20948_INT_STATUS_3 {0x1C}; + static constexpr uint8_t ICM20948_DELAY_TIME_H {0x28}; + static constexpr uint8_t ICM20948_DELAY_TIME_L {0x29}; + static constexpr uint8_t ICM20948_ACCEL_OUT {0x2D}; // accel data registers begin + static constexpr uint8_t ICM20948_GYRO_OUT {0x33}; // gyro data registers begin + static constexpr uint8_t ICM20948_TEMP_OUT {0x39}; + static constexpr uint8_t ICM20948_EXT_SLV_SENS_DATA_00{0x3B}; + static constexpr uint8_t ICM20948_EXT_SLV_SENS_DATA_01{0x3C}; + static constexpr uint8_t ICM20948_FIFO_EN_1 {0x66}; + static constexpr uint8_t ICM20948_FIFO_EN_2 {0x67}; + static constexpr uint8_t ICM20948_FIFO_RST {0x68}; + static constexpr uint8_t ICM20948_FIFO_MODE {0x69}; + static constexpr uint8_t ICM20948_FIFO_COUNT {0x70}; + static constexpr uint8_t ICM20948_FIFO_R_W {0x72}; + static constexpr uint8_t ICM20948_DATA_RDY_STATUS {0x74}; + static constexpr uint8_t ICM20948_FIFO_CFG {0x76}; + + /* Registers ICM20948 USER BANK 1*/ + static constexpr uint8_t ICM20948_SELF_TEST_X_GYRO {0x02}; + static constexpr uint8_t ICM20948_SELF_TEST_Y_GYRO {0x03}; + static constexpr uint8_t ICM20948_SELF_TEST_Z_GYRO {0x04}; + static constexpr uint8_t ICM20948_SELF_TEST_X_ACCEL {0x0E}; + static constexpr uint8_t ICM20948_SELF_TEST_Y_ACCEL {0x0F}; + static constexpr uint8_t ICM20948_SELF_TEST_Z_ACCEL {0x10}; + static constexpr uint8_t ICM20948_XA_OFFS_H {0x14}; + static constexpr uint8_t ICM20948_XA_OFFS_L {0x15}; + static constexpr uint8_t ICM20948_YA_OFFS_H {0x17}; + static constexpr uint8_t ICM20948_YA_OFFS_L {0x18}; + static constexpr uint8_t ICM20948_ZA_OFFS_H {0x1A}; + static constexpr uint8_t ICM20948_ZA_OFFS_L {0x1B}; + static constexpr uint8_t ICM20948_TIMEBASE_CORR_PLL {0x28}; + + /* Registers ICM20948 USER BANK 2*/ + static constexpr uint8_t ICM20948_GYRO_SMPLRT_DIV {0x00}; + static constexpr uint8_t ICM20948_GYRO_CONFIG_1 {0x01}; + static constexpr uint8_t ICM20948_GYRO_CONFIG_2 {0x02}; + static constexpr uint8_t ICM20948_XG_OFFS_USRH {0x03}; + static constexpr uint8_t ICM20948_XG_OFFS_USRL {0x04}; + static constexpr uint8_t ICM20948_YG_OFFS_USRH {0x05}; + static constexpr uint8_t ICM20948_YG_OFFS_USRL {0x06}; + static constexpr uint8_t ICM20948_ZG_OFFS_USRH {0x07}; + static constexpr uint8_t ICM20948_ZG_OFFS_USRL {0x08}; + static constexpr uint8_t ICM20948_ODR_ALIGN_EN {0x09}; + static constexpr uint8_t ICM20948_ACCEL_SMPLRT_DIV_1 {0x10}; + static constexpr uint8_t ICM20948_ACCEL_SMPLRT_DIV_2 {0x11}; + static constexpr uint8_t ICM20948_ACCEL_INTEL_CTRL {0x12}; + static constexpr uint8_t ICM20948_ACCEL_WOM_THR {0x13}; + static constexpr uint8_t ICM20948_ACCEL_CONFIG {0x14}; + static constexpr uint8_t ICM20948_ACCEL_CONFIG_2 {0x15}; + static constexpr uint8_t ICM20948_FSYNC_CONFIG {0x52}; + static constexpr uint8_t ICM20948_TEMP_CONFIG {0x53}; + static constexpr uint8_t ICM20948_MOD_CTRL_USR {0x54}; + + /* Registers ICM20948 USER BANK 3*/ + static constexpr uint8_t ICM20948_I2C_MST_ODR_CFG {0x00}; + static constexpr uint8_t ICM20948_I2C_MST_CTRL {0x01}; + static constexpr uint8_t ICM20948_I2C_MST_DELAY_CTRL {0x02}; + static constexpr uint8_t ICM20948_I2C_SLV0_ADDR {0x03}; + static constexpr uint8_t ICM20948_I2C_SLV0_REG {0x04}; + static constexpr uint8_t ICM20948_I2C_SLV0_CTRL {0x05}; + static constexpr uint8_t ICM20948_I2C_SLV0_DO {0x06}; + + /* Registers ICM20948 ALL BANKS */ + static constexpr uint8_t ICM20948_REG_BANK_SEL {0x7F}; + + /* Registers AK09916 */ + static constexpr uint8_t AK09916_WIA_1 {0x00}; // Who I am, Company ID + static constexpr uint8_t AK09916_WIA_2 {0x01}; // Who I am, Device ID + static constexpr uint8_t AK09916_STATUS_1 {0x10}; + static constexpr uint8_t AK09916_HXL {0x11}; + static constexpr uint8_t AK09916_HXH {0x12}; + static constexpr uint8_t AK09916_HYL {0x13}; + static constexpr uint8_t AK09916_HYH {0x14}; + static constexpr uint8_t AK09916_HZL {0x15}; + static constexpr uint8_t AK09916_HZH {0x16}; + static constexpr uint8_t AK09916_STATUS_2 {0x18}; + static constexpr uint8_t AK09916_CNTL_2 {0x31}; + static constexpr uint8_t AK09916_CNTL_3 {0x32}; + + /* Register Bits */ + static constexpr uint8_t ICM20948_RESET {0x80}; + static constexpr uint8_t ICM20948_I2C_MST_EN {0x20}; + static constexpr uint8_t ICM20948_SLEEP {0x40}; + static constexpr uint8_t ICM20948_LP_EN {0x20}; + static constexpr uint8_t ICM20948_BYPASS_EN {0x02}; + static constexpr uint8_t ICM20948_GYR_EN {0x07}; + static constexpr uint8_t ICM20948_ACC_EN {0x38}; + static constexpr uint8_t ICM20948_FIFO_EN {0x40}; + static constexpr uint8_t ICM20948_INT1_ACTL {0x80}; + static constexpr uint8_t ICM20948_INT_1_LATCH_EN {0x20}; + static constexpr uint8_t ICM20948_ACTL_FSYNC {0x08}; + static constexpr uint8_t ICM20948_INT_ANYRD_2CLEAR {0x10}; + static constexpr uint8_t ICM20948_FSYNC_INT_MODE_EN {0x06}; + static constexpr uint8_t AK09916_16_BIT {0x10}; + static constexpr uint8_t AK09916_OVF {0x08}; + static constexpr uint8_t AK09916_READ {0x80}; + + /* Others */ + static constexpr uint16_t AK09916_WHO_AM_I_1 {0x4809}; + static constexpr uint16_t AK09916_WHO_AM_I_2 {0x0948}; + static constexpr uint8_t ICM20948_WHO_AM_I_CONTENT{0xEA}; + static constexpr float ICM20948_ROOM_TEMP_OFFSET {0.0}; + static constexpr float ICM20948_T_SENSITIVITY {333.87}; + static constexpr float AK09916_MAG_LSB {0.1495}; + + /* Constructors */ - ICM20948_WE(int addr); - ICM20948_WE(); - ICM20948_WE(TwoWire *w, int addr); - ICM20948_WE(TwoWire *w); - ICM20948_WE(SPIClass *s, int cs, bool spi); - ICM20948_WE(int cs, bool spi); + ICM20948_WE(uint8_t addr = 0x68) : _wire{&Wire}, i2cAddress{addr}, useSPI{false} {} + ICM20948_WE(TwoWire *w, uint8_t addr = 0x68) : _wire{w}, i2cAddress{addr}, useSPI{false} {} + ICM20948_WE(int cs, bool spi) : _spi{&SPI}, csPin{cs}, useSPI{spi} {} + ICM20948_WE(SPIClass *s, int cs, bool spi) : _spi{s}, csPin{cs}, useSPI{spi} {} - /* Basic settings */ - - bool init(); - void autoOffsets(); - void setAccOffsets(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax); - void setGyrOffsets(float xOffset, float yOffset, float zOffset); - uint8_t whoAmI(); - void enableAcc(bool enAcc); - void setAccRange(ICM20948_accRange accRange); - void setAccDLPF(ICM20948_dlpf dlpf); - void setAccSampleRateDivider(uint16_t accSplRateDiv); - void enableGyr(bool enGyr); - void setGyrRange(ICM20948_gyroRange gyroRange); - void setGyrDLPF(ICM20948_dlpf dlpf); - void setGyrSampleRateDivider(uint8_t gyrSplRateDiv); - void setTempDLPF(ICM20948_dlpf dlpf); - void setI2CMstSampleRate(uint8_t rateExp); - void setSPIClockSpeed(unsigned long clock); + /* Basic settings */ + + bool init(); + void autoOffsets(); + void setAccOffsets(float xMin, float xMax, float yMin, float yMax, float zMin, float zMax); + void setGyrOffsets(float xOffset, float yOffset, float zOffset); + uint8_t whoAmI(); + void enableAcc(bool enAcc); + void setAccRange(ICM20948_accRange accRange); + void setAccDLPF(ICM20948_dlpf dlpf); + void setAccSampleRateDivider(uint16_t accSplRateDiv); + void enableGyr(bool enGyr); + void setGyrRange(ICM20948_gyroRange gyroRange); + void setGyrDLPF(ICM20948_dlpf dlpf); + void setGyrSampleRateDivider(uint8_t gyrSplRateDiv); + void setTempDLPF(ICM20948_dlpf dlpf); + void setI2CMstSampleRate(uint8_t rateExp); + void setSPIClockSpeed(unsigned long clock); + + + /* x,y,z results */ + + void readSensor(); + xyzFloat getAccRawValues(); + xyzFloat getCorrectedAccRawValues(); + xyzFloat getGValues(); + xyzFloat getAccRawValuesFromFifo(); + xyzFloat getCorrectedAccRawValuesFromFifo(); + xyzFloat getGValuesFromFifo(); + float getResultantG(xyzFloat gVal); + float getTemperature(); + xyzFloat getGyrRawValues(); + xyzFloat getCorrectedGyrRawValues(); + xyzFloat getGyrValues(); + xyzFloat getGyrValuesFromFifo(); + xyzFloat getMagValues(); + - /* x,y,z results */ - - void readSensor(); - xyzFloat getAccRawValues(); - xyzFloat getCorrectedAccRawValues(); - xyzFloat getGValues(); - xyzFloat getAccRawValuesFromFifo(); - xyzFloat getCorrectedAccRawValuesFromFifo(); - xyzFloat getGValuesFromFifo(); - float getResultantG(xyzFloat gVal); - float getTemperature(); - xyzFloat getGyrRawValues(); - xyzFloat getCorrectedGyrRawValues(); - xyzFloat getGyrValues(); - xyzFloat getGyrValuesFromFifo(); - xyzFloat getMagValues(); - + /* Angles and Orientation */ - /* Angles and Orientation */ - - xyzFloat getAngles(); - ICM20948_orientation getOrientation(); - String getOrientationAsString(); - float getPitch(); - float getRoll(); - - - /* Power, Sleep, Standby */ - - void enableCycle(ICM20948_cycle cycle); - void enableLowPower(bool enLP); - void setGyrAverageInCycleMode(ICM20948_gyroAvgLowPower avg); - void setAccAverageInCycleMode(ICM20948_accAvgLowPower avg); - void sleep(bool sleep); - - - /* Interrupts */ - - void setIntPinPolarity(ICM20948_intPinPol pol); - void enableIntLatch(bool latch); - void enableClearIntByAnyRead(bool clearByAnyRead); - void setFSyncIntPolarity(ICM20948_intPinPol pol); - void enableInterrupt(ICM20948_intType intType); - void disableInterrupt(ICM20948_intType intType); - uint8_t readAndClearInterrupts(); - bool checkInterrupt(uint8_t source, ICM20948_intType type); - void setWakeOnMotionThreshold(uint8_t womThresh, ICM20948_womCompEn womCompEn); - - - /* FIFO */ - - void enableFifo(bool fifo); - void setFifoMode(ICM20948_fifoMode mode); - void startFifo(ICM20948_fifoType fifo); - void stopFifo(); - void resetFifo(); - int16_t getFifoCount(); - int16_t getNumberOfFifoDataSets(); - void findFifoBegin(); - - - /* Magnetometer */ - - bool initMagnetometer(); - int16_t whoAmIMag(); - void setMagOpMode(AK09916_opMode opMode); - void resetMag(); - -private: - TwoWire *_wire; - SPIClass *_spi; - SPISettings mySPISettings; - int i2cAddress; - uint8_t currentBank; - uint8_t buffer[20]; - xyzFloat accOffsetVal; - xyzFloat accCorrFactor; - xyzFloat gyrOffsetVal; - uint8_t accRangeFactor; - uint8_t gyrRangeFactor; - uint8_t regVal; // intermediate storage of register values - ICM20948_fifoType fifoType; - int16_t csPin; - bool useSPI; - void setClockToAutoSelect(); - xyzFloat correctAccRawValues(xyzFloat accRawVal); - xyzFloat correctGyrRawValues(xyzFloat gyrRawVal); - void switchBank(uint8_t newBank); - void writeRegister8(uint8_t bank, uint8_t reg, uint8_t val); - void writeRegister16(uint8_t bank, uint8_t reg, int16_t val); - uint8_t readRegister8(uint8_t bank, uint8_t reg); - int16_t readRegister16(uint8_t bank, uint8_t reg); - void readAllData(uint8_t* data); - xyzFloat readICM20948xyzValFromFifo(); - void writeAK09916Register8(uint8_t reg, uint8_t val); - uint8_t readAK09916Register8(uint8_t reg); - int16_t readAK09916Register16(uint8_t reg); - void reset_ICM20948(); - void enableI2CMaster(); - void enableMagDataRead(uint8_t reg, uint8_t bytes); + xyzFloat getAngles(); + ICM20948_orientation getOrientation(); + String getOrientationAsString(); + float getPitch(); + float getRoll(); + + + /* Power, Sleep, Standby */ + + void enableCycle(ICM20948_cycle cycle); + void enableLowPower(bool enLP); + void setGyrAverageInCycleMode(ICM20948_gyroAvgLowPower avg); + void setAccAverageInCycleMode(ICM20948_accAvgLowPower avg); + void sleep(bool sleep); + + + /* Interrupts */ + + void setIntPinPolarity(ICM20948_intPinPol pol); + void enableIntLatch(bool latch); + void enableClearIntByAnyRead(bool clearByAnyRead); + void setFSyncIntPolarity(ICM20948_intPinPol pol); + void enableInterrupt(ICM20948_intType intType); + void disableInterrupt(ICM20948_intType intType); + uint8_t readAndClearInterrupts(); + bool checkInterrupt(uint8_t source, ICM20948_intType type); + void setWakeOnMotionThreshold(uint8_t womThresh, ICM20948_womCompEn womCompEn); + + + /* FIFO */ + + void enableFifo(bool fifo); + void setFifoMode(ICM20948_fifoMode mode); + void startFifo(ICM20948_fifoType fifo); + void stopFifo(); + void resetFifo(); + int16_t getFifoCount(); + int16_t getNumberOfFifoDataSets(); + void findFifoBegin(); + + + /* Magnetometer */ + + bool initMagnetometer(); + uint16_t whoAmIMag(); + void setMagOpMode(AK09916_opMode opMode); + void resetMag(); + + protected: + TwoWire *_wire; + SPIClass *_spi; + SPISettings mySPISettings; + uint8_t i2cAddress; + uint8_t currentBank; + uint8_t buffer[20]; + xyzFloat accOffsetVal; + xyzFloat accCorrFactor; + xyzFloat gyrOffsetVal; + uint8_t accRangeFactor; + uint8_t gyrRangeFactor; + uint8_t regVal; // intermediate storage of register values + ICM20948_fifoType fifoType; + int16_t csPin; + bool useSPI; + void setClockToAutoSelect(); + xyzFloat correctAccRawValues(xyzFloat accRawVal); + xyzFloat correctGyrRawValues(xyzFloat gyrRawVal); + void switchBank(uint8_t newBank); + void writeRegister8(uint8_t bank, uint8_t reg, uint8_t val); + void writeRegister16(uint8_t bank, uint8_t reg, int16_t val); + uint8_t readRegister8(uint8_t bank, uint8_t reg); + int16_t readRegister16(uint8_t bank, uint8_t reg); + void readAllData(uint8_t* data); + xyzFloat readICM20948xyzValFromFifo(); + void writeAK09916Register8(uint8_t reg, uint8_t val); + uint8_t readAK09916Register8(uint8_t reg); + int16_t readAK09916Register16(uint8_t reg); + void reset_ICM20948(); + void enableI2CMaster(); + void enableMagDataRead(uint8_t reg, uint8_t bytes); };