6#define I2C_MASTER_RESETS_BEFORE_FAIL \
8#define NUM_FINISHED_CHECKS \
12#define ICM20X_B0_WHOAMI 0x00
13#define ICM20X_B0_USER_CTRL 0x03
14#define ICM20X_B0_LP_CONFIG 0x05
15#define ICM20X_B0_REG_INT_PIN_CFG 0xF
16#define ICM20X_B0_REG_INT_ENABLE 0x10
17#define ICM20X_B0_REG_INT_ENABLE_1 0x11
18#define ICM20X_B0_I2C_MST_STATUS \
20#define ICM20X_B0_REG_BANK_SEL 0x7F
21#define ICM20X_B0_PWR_MGMT_1 0x06
22#define ICM20X_B0_ACCEL_XOUT_H 0x2D
23#define ICM20X_B0_GYRO_XOUT_H 0x33
26#define ICM20X_B2_GYRO_SMPLRT_DIV 0x00
27#define ICM20X_B2_GYRO_CONFIG_1 0x01
28#define ICM20X_B2_ACCEL_SMPLRT_DIV_1 0x10
29#define ICM20X_B2_ACCEL_SMPLRT_DIV_2 0x11
30#define ICM20X_B2_ACCEL_CONFIG_1 0x14
33#define ICM20X_B3_I2C_MST_ODR_CONFIG 0x0
34#define ICM20X_B3_I2C_MST_CTRL 0x1
35#define ICM20X_B3_I2C_MST_DELAY_CTRL 0x2
36#define ICM20X_B3_I2C_SLV0_ADDR \
38#define ICM20X_B3_I2C_SLV0_REG \
40#define ICM20X_B3_I2C_SLV0_CTRL 0x5
41#define ICM20X_B3_I2C_SLV0_DO 0x6
43#define ICM20X_B3_I2C_SLV4_ADDR \
45#define ICM20X_B3_I2C_SLV4_REG \
47#define ICM20X_B3_I2C_SLV4_CTRL 0x15
48#define ICM20X_B3_I2C_SLV4_DO 0x16
49#define ICM20X_B3_I2C_SLV4_DI 0x17
51#define ICM20948_CHIP_ID 0xEA
53#define ICM20948_I2CADDR_DEFAULT 0x69
54#define ICM20948_MAG_ID 0x09
56#define ICM20948_UT_PER_LSB 0.15
58#define AK09916_WIA2 0x01
59#define AK09916_ST1 0x10
60#define AK09916_HXL 0x11
61#define AK09916_HXH 0x12
62#define AK09916_HYL 0x13
63#define AK09916_HYH 0x14
64#define AK09916_HZL 0x15
65#define AK09916_HZH 0x16
66#define AK09916_ST2 0x18
67#define AK09916_CNTL2 0x31
68#define AK09916_CNTL3 0x32
70#define SENSORS_GRAVITY_EARTH (9.80665F)
71#define SENSORS_DPS_TO_RADS (0.017453293F)
119 i2c_.
Init(i2c_config);
122 void Write(uint8_t *data, uint16_t size)
128 void Read(uint8_t *data, uint16_t size)
157 buffer[1] = value >> 8;
158 buffer[1] = value & 0xFF;
164 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
240 void Write(uint8_t *data, uint16_t size)
245 void Read(uint8_t *data, uint16_t size)
258 buffer[0] = reg & ~0x80;
272 buffer[0] = reg & ~0x80;
273 buffer[1] = value >> 8;
274 buffer[2] = value & 0xFF;
280 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
282 reg = uint8_t(reg | 0x80);
315template <
typename Transport>
508 float accel_scale = 1.0;
509 float gyro_scale = 1.0;
521 accel_scale = 16384.0;
523 accel_scale = 8192.0;
525 accel_scale = 4096.0;
527 accel_scale = 2048.0;
529 gyroX = rawGyroX / gyro_scale;
530 gyroY = rawGyroY / gyro_scale;
531 gyroZ = rawGyroZ / gyro_scale;
533 accX = rawAccX / accel_scale;
534 accY = rawAccY / accel_scale;
535 accZ = rawAccZ / accel_scale;
578 current_accel_range_ = new_accel_range;
624 current_gyro_range_ = new_gyro_range;
700 false, slv_addr, reg_addr, value);
726 return (uint8_t)
false;
733 return (uint8_t)
false;
739 return (uint8_t)
false;
745 return (uint8_t)
false;
756 return (uint8_t)
false;
766 return (uint8_t)
true;
776 const uint8_t numbytes
779 uint8_t buffer[numbytes];
782 rawAccX = buffer[0] << 8 | buffer[1];
783 rawAccY = buffer[2] << 8 | buffer[3];
784 rawAccZ = buffer[4] << 8 | buffer[5];
786 rawGyroX = buffer[6] << 8 | buffer[7];
787 rawGyroY = buffer[8] << 8 | buffer[9];
788 rawGyroZ = buffer[10] << 8 | buffer[11];
790 temperature = buffer[12] << 8 | buffer[13];
792 rawMagX = ((buffer[16] << 8)
793 | (buffer[15] & 0xFF));
794 rawMagY = ((buffer[18] << 8) | (buffer[17] & 0xFF));
795 rawMagZ = ((buffer[20] << 8) | (buffer[19] & 0xFF));
831 float GetTemp() {
return (temperature / 333.87) + 21.0; }
837 uint8_t
Read8(uint8_t reg) {
return transport_.Read8(reg); }
845 return transport_.Write8(reg, value);
854 return transport_.Write16(reg, value);
858 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
860 return transport_.ReadReg(reg, buff, size);
863 uint8_t
ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
865 uint8_t val =
Read8(reg);
867 return val & ((1 << (bits)) - 1);
870 void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
872 uint8_t val =
Read8(reg);
875 uint8_t mask = (1 << (bits)) - 1;
880 val |= data << shift;
957 Transport transport_;
959 uint16_t _sensorid_accel,
964 uint8_t current_accel_range_;
965 uint8_t current_gyro_range_;
Result Init(const Config &config)
Result ReceiveBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Result TransmitBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Device support for ICM20948 IMU sensor.
Definition icm20948.h:317
icm20948_accel_range_t GetAccelRange()
Definition icm20948.h:555
void SetAccelRange(icm20948_accel_range_t new_accel_range)
Definition icm20948.h:585
Result GetTransportError()
Definition icm20948.h:953
Result Init(Config config)
Definition icm20948.h:376
void ResetI2CMaster(void)
Definition icm20948.h:918
icm20948_accel_range_t
Definition icm20948.h:338
@ ICM20948_ACCEL_RANGE_8_G
Definition icm20948.h:341
@ ICM20948_ACCEL_RANGE_16_G
Definition icm20948.h:342
@ ICM20948_ACCEL_RANGE_2_G
Definition icm20948.h:339
@ ICM20948_ACCEL_RANGE_4_G
Definition icm20948.h:340
Result AuxI2CBusSetupFailed(void)
Definition icm20948.h:933
bool WriteMagRegister(uint8_t mag_reg_addr, uint8_t value)
Definition icm20948.h:496
void SetBank(uint8_t bank_number)
Definition icm20948.h:673
Icm20948()
Definition icm20948.h:319
uint8_t ReadAccelRange()
Definition icm20948.h:563
void Write16(uint8_t reg, uint16_t value)
Definition icm20948.h:852
ak09916_data_rate_t GetMagDataRate()
Definition icm20948.h:644
~Icm20948()
Definition icm20948.h:320
uint8_t GetMagId()
Definition icm20948.h:432
Icm20948Vect GetGyroVect()
Definition icm20948.h:811
bool SetMagDataRate(ak09916_data_rate_t rate)
Definition icm20948.h:654
void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
Definition icm20948.h:870
void SetGyroRange(icm20948_gyro_range_t new_gyro_range)
Definition icm20948.h:612
uint8_t ReadExternalRegister(uint8_t slv_addr, uint8_t reg_addr)
Definition icm20948.h:684
void Reset()
Definition icm20948.h:417
Icm20948Vect GetMagVect()
Definition icm20948.h:821
void Write8(uint8_t reg, uint8_t value)
Definition icm20948.h:843
bool WriteExternalRegister(uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
Definition icm20948.h:697
Result ConfigureI2CMaster(void)
Definition icm20948.h:910
Result SetupMag()
Definition icm20948.h:438
icm20948_gyro_range_t
Definition icm20948.h:347
@ ICM20948_GYRO_RANGE_500_DPS
Definition icm20948.h:349
@ ICM20948_GYRO_RANGE_250_DPS
Definition icm20948.h:348
@ ICM20948_GYRO_RANGE_1000_DPS
Definition icm20948.h:350
@ ICM20948_GYRO_RANGE_2000_DPS
Definition icm20948.h:351
void WriteGyroRange(uint8_t new_gyro_range)
Definition icm20948.h:620
Result EnableI2CMaster(bool enable_i2c_master)
Definition icm20948.h:900
void SetAccelRateDivisor(uint16_t new_accel_divisor)
Definition icm20948.h:545
icm20948_gyro_range_t GetGyroRange()
Definition icm20948.h:604
ak09916_data_rate_t
Definition icm20948.h:356
@ AK09916_MAG_DATARATE_50_HZ
updates at 50Hz
Definition icm20948.h:363
@ AK09916_MAG_DATARATE_10_HZ
updates at 10Hz
Definition icm20948.h:361
@ AK09916_MAG_DATARATE_100_HZ
updates at 100Hz
Definition icm20948.h:364
@ AK09916_MAG_DATARATE_SHUTDOWN
Stops measurement updates.
Definition icm20948.h:357
@ AK09916_MAG_DATARATE_SINGLE
Definition icm20948.h:358
@ AK09916_MAG_DATARATE_20_HZ
updates at 20Hz
Definition icm20948.h:362
float GetTemp()
Definition icm20948.h:831
uint8_t ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
Definition icm20948.h:863
Icm20948Vect GetAccelVect()
Definition icm20948.h:801
uint8_t AuxillaryRegisterTransaction(bool read, uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
Definition icm20948.h:709
void WriteAccelRange(uint8_t new_accel_range)
Definition icm20948.h:574
void SetGyroRateDivisor(uint8_t new_gyro_divisor)
Definition icm20948.h:594
void ScaleValues()
Definition icm20948.h:501
Result
Definition icm20948.h:368
@ OK
Definition icm20948.h:369
@ ERR
Definition icm20948.h:370
uint8_t Read8(uint8_t reg)
Definition icm20948.h:837
uint8_t ReadMagRegister(uint8_t mag_reg_addr)
Definition icm20948.h:491
void SetI2CBypass(bool bypass_i2c)
Definition icm20948.h:890
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition icm20948.h:858
uint8_t ReadGyroRange()
Definition icm20948.h:632
void Process()
Definition icm20948.h:770
void Read(uint8_t *data, uint16_t size)
Definition icm20948.h:128
void Write8(uint8_t reg, uint8_t value)
Definition icm20948.h:138
void Write16(uint8_t reg, uint16_t value)
Definition icm20948.h:152
uint8_t Read8(uint8_t reg)
Definition icm20948.h:174
~Icm20948I2CTransport()
Definition icm20948.h:84
void Write(uint8_t *data, uint16_t size)
Definition icm20948.h:122
void Init(Config config)
Definition icm20948.h:107
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition icm20948.h:164
Icm20948I2CTransport()
Definition icm20948.h:83
bool GetError()
Definition icm20948.h:181
Definition icm20948.h:198
void Write16(uint8_t reg, uint16_t value)
Definition icm20948.h:268
bool GetError()
Definition icm20948.h:299
Icm20948SpiTransport()
Definition icm20948.h:200
uint8_t Read8(uint8_t reg)
Definition icm20948.h:292
void Write(uint8_t *data, uint16_t size)
Definition icm20948.h:240
void Write8(uint8_t reg, uint8_t value)
Definition icm20948.h:254
void Read(uint8_t *data, uint16_t size)
Definition icm20948.h:245
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition icm20948.h:280
~Icm20948SpiTransport()
Definition icm20948.h:201
void Init(Config config)
Definition icm20948.h:221
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result BlockingReceive(uint8_t *buffer, uint16_t size, uint32_t timeout)
Result Init(const Config &config)
static void Delay(uint32_t delay_ms)
#define ICM20X_B0_USER_CTRL
User Control Reg. Includes I2C Master.
Definition icm20948.h:13
#define ICM20X_B0_I2C_MST_STATUS
Records if I2C master bus data is finished/*#end#*/.
Definition icm20948.h:18
#define ICM20X_B0_REG_INT_PIN_CFG
Interrupt config register.
Definition icm20948.h:15
#define ICM20X_B3_I2C_SLV0_REG
Sets register address for I2C master bus slave 0/*#end#*/.
Definition icm20948.h:38
#define ICM20X_B2_ACCEL_SMPLRT_DIV_1
Accel data rate divisor MSByte.
Definition icm20948.h:28
#define ICM20X_B2_GYRO_CONFIG_1
Gyro config for range setting.
Definition icm20948.h:27
#define ICM20X_B0_REG_BANK_SEL
register bank selection register
Definition icm20948.h:20
#define ICM20X_B0_ACCEL_XOUT_H
first byte of accel data
Definition icm20948.h:22
#define ICM20X_B3_I2C_SLV4_ADDR
Sets I2C address for I2C master bus slave 4/*#end#*/.
Definition icm20948.h:43
#define ICM20X_B3_I2C_SLV4_REG
Sets register address for I2C master bus slave 4/*#end#*/.
Definition icm20948.h:45
#define ICM20948_MAG_ID
The chip ID for the magnetometer.
Definition icm20948.h:54
#define SENSORS_DPS_TO_RADS
Definition icm20948.h:71
#define ICM20948_UT_PER_LSB
mag data LSB value (fixed)
Definition icm20948.h:56
#define ICM20X_B2_GYRO_SMPLRT_DIV
Gyroscope data rate divisor.
Definition icm20948.h:26
#define I2C_MASTER_RESETS_BEFORE_FAIL
The number of times to try resetting a stuck I2C master before giving up/*#end#*/.
Definition icm20948.h:6
#define ICM20948_I2CADDR_DEFAULT
ICM20948 default i2c address.
Definition icm20948.h:53
#define ICM20X_B3_I2C_SLV4_CTRL
Controls for I2C master bus slave 4.
Definition icm20948.h:47
#define ICM20948_CHIP_ID
ICM20948 default device id from WHOAMI.
Definition icm20948.h:51
#define ICM20X_B3_I2C_SLV4_DI
Sets I2C master bus slave 4 data in.
Definition icm20948.h:49
#define ICM20X_B2_ACCEL_CONFIG_1
Accel config for setting range.
Definition icm20948.h:30
#define ICM20X_B3_I2C_SLV4_DO
Sets I2C master bus slave 4 data out.
Definition icm20948.h:48
#define AK09916_CNTL2
Magnetometer.
Definition icm20948.h:67
#define ICM20X_B3_I2C_SLV0_ADDR
Sets I2C address for I2C master bus slave 0/*#end#*/.
Definition icm20948.h:36
#define NUM_FINISHED_CHECKS
How many times to poll I2C_SLV4_DONE before giving up and resetting/*#end#*/.
Definition icm20948.h:8
#define ICM20X_B0_WHOAMI
Chip ID register.
Definition icm20948.h:12
#define ICM20X_B3_I2C_MST_CTRL
I2C master bus config.
Definition icm20948.h:34
#define ICM20X_B3_I2C_SLV0_CTRL
Controls for I2C master bus slave 0.
Definition icm20948.h:40
#define SENSORS_GRAVITY_EARTH
Definition icm20948.h:70
#define ICM20X_B0_PWR_MGMT_1
primary power management register
Definition icm20948.h:21
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTB
Definition daisy_core.h:178
@ PORTG
Definition daisy_core.h:183
struct daisy::I2CHandle::Config::@15 pin_config
Mode mode
Definition i2c.h:65
Pin scl
Definition i2c.h:60
Speed speed
Definition i2c.h:64
Peripheral periph
Definition i2c.h:57
Peripheral
Definition i2c.h:40
Pin sda
Definition i2c.h:61
Definition icm20948.h:323
Config()
Definition icm20948.h:326
Transport::Config transport_config
Definition icm20948.h:324
Definition icm20948.h:330
float y
Definition icm20948.h:332
float z
Definition icm20948.h:333
float x
Definition icm20948.h:331
I2CHandle::Config::Speed speed
Definition icm20948.h:89
Config()
Definition icm20948.h:95
Pin sda
Definition icm20948.h:91
I2CHandle::Config::Peripheral periph
Definition icm20948.h:88
uint8_t address
Definition icm20948.h:93
Pin scl
Definition icm20948.h:90
Definition icm20948.h:204
Pin miso
Definition icm20948.h:207
Pin sclk
Definition icm20948.h:206
Config()
Definition icm20948.h:211
SpiHandle::Config::Peripheral periph
Definition icm20948.h:205
Pin nss
Definition icm20948.h:209
Pin mosi
Definition icm20948.h:208
representation of hardware port/pin combination
Definition daisy_core.h:193
ClockPolarity clock_polarity
Definition spi.h:104
Peripheral periph
Definition spi.h:100
Pin nss
Definition spi.h:88
struct daisy::SpiHandle::Config::@18 pin_config
Mode mode
Definition spi.h:101
Peripheral
Definition spi.h:29
Pin mosi
Definition spi.h:87
Pin sclk
Definition spi.h:85
ClockPhase clock_phase
Definition spi.h:105
BaudPrescaler baud_prescaler
Definition spi.h:107
Pin miso
Definition spi.h:86
Direction direction
Definition spi.h:102