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 uint8_t buffer[2];
441
442 SetI2CBypass(false);
443
445
446 EnableI2CMaster(true);
447
449 {
450 return ERR;
451 }
452
453 // set mag data rate
455 {
456 // Serial.println("Error setting magnetometer data rate on external bus");
457 return ERR;
458 }
459
460 // TODO: extract method
461 // Set up Slave0 to proxy Mag readings
462 SetBank(3);
463
464 // set up slave0 to proxy reads to mag
466 if(GetTransportError() != OK)
467 {
468 return ERR;
469 }
470
472 if(GetTransportError() != OK)
473 {
474 return ERR;
475 }
476
477 // enable, read 9 bytes
479 if(GetTransportError() != OK)
480 {
481 return ERR;
482 }
483
484 return OK;
485 }
486
493 uint8_t ReadMagRegister(uint8_t mag_reg_addr)
494 {
495 return ReadExternalRegister(0x8C, mag_reg_addr);
496 }
497
498 bool WriteMagRegister(uint8_t mag_reg_addr, uint8_t value)
499 {
500 return WriteExternalRegister(0x0C, mag_reg_addr, value);
501 }
502
504 {
505 icm20948_gyro_range_t gyro_range
506 = (icm20948_gyro_range_t)current_gyro_range_;
507 icm20948_accel_range_t accel_range
508 = (icm20948_accel_range_t)current_accel_range_;
509
510 float accel_scale = 1.0;
511 float gyro_scale = 1.0;
512
513 if(gyro_range == ICM20948_GYRO_RANGE_250_DPS)
514 gyro_scale = 131.0;
515 if(gyro_range == ICM20948_GYRO_RANGE_500_DPS)
516 gyro_scale = 65.5;
517 if(gyro_range == ICM20948_GYRO_RANGE_1000_DPS)
518 gyro_scale = 32.8;
519 if(gyro_range == ICM20948_GYRO_RANGE_2000_DPS)
520 gyro_scale = 16.4;
521
522 if(accel_range == ICM20948_ACCEL_RANGE_2_G)
523 accel_scale = 16384.0;
524 if(accel_range == ICM20948_ACCEL_RANGE_4_G)
525 accel_scale = 8192.0;
526 if(accel_range == ICM20948_ACCEL_RANGE_8_G)
527 accel_scale = 4096.0;
528 if(accel_range == ICM20948_ACCEL_RANGE_16_G)
529 accel_scale = 2048.0;
530
531 gyroX = rawGyroX / gyro_scale;
532 gyroY = rawGyroY / gyro_scale;
533 gyroZ = rawGyroZ / gyro_scale;
534
535 accX = rawAccX / accel_scale;
536 accY = rawAccY / accel_scale;
537 accZ = rawAccZ / accel_scale;
538
539 magX = rawMagX * ICM20948_UT_PER_LSB;
540 magY = rawMagY * ICM20948_UT_PER_LSB;
541 magZ = rawMagZ * ICM20948_UT_PER_LSB;
542 }
543
547 void SetAccelRateDivisor(uint16_t new_accel_divisor)
548 {
549 SetBank(2);
550 Write16(ICM20X_B2_ACCEL_SMPLRT_DIV_1, new_accel_divisor);
551 SetBank(0);
552 }
553
561
566 {
567 SetBank(2);
568 uint8_t range = ReadBits(ICM20X_B2_ACCEL_CONFIG_1, 2, 1);
569 SetBank(0);
570 return range;
571 }
572
576 void WriteAccelRange(uint8_t new_accel_range)
577 {
578 SetBank(2);
579 WriteBits(ICM20X_B2_ACCEL_CONFIG_1, new_accel_range, 2, 1);
580 current_accel_range_ = new_accel_range;
581 SetBank(0);
582 }
583
588 {
589 WriteAccelRange((uint8_t)new_accel_range);
590 }
591
592
596 void SetGyroRateDivisor(uint8_t new_gyro_divisor)
597 {
598 SetBank(2);
599 Write8(ICM20X_B2_GYRO_SMPLRT_DIV, new_gyro_divisor);
600 SetBank(0);
601 }
602
610
615 {
616 WriteGyroRange((uint8_t)new_gyro_range);
617 }
618
622 void WriteGyroRange(uint8_t new_gyro_range)
623 {
624 SetBank(2);
625 WriteBits(ICM20X_B2_GYRO_CONFIG_1, new_gyro_range, 2, 1);
626 current_gyro_range_ = new_gyro_range;
627 SetBank(0);
628 }
629
630
635 {
636 SetBank(2);
637 uint8_t range = ReadBits(ICM20X_B2_GYRO_CONFIG_1, 2, 1);
638 SetBank(0);
639 return range;
640 }
641
642
647 {
648 uint8_t raw_mag_rate = ReadMagRegister(AK09916_CNTL2);
649 return (ak09916_data_rate_t)(raw_mag_rate);
650 }
651
657 {
658 /* Following the datasheet, the sensor will be set to
659 * AK09916_MAG_DATARATE_SHUTDOWN followed by a 100ms delay, followed by
660 * setting the new data rate.
661 *
662 * See page 9 of https://www.y-ic.es/datasheet/78/SMDSW.020-2OZ.pdf */
663
664 // don't need to read/mask because there's nothing else in the register and
665 // it's right justified
666 bool success
668 System::Delay(1);
669 return WriteMagRegister(AK09916_CNTL2, rate) && success;
670 }
671
675 void SetBank(uint8_t bank_number)
676 {
677 Write8(ICM20X_B0_REG_BANK_SEL, (bank_number & 0b11) << 4);
678 }
679
680
686 uint8_t ReadExternalRegister(uint8_t slv_addr, uint8_t reg_addr)
687 {
688 return AuxillaryRegisterTransaction(true, slv_addr, reg_addr);
689 }
690
698 bool
699 WriteExternalRegister(uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
700 {
701 return (bool)AuxillaryRegisterTransaction(
702 false, slv_addr, reg_addr, value);
703 }
704
712 uint8_t slv_addr,
713 uint8_t reg_addr,
714 uint8_t value)
715 {
716 SetBank(3);
717
718 if(read)
719 {
720 // set high bit for read, presumably for multi-byte reads
721 slv_addr |= 0x80;
722 }
723 else
724 {
726 if(GetTransportError() == ERR)
727 {
728 return (uint8_t) false;
729 }
730 }
731
733 if(GetTransportError() == ERR)
734 {
735 return (uint8_t) false;
736 }
737
739 if(GetTransportError() == ERR)
740 {
741 return (uint8_t) false;
742 }
743
745 if(GetTransportError() == ERR)
746 {
747 return (uint8_t) false;
748 }
749
750 SetBank(0);
751 uint8_t tries = 0;
752 // wait until the operation is finished
753 while(ReadBits(ICM20X_B0_I2C_MST_STATUS, 1, 6) != true)
754 {
755 tries++;
756 if(tries >= NUM_FINISHED_CHECKS)
757 {
758 return (uint8_t) false;
759 }
760 }
761
762 if(read)
763 {
764 SetBank(3);
766 }
767
768 return (uint8_t) true;
769 }
770
772 void Process()
773 {
774 SetBank(0);
775
776 // reading 9 bytes of mag data to fetch the register that tells the mag we've
777 // read all the data
778 const uint8_t numbytes
779 = 14 + 9; // Read Accel, gyro, temp, and 9 bytes of mag
780
781 uint8_t buffer[numbytes];
782 transport_.ReadReg(ICM20X_B0_ACCEL_XOUT_H, buffer, numbytes);
783
784 rawAccX = buffer[0] << 8 | buffer[1];
785 rawAccY = buffer[2] << 8 | buffer[3];
786 rawAccZ = buffer[4] << 8 | buffer[5];
787
788 rawGyroX = buffer[6] << 8 | buffer[7];
789 rawGyroY = buffer[8] << 8 | buffer[9];
790 rawGyroZ = buffer[10] << 8 | buffer[11];
791
792 temperature = buffer[12] << 8 | buffer[13];
793
794 rawMagX = ((buffer[16] << 8)
795 | (buffer[15] & 0xFF)); // Mag data is read little endian
796 rawMagY = ((buffer[18] << 8) | (buffer[17] & 0xFF));
797 rawMagZ = ((buffer[20] << 8) | (buffer[19] & 0xFF));
798
799 ScaleValues();
800 SetBank(0);
801 }
802
804 {
805 Icm20948Vect vect;
806 vect.x = accX * SENSORS_GRAVITY_EARTH;
807 vect.y = accY * SENSORS_GRAVITY_EARTH;
808 vect.z = accZ * SENSORS_GRAVITY_EARTH;
809
810 return vect;
811 }
812
814 {
815 Icm20948Vect vect;
816 vect.x = gyroX * SENSORS_DPS_TO_RADS;
817 vect.y = gyroY * SENSORS_DPS_TO_RADS;
818 vect.z = gyroZ * SENSORS_DPS_TO_RADS;
819
820 return vect;
821 }
822
824 {
825 Icm20948Vect vect;
826 vect.x = magX;
827 vect.y = magY;
828 vect.z = magZ;
829
830 return vect;
831 }
832
833 float GetTemp() { return (temperature / 333.87) + 21.0; }
834
839 uint8_t Read8(uint8_t reg) { return transport_.Read8(reg); }
840
845 void Write8(uint8_t reg, uint8_t value)
846 {
847 return transport_.Write8(reg, value);
848 }
849
854 void Write16(uint8_t reg, uint16_t value)
855 {
856 return transport_.Write16(reg, value);
857 }
858
860 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
861 {
862 return transport_.ReadReg(reg, buff, size);
863 }
864
865 uint8_t ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
866 {
867 uint8_t val = Read8(reg);
868 val >>= shift;
869 return val & ((1 << (bits)) - 1);
870 }
871
872 void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
873 {
874 uint8_t val = Read8(reg);
875
876 // mask off the data before writing
877 uint8_t mask = (1 << (bits)) - 1;
878 data &= mask;
879
880 mask <<= shift;
881 val &= ~mask; // remove the current data at that spot
882 val |= data << shift; // and add in the new data
883
884 Write8(reg, val);
885 }
886
892 void SetI2CBypass(bool bypass_i2c)
893 {
894 SetBank(0);
895 WriteBits(ICM20X_B0_REG_INT_PIN_CFG, bypass_i2c, 1, 1);
896 }
897
902 Result EnableI2CMaster(bool enable_i2c_master)
903 {
904 SetBank(0);
905 WriteBits(ICM20X_B0_USER_CTRL, enable_i2c_master, 1, 5);
906 return GetTransportError();
907 }
908
913 {
914 SetBank(3);
916 return GetTransportError();
917 }
918
920 void ResetI2CMaster(void)
921 {
922 SetBank(0);
923
924 WriteBits(ICM20X_B0_USER_CTRL, true, 1, 1);
925 while(ReadBits(ICM20X_B0_USER_CTRL, 1, 1))
926 {
927 System::Delay(10);
928 }
929 System::Delay(100);
930 }
931
932 // A million thanks to the SparkFun folks for their library that I pillaged to
933 // write this method! See their Arduino library here:
934 // https://github.com/sparkfun/SparkFun_ICM-20948_ArduinoLibrary
936 {
937 // check aux I2C bus connection by reading the magnetometer chip ID
938 for(int i = 0; i < I2C_MASTER_RESETS_BEFORE_FAIL; i++)
939 {
941 {
943 }
944 else
945 {
946 return ERR;
947 }
948 }
949 return OK;
950 }
951
955 Result GetTransportError() { return transport_.GetError() ? ERR : OK; }
956
957 private:
958 Config config_;
959 Transport transport_;
960
961 uint16_t _sensorid_accel,
962 _sensorid_gyro,
963 _sensorid_mag,
964 _sensorid_temp;
965
966 uint8_t current_accel_range_;
967 uint8_t current_gyro_range_;
968
969 int16_t rawAccX,
970 rawAccY,
971 rawAccZ,
972 rawTemp,
973 rawGyroX,
974 rawGyroY,
975 rawGyroZ,
976 rawMagX,
977 rawMagY,
978 rawMagZ;
979
980 float temperature,
981 accX,
982 accY,
983 accZ,
984 gyroX,
985 gyroY,
986 gyroZ,
987 magX,
988 magY,
989 magZ;
990};
991
996} // namespace daisy
997#endif
Definition i2c.h:25
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:557
void SetAccelRange(icm20948_accel_range_t new_accel_range)
Definition icm20948.h:587
Result GetTransportError()
Definition icm20948.h:955
Result Init(Config config)
Definition icm20948.h:376
void ResetI2CMaster(void)
Definition icm20948.h:920
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:935
bool WriteMagRegister(uint8_t mag_reg_addr, uint8_t value)
Definition icm20948.h:498
void SetBank(uint8_t bank_number)
Definition icm20948.h:675
Icm20948()
Definition icm20948.h:319
uint8_t ReadAccelRange()
Definition icm20948.h:565
void Write16(uint8_t reg, uint16_t value)
Definition icm20948.h:854
ak09916_data_rate_t GetMagDataRate()
Definition icm20948.h:646
~Icm20948()
Definition icm20948.h:320
uint8_t GetMagId()
Definition icm20948.h:432
Icm20948Vect GetGyroVect()
Definition icm20948.h:813
bool SetMagDataRate(ak09916_data_rate_t rate)
Definition icm20948.h:656
void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
Definition icm20948.h:872
void SetGyroRange(icm20948_gyro_range_t new_gyro_range)
Definition icm20948.h:614
uint8_t ReadExternalRegister(uint8_t slv_addr, uint8_t reg_addr)
Definition icm20948.h:686
void Reset()
Definition icm20948.h:417
Icm20948Vect GetMagVect()
Definition icm20948.h:823
void Write8(uint8_t reg, uint8_t value)
Definition icm20948.h:845
bool WriteExternalRegister(uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
Definition icm20948.h:699
Result ConfigureI2CMaster(void)
Definition icm20948.h:912
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:622
Result EnableI2CMaster(bool enable_i2c_master)
Definition icm20948.h:902
void SetAccelRateDivisor(uint16_t new_accel_divisor)
Definition icm20948.h:547
icm20948_gyro_range_t GetGyroRange()
Definition icm20948.h:606
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:833
uint8_t ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
Definition icm20948.h:865
Icm20948Vect GetAccelVect()
Definition icm20948.h:803
uint8_t AuxillaryRegisterTransaction(bool read, uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
Definition icm20948.h:711
void WriteAccelRange(uint8_t new_accel_range)
Definition icm20948.h:576
void SetGyroRateDivisor(uint8_t new_gyro_divisor)
Definition icm20948.h:596
void ScaleValues()
Definition icm20948.h:503
Result
Definition icm20948.h:368
@ OK
Definition icm20948.h:369
@ ERR
Definition icm20948.h:370
uint8_t Read8(uint8_t reg)
Definition icm20948.h:839
uint8_t ReadMagRegister(uint8_t mag_reg_addr)
Definition icm20948.h:493
void SetI2CBypass(bool bypass_i2c)
Definition icm20948.h:892
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition icm20948.h:860
uint8_t ReadGyroRange()
Definition icm20948.h:634
void Process()
Definition icm20948.h:772
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:20
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:246
@ PORTG
Definition daisy_core.h:251
Definition i2c.h:29
dsy_gpio_pin scl
Definition i2c.h:59
Mode mode
Definition i2c.h:64
Speed
Definition i2c.h:50
Speed speed
Definition i2c.h:63
dsy_gpio_pin sda
Definition i2c.h:60
struct daisy::I2CHandle::Config::@13 pin_config
Peripheral periph
Definition i2c.h:56
Peripheral
Definition i2c.h:39
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:261
Definition spi.h:23
ClockPolarity clock_polarity
Definition spi.h:100
Peripheral periph
Definition spi.h:96
dsy_gpio_pin sclk
Definition spi.h:81
struct daisy::SpiHandle::Config::@16 pin_config
Mode mode
Definition spi.h:97
dsy_gpio_pin mosi
Definition spi.h:83
Peripheral
Definition spi.h:25
dsy_gpio_pin nss
Definition spi.h:84
ClockPhase clock_phase
Definition spi.h:101
BaudPrescaler baud_prescaler
Definition spi.h:103
dsy_gpio_pin miso
Definition spi.h:82
Direction direction
Definition spi.h:98