libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
icm20948.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_ICM20948_H
3#define DSY_ICM20948_H
4
5// Misc configuration macros
6#define I2C_MASTER_RESETS_BEFORE_FAIL \
7 5
8#define NUM_FINISHED_CHECKS \
9 100
10
11// Bank 0
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 \
19 0x17
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
24
25// Bank 2
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
31
32// Bank 3
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 \
37 0x3
38#define ICM20X_B3_I2C_SLV0_REG \
39 0x4
40#define ICM20X_B3_I2C_SLV0_CTRL 0x5
41#define ICM20X_B3_I2C_SLV0_DO 0x6
42
43#define ICM20X_B3_I2C_SLV4_ADDR \
44 0x13
45#define ICM20X_B3_I2C_SLV4_REG \
46 0x14
47#define ICM20X_B3_I2C_SLV4_CTRL 0x15
48#define ICM20X_B3_I2C_SLV4_DO 0x16
49#define ICM20X_B3_I2C_SLV4_DI 0x17
50
51#define ICM20948_CHIP_ID 0xEA
52
53#define ICM20948_I2CADDR_DEFAULT 0x69
54#define ICM20948_MAG_ID 0x09
55
56#define ICM20948_UT_PER_LSB 0.15
57
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
69
70#define SENSORS_GRAVITY_EARTH (9.80665F)
71#define SENSORS_DPS_TO_RADS (0.017453293F)
72
73namespace daisy
74{
81{
82 public:
85
106
107 inline void Init(Config config)
108 {
109 config_ = config;
110
111 I2CHandle::Config i2c_config;
113 i2c_config.periph = config.periph;
114 i2c_config.speed = config.speed;
115
116 i2c_config.pin_config.scl = config.scl;
117 i2c_config.pin_config.sda = config.sda;
118
119 i2c_.Init(i2c_config);
120 }
121
122 void Write(uint8_t *data, uint16_t size)
123 {
124 error_ |= I2CHandle::Result::OK
125 != i2c_.TransmitBlocking(config_.address, data, size, 10);
126 }
127
128 void Read(uint8_t *data, uint16_t size)
129 {
130 error_ |= I2CHandle::Result::OK
131 != i2c_.ReceiveBlocking(config_.address, data, size, 10);
132 }
133
138 void Write8(uint8_t reg, uint8_t value)
139 {
140 uint8_t buffer[2];
141
142 buffer[0] = reg;
143 buffer[1] = value;
144
145 Write(buffer, 2);
146 }
147
152 void Write16(uint8_t reg, uint16_t value)
153 {
154 uint8_t buffer[3];
155
156 buffer[0] = reg;
157 buffer[1] = value >> 8;
158 buffer[1] = value & 0xFF;
159
160 Write(buffer, 2);
161 }
162
164 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
165 {
166 Write(&reg, 1);
167 Read(buff, size);
168 }
169
174 uint8_t Read8(uint8_t reg)
175 {
176 uint8_t buffer;
177 ReadReg(reg, &buffer, 1);
178 return buffer;
179 }
180
181 bool GetError()
182 {
183 bool tmp = error_;
184 error_ = false;
185 return tmp;
186 }
187
188 private:
189 I2CHandle i2c_;
190 Config config_;
191
192 // true if error has occured since last check
193 bool error_;
194};
195
198{
199 public:
202
220
221 inline void Init(Config config)
222 {
223 SpiHandle::Config spi_conf;
230
231 spi_conf.periph = config.periph;
232 spi_conf.pin_config.sclk = config.sclk;
233 spi_conf.pin_config.miso = config.miso;
234 spi_conf.pin_config.mosi = config.mosi;
235 spi_conf.pin_config.nss = config.nss;
236
237 spi_.Init(spi_conf);
238 }
239
240 void Write(uint8_t *data, uint16_t size)
241 {
242 error_ |= SpiHandle::Result::OK != spi_.BlockingTransmit(data, size);
243 }
244
245 void Read(uint8_t *data, uint16_t size)
246 {
247 error_ |= SpiHandle::Result::OK != spi_.BlockingReceive(data, size, 10);
248 }
249
254 void Write8(uint8_t reg, uint8_t value)
255 {
256 uint8_t buffer[2];
257
258 buffer[0] = reg & ~0x80;
259 buffer[1] = value;
260
261 Write(buffer, 2);
262 }
263
268 void Write16(uint8_t reg, uint16_t value)
269 {
270 uint8_t buffer[3];
271
272 buffer[0] = reg & ~0x80;
273 buffer[1] = value >> 8;
274 buffer[2] = value & 0xFF;
275
276 Write(buffer, 3);
277 }
278
280 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
281 {
282 reg = uint8_t(reg | 0x80);
283 Write(&reg, 1);
284 Read(buff, size);
285 }
286
287
292 uint8_t Read8(uint8_t reg)
293 {
294 uint8_t buffer;
295 ReadReg(reg, &buffer, 1);
296 return buffer;
297 }
298
299 bool GetError()
300 {
301 bool tmp = error_;
302 error_ = false;
303 return tmp;
304 }
305
306 private:
307 SpiHandle spi_;
308 bool error_;
309};
310
315template <typename Transport>
317{
318 public:
321
322 struct Config
323 {
324 typename Transport::Config transport_config;
325
327 };
328
330 {
331 float x;
332 float y;
333 float z;
334 };
335
344
353
366
368 {
369 OK = 0,
370 ERR
371 };
372
377 {
378 config_ = config;
379
380 transport_.Init(config_.transport_config);
381
382 SetBank(0);
383
384 uint8_t chip_id = Read8(ICM20X_B0_WHOAMI);
385
386 if(chip_id != ICM20948_CHIP_ID)
387 {
388 return ERR;
389 }
390
391 _sensorid_accel = 0;
392 _sensorid_gyro = 1;
393 _sensorid_mag = 2;
394 _sensorid_temp = 3;
395
396 Reset();
397
398 // take out of default sleep state
400
401 // 3 will be the largest range for either sensor
404
405 // 1100Hz/(1+10) = 100Hz
407
408 // # 1125Hz/(1+20) = 53.57Hz
410
411 System::Delay(20);
412
413 return GetTransportError();
414 }
415
417 void Reset()
418 {
419 SetBank(0);
420
422 System::Delay(20);
423
424 while(ReadBits(ICM20X_B0_PWR_MGMT_1, 1, 7))
425 {
426 System::Delay(10);
427 };
428
429 System::Delay(50);
430 }
431
432 uint8_t GetMagId()
433 {
434 // verify the magnetometer id
435 return ReadExternalRegister(0x8C, 0x01);
436 }
437
439 {
440 SetI2CBypass(false);
441
443
444 EnableI2CMaster(true);
445
447 {
448 return ERR;
449 }
450
451 // set mag data rate
453 {
454 // Serial.println("Error setting magnetometer data rate on external bus");
455 return ERR;
456 }
457
458 // TODO: extract method
459 // Set up Slave0 to proxy Mag readings
460 SetBank(3);
461
462 // set up slave0 to proxy reads to mag
464 if(GetTransportError() != OK)
465 {
466 return ERR;
467 }
468
470 if(GetTransportError() != OK)
471 {
472 return ERR;
473 }
474
475 // enable, read 9 bytes
477 if(GetTransportError() != OK)
478 {
479 return ERR;
480 }
481
482 return OK;
483 }
484
491 uint8_t ReadMagRegister(uint8_t mag_reg_addr)
492 {
493 return ReadExternalRegister(0x8C, mag_reg_addr);
494 }
495
496 bool WriteMagRegister(uint8_t mag_reg_addr, uint8_t value)
497 {
498 return WriteExternalRegister(0x0C, mag_reg_addr, value);
499 }
500
502 {
503 icm20948_gyro_range_t gyro_range
504 = (icm20948_gyro_range_t)current_gyro_range_;
505 icm20948_accel_range_t accel_range
506 = (icm20948_accel_range_t)current_accel_range_;
507
508 float accel_scale = 1.0;
509 float gyro_scale = 1.0;
510
511 if(gyro_range == ICM20948_GYRO_RANGE_250_DPS)
512 gyro_scale = 131.0;
513 if(gyro_range == ICM20948_GYRO_RANGE_500_DPS)
514 gyro_scale = 65.5;
515 if(gyro_range == ICM20948_GYRO_RANGE_1000_DPS)
516 gyro_scale = 32.8;
517 if(gyro_range == ICM20948_GYRO_RANGE_2000_DPS)
518 gyro_scale = 16.4;
519
520 if(accel_range == ICM20948_ACCEL_RANGE_2_G)
521 accel_scale = 16384.0;
522 if(accel_range == ICM20948_ACCEL_RANGE_4_G)
523 accel_scale = 8192.0;
524 if(accel_range == ICM20948_ACCEL_RANGE_8_G)
525 accel_scale = 4096.0;
526 if(accel_range == ICM20948_ACCEL_RANGE_16_G)
527 accel_scale = 2048.0;
528
529 gyroX = rawGyroX / gyro_scale;
530 gyroY = rawGyroY / gyro_scale;
531 gyroZ = rawGyroZ / gyro_scale;
532
533 accX = rawAccX / accel_scale;
534 accY = rawAccY / accel_scale;
535 accZ = rawAccZ / accel_scale;
536
537 magX = rawMagX * ICM20948_UT_PER_LSB;
538 magY = rawMagY * ICM20948_UT_PER_LSB;
539 magZ = rawMagZ * ICM20948_UT_PER_LSB;
540 }
541
545 void SetAccelRateDivisor(uint16_t new_accel_divisor)
546 {
547 SetBank(2);
548 Write16(ICM20X_B2_ACCEL_SMPLRT_DIV_1, new_accel_divisor);
549 SetBank(0);
550 }
551
559
564 {
565 SetBank(2);
566 uint8_t range = ReadBits(ICM20X_B2_ACCEL_CONFIG_1, 2, 1);
567 SetBank(0);
568 return range;
569 }
570
574 void WriteAccelRange(uint8_t new_accel_range)
575 {
576 SetBank(2);
577 WriteBits(ICM20X_B2_ACCEL_CONFIG_1, new_accel_range, 2, 1);
578 current_accel_range_ = new_accel_range;
579 SetBank(0);
580 }
581
586 {
587 WriteAccelRange((uint8_t)new_accel_range);
588 }
589
590
594 void SetGyroRateDivisor(uint8_t new_gyro_divisor)
595 {
596 SetBank(2);
597 Write8(ICM20X_B2_GYRO_SMPLRT_DIV, new_gyro_divisor);
598 SetBank(0);
599 }
600
608
613 {
614 WriteGyroRange((uint8_t)new_gyro_range);
615 }
616
620 void WriteGyroRange(uint8_t new_gyro_range)
621 {
622 SetBank(2);
623 WriteBits(ICM20X_B2_GYRO_CONFIG_1, new_gyro_range, 2, 1);
624 current_gyro_range_ = new_gyro_range;
625 SetBank(0);
626 }
627
628
633 {
634 SetBank(2);
635 uint8_t range = ReadBits(ICM20X_B2_GYRO_CONFIG_1, 2, 1);
636 SetBank(0);
637 return range;
638 }
639
640
645 {
646 uint8_t raw_mag_rate = ReadMagRegister(AK09916_CNTL2);
647 return (ak09916_data_rate_t)(raw_mag_rate);
648 }
649
655 {
656 /* Following the datasheet, the sensor will be set to
657 * AK09916_MAG_DATARATE_SHUTDOWN followed by a 100ms delay, followed by
658 * setting the new data rate.
659 *
660 * See page 9 of https://www.y-ic.es/datasheet/78/SMDSW.020-2OZ.pdf */
661
662 // don't need to read/mask because there's nothing else in the register and
663 // it's right justified
664 bool success
666 System::Delay(1);
667 return WriteMagRegister(AK09916_CNTL2, rate) && success;
668 }
669
673 void SetBank(uint8_t bank_number)
674 {
675 Write8(ICM20X_B0_REG_BANK_SEL, (bank_number & 0b11) << 4);
676 }
677
678
684 uint8_t ReadExternalRegister(uint8_t slv_addr, uint8_t reg_addr)
685 {
686 return AuxillaryRegisterTransaction(true, slv_addr, reg_addr);
687 }
688
696 bool
697 WriteExternalRegister(uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
698 {
699 return (bool)AuxillaryRegisterTransaction(
700 false, slv_addr, reg_addr, value);
701 }
702
710 uint8_t slv_addr,
711 uint8_t reg_addr,
712 uint8_t value)
713 {
714 SetBank(3);
715
716 if(read)
717 {
718 // set high bit for read, presumably for multi-byte reads
719 slv_addr |= 0x80;
720 }
721 else
722 {
724 if(GetTransportError() == ERR)
725 {
726 return (uint8_t) false;
727 }
728 }
729
731 if(GetTransportError() == ERR)
732 {
733 return (uint8_t) false;
734 }
735
737 if(GetTransportError() == ERR)
738 {
739 return (uint8_t) false;
740 }
741
743 if(GetTransportError() == ERR)
744 {
745 return (uint8_t) false;
746 }
747
748 SetBank(0);
749 uint8_t tries = 0;
750 // wait until the operation is finished
751 while(ReadBits(ICM20X_B0_I2C_MST_STATUS, 1, 6) != true)
752 {
753 tries++;
754 if(tries >= NUM_FINISHED_CHECKS)
755 {
756 return (uint8_t) false;
757 }
758 }
759
760 if(read)
761 {
762 SetBank(3);
764 }
765
766 return (uint8_t) true;
767 }
768
770 void Process()
771 {
772 SetBank(0);
773
774 // reading 9 bytes of mag data to fetch the register that tells the mag we've
775 // read all the data
776 const uint8_t numbytes
777 = 14 + 9; // Read Accel, gyro, temp, and 9 bytes of mag
778
779 uint8_t buffer[numbytes];
780 transport_.ReadReg(ICM20X_B0_ACCEL_XOUT_H, buffer, numbytes);
781
782 rawAccX = buffer[0] << 8 | buffer[1];
783 rawAccY = buffer[2] << 8 | buffer[3];
784 rawAccZ = buffer[4] << 8 | buffer[5];
785
786 rawGyroX = buffer[6] << 8 | buffer[7];
787 rawGyroY = buffer[8] << 8 | buffer[9];
788 rawGyroZ = buffer[10] << 8 | buffer[11];
789
790 temperature = buffer[12] << 8 | buffer[13];
791
792 rawMagX = ((buffer[16] << 8)
793 | (buffer[15] & 0xFF)); // Mag data is read little endian
794 rawMagY = ((buffer[18] << 8) | (buffer[17] & 0xFF));
795 rawMagZ = ((buffer[20] << 8) | (buffer[19] & 0xFF));
796
797 ScaleValues();
798 SetBank(0);
799 }
800
802 {
803 Icm20948Vect vect;
804 vect.x = accX * SENSORS_GRAVITY_EARTH;
805 vect.y = accY * SENSORS_GRAVITY_EARTH;
806 vect.z = accZ * SENSORS_GRAVITY_EARTH;
807
808 return vect;
809 }
810
812 {
813 Icm20948Vect vect;
814 vect.x = gyroX * SENSORS_DPS_TO_RADS;
815 vect.y = gyroY * SENSORS_DPS_TO_RADS;
816 vect.z = gyroZ * SENSORS_DPS_TO_RADS;
817
818 return vect;
819 }
820
822 {
823 Icm20948Vect vect;
824 vect.x = magX;
825 vect.y = magY;
826 vect.z = magZ;
827
828 return vect;
829 }
830
831 float GetTemp() { return (temperature / 333.87) + 21.0; }
832
837 uint8_t Read8(uint8_t reg) { return transport_.Read8(reg); }
838
843 void Write8(uint8_t reg, uint8_t value)
844 {
845 return transport_.Write8(reg, value);
846 }
847
852 void Write16(uint8_t reg, uint16_t value)
853 {
854 return transport_.Write16(reg, value);
855 }
856
858 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
859 {
860 return transport_.ReadReg(reg, buff, size);
861 }
862
863 uint8_t ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
864 {
865 uint8_t val = Read8(reg);
866 val >>= shift;
867 return val & ((1 << (bits)) - 1);
868 }
869
870 void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
871 {
872 uint8_t val = Read8(reg);
873
874 // mask off the data before writing
875 uint8_t mask = (1 << (bits)) - 1;
876 data &= mask;
877
878 mask <<= shift;
879 val &= ~mask; // remove the current data at that spot
880 val |= data << shift; // and add in the new data
881
882 Write8(reg, val);
883 }
884
890 void SetI2CBypass(bool bypass_i2c)
891 {
892 SetBank(0);
893 WriteBits(ICM20X_B0_REG_INT_PIN_CFG, bypass_i2c, 1, 1);
894 }
895
900 Result EnableI2CMaster(bool enable_i2c_master)
901 {
902 SetBank(0);
903 WriteBits(ICM20X_B0_USER_CTRL, enable_i2c_master, 1, 5);
904 return GetTransportError();
905 }
906
911 {
912 SetBank(3);
914 return GetTransportError();
915 }
916
918 void ResetI2CMaster(void)
919 {
920 SetBank(0);
921
922 WriteBits(ICM20X_B0_USER_CTRL, true, 1, 1);
923 while(ReadBits(ICM20X_B0_USER_CTRL, 1, 1))
924 {
925 System::Delay(10);
926 }
927 System::Delay(100);
928 }
929
930 // A million thanks to the SparkFun folks for their library that I pillaged to
931 // write this method! See their Arduino library here:
932 // https://github.com/sparkfun/SparkFun_ICM-20948_ArduinoLibrary
934 {
935 // check aux I2C bus connection by reading the magnetometer chip ID
936 for(int i = 0; i < I2C_MASTER_RESETS_BEFORE_FAIL; i++)
937 {
939 {
941 }
942 else
943 {
944 return ERR;
945 }
946 }
947 return OK;
948 }
949
953 Result GetTransportError() { return transport_.GetError() ? ERR : OK; }
954
955 private:
956 Config config_;
957 Transport transport_;
958
959 uint16_t _sensorid_accel,
960 _sensorid_gyro,
961 _sensorid_mag,
962 _sensorid_temp;
963
964 uint8_t current_accel_range_;
965 uint8_t current_gyro_range_;
966
967 int16_t rawAccX,
968 rawAccY,
969 rawAccZ,
970 rawTemp,
971 rawGyroX,
972 rawGyroY,
973 rawGyroZ,
974 rawMagX,
975 rawMagY,
976 rawMagZ;
977
978 float temperature,
979 accX,
980 accY,
981 accZ,
982 gyroX,
983 gyroY,
984 gyroZ,
985 magX,
986 magY,
987 magZ;
988};
989
994} // namespace daisy
995#endif
Definition i2c.h:26
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
Definition icm20948.h:81
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
Definition spi.h:24
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
Definition i2c.h:30
struct daisy::I2CHandle::Config::@15 pin_config
Mode mode
Definition i2c.h:65
Pin scl
Definition i2c.h:60
Speed
Definition i2c.h:51
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
Definition icm20948.h:87
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
Definition spi.h:27
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