Skip to content

Commit 5d94703

Browse files
committed
Adding the more recent DMP firmware binary (14301 bytes). Adding missing DMP register locations.
1 parent 85ae2d5 commit 5d94703

File tree

3 files changed

+843
-661
lines changed

3 files changed

+843
-661
lines changed

src/util/ICM_20948_C.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ extern "C"
2525
extern int memcmp(const void *, const void *, size_t); // Avoid compiler warnings
2626

2727
// Define if the DMP will be supported
28-
// Note: you must have 14290 Bytes of program memory available to store the DMP firmware!
29-
//#define ICM_20948_USE_DMP // Uncomment this line to enable DMP support.
28+
// Note: you must have 14301 Bytes of program memory available to store the DMP firmware!
29+
#define ICM_20948_USE_DMP // Uncomment this line to enable DMP support.
3030

3131
#define ICM_20948_I2C_ADDR_AD0 0x68 // Or 0x69 when AD0 is high
3232
#define ICM_20948_I2C_ADDR_AD1 0x69 //

src/util/ICM_20948_DMP.h

Lines changed: 201 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ extern "C" {
1717
#define DMP_MEM_BANK_SIZE 256
1818
#define DMP_LOAD_START 0x90
1919

20-
#define DMP_CODE_SIZE 14290
20+
#define DMP_CODE_SIZE 14301 /* dmp3a.20x48-0.4.1 */
21+
22+
#define CFG_FIFO_SIZE (4222)
2123

2224
// AGB0_REG_DMP_INT_STATUS bit definitions
2325
#define BIT_WAKE_ON_MOTION_INT 0x08
@@ -38,13 +40,21 @@ extern "C" {
3840
#define DATA_OUT_CTL2 (4 * 16 + 2) // 16-bit: Data output control 2 register : configure the BM, accel/gyro/compass accuracy and gesture such as Pick-up
3941
#define DATA_INTR_CTL (4 * 16 + 12) // 16-bit: Determines which sensors can generate interrupt according to bit map defined for DATA_OUT_CTL1
4042
#define FIFO_WATERMARK (31 * 16 + 14) // 16-bit: DMP will send FIFO interrupt if FIFO count > FIFO watermark. FIFO watermark is set to 80% of actual FIFO size by default
43+
4144
// motion event control
4245
#define MOTION_EVENT_CTL (4 * 16 + 14) // 16-bit: configure DMP for Android L and Invensense specific features
46+
47+
// indicates to DMP which sensors are available
48+
/* 1: gyro samples available
49+
2: accel samples available
50+
8: secondary samples available */
4351
#define DATA_RDY_STATUS (8 * 16 + 10) // 16-bit: indicates to DMP which sensors are available
52+
4453
// batch mode
4554
#define BM_BATCH_CNTR (27 * 16) // 32-bit: Batch counter
4655
#define BM_BATCH_THLD (19 * 16 + 12) // 32-bit: Batch mode threshold
4756
#define BM_BATCH_MASK (21 * 16 + 14) // 16-bit
57+
4858
// sensor output data rate: all 16-bit
4959
#define ODR_ACCEL (11 * 16 + 14) // ODR_ACCEL Register for accel ODR
5060
#define ODR_GYRO (11 * 16 + 10) // ODR_GYRO Register for gyro ODR
@@ -57,6 +67,7 @@ extern "C" {
5767
#define ODR_PRESSURE (11 * 16 + 12) // ODR_PRESSURE Register for pressure ODR
5868
#define ODR_GYRO_CALIBR (11 * 16 + 8) // ODR_GYRO_CALIBR Register for calibrated gyro ODR
5969
#define ODR_CPASS_CALIBR (11 * 16 + 4) // ODR_CPASS_CALIBR Register for calibrated compass ODR
70+
6071
// sensor output data rate counter: all 16-bit
6172
#define ODR_CNTR_ACCEL (9 * 16 + 14) // ODR_CNTR_ACCEL Register for accel ODR counter
6273
#define ODR_CNTR_GYRO (9 * 16 + 10) // ODR_CNTR_GYRO Register for gyro ODR counter
@@ -69,6 +80,7 @@ extern "C" {
6980
#define ODR_CNTR_PRESSURE (9 * 16 + 12) // ODR_CNTR_PRESSURE Register for pressure ODR counter
7081
#define ODR_CNTR_GYRO_CALIBR (9 * 16 + 8) // ODR_CNTR_GYRO_CALIBR Register for calibrated gyro ODR counter
7182
#define ODR_CNTR_CPASS_CALIBR (9 * 16 + 4) // ODR_CNTR_CPASS_CALIBR Register for calibrated compass ODR counter
83+
7284
// mounting matrix: all 32-bit
7385
#define CPASS_MTX_00 (23 * 16) // Compass mount matrix and scale
7486
#define CPASS_MTX_01 (23 * 16 + 4) // Compass mount matrix and scale
@@ -79,6 +91,7 @@ extern "C" {
7991
#define CPASS_MTX_20 (24 * 16 + 8) // Compass mount matrix and scale
8092
#define CPASS_MTX_21 (24 * 16 + 12) // Compass mount matrix and scale
8193
#define CPASS_MTX_22 (25 * 16) // Compass mount matrix and scale
94+
8295
// bias calibration: all 32-bit
8396
// The biases are 32-bits in chip frame in hardware unit scaled by:
8497
// 2^12 (FSR 4g) for accel, 2^15 for gyro, in uT scaled by 2^16 for compass.
@@ -91,25 +104,191 @@ extern "C" {
91104
#define CPASS_BIAS_X (126 * 16 + 4)
92105
#define CPASS_BIAS_Y (126 * 16 + 8)
93106
#define CPASS_BIAS_Z (126 * 16 + 12)
107+
108+
#define GYRO_ACCURACY (138 * 16 + 2)
109+
#define GYRO_BIAS_SET (138 * 16 + 6)
110+
#define GYRO_LAST_TEMPR (134 * 16)
111+
#define GYRO_SLOPE_X ( 78 * 16 + 4)
112+
#define GYRO_SLOPE_Y ( 78 * 16 + 8)
113+
#define GYRO_SLOPE_Z ( 78 * 16 + 12)
114+
115+
// parameters for accel calibration
116+
#define ACCEL_ACCURACY (97 * 16)
117+
#define ACCEL_CAL_RESET (77 * 16)
118+
#define ACCEL_VARIANCE_THRESH (93 * 16)
119+
#define ACCEL_CAL_RATE (94 * 16 + 4) // 16-bit
120+
#define ACCEL_PRE_SENSOR_DATA (97 * 16 + 4)
121+
#define ACCEL_COVARIANCE (101 * 16 + 8)
122+
#define ACCEL_ALPHA_VAR (91 * 16) // 32-bit: 1026019965 (225Hz) 977872018 (112Hz) 882002213 (56Hz)
123+
#define ACCEL_A_VAR (92 * 16) // 32-bit: 47721859 (225Hz) 95869806 (112Hz) 191739611 (56Hz)
124+
#define ACCEL_CAL_INIT (94 * 16 + 2)
125+
#define ACCEL_CAL_SCALE_COVQ_IN_RANGE (194 * 16)
126+
#define ACCEL_CAL_SCALE_COVQ_OUT_RANGE (195 * 16)
127+
#define ACCEL_CAL_TEMPERATURE_SENSITIVITY (194 * 16 + 4)
128+
#define ACCEL_CAL_TEMPERATURE_OFFSET_TRIM (194 * 16 + 12)
129+
130+
#define CPASS_ACCURACY (37 * 16)
131+
#define CPASS_BIAS_SET (34 * 16 + 14)
132+
#define MAR_MODE (37 * 16 + 2)
133+
#define CPASS_COVARIANCE (115 * 16)
134+
#define CPASS_COVARIANCE_CUR (118 * 16 + 8)
135+
#define CPASS_REF_MAG_3D (122 * 16)
136+
#define CPASS_CAL_INIT (114 * 16)
137+
#define CPASS_EST_FIRST_BIAS (113 * 16)
138+
#define MAG_DISTURB_STATE (113 * 16 + 2)
139+
#define CPASS_VAR_COUNT (112 * 16 + 6)
140+
#define CPASS_COUNT_7 ( 87 * 16 + 2)
141+
#define CPASS_MAX_INNO (124 * 16)
142+
#define CPASS_BIAS_OFFSET (113 * 16 + 4)
143+
#define CPASS_CUR_BIAS_OFFSET (114 * 16 + 4)
144+
#define CPASS_PRE_SENSOR_DATA ( 87 * 16 + 4)
145+
146+
// Compass Cal params to be adjusted according to sampling rate
147+
#define CPASS_TIME_BUFFER (112 * 16 + 14)
148+
#define CPASS_RADIUS_3D_THRESH_ANOMALY (112 * 16 + 8)
149+
150+
#define CPASS_STATUS_CHK (25 * 16 + 12)
151+
152+
// gains
153+
#define ACCEL_FB_GAIN (34 * 16)
154+
#define ACCEL_ONLY_GAIN (16 * 16 + 12) // 32-bit: 15252014 (225Hz) 30504029 (112Hz) 61117001 (56Hz)
155+
#define GYRO_SF (19 * 16) // 32-bit: gyro scaling factor
156+
157+
// 9-axis
158+
#define MAGN_THR_9X (80 * 16)
159+
#define MAGN_LPF_THR_9X (80 * 16 + 8)
160+
#define QFB_THR_9X (80 * 16 + 12)
161+
162+
// DMP running counter
163+
#define DMPRATE_CNTR (18 * 16 + 4)
164+
165+
// pedometer
166+
#define PEDSTD_BP_B (49 * 16 + 12)
167+
#define PEDSTD_BP_A4 (52 * 16)
168+
#define PEDSTD_BP_A3 (52 * 16 + 4)
169+
#define PEDSTD_BP_A2 (52 * 16 + 8)
170+
#define PEDSTD_BP_A1 (52 * 16 + 12)
171+
#define PEDSTD_SB (50 * 16 + 8)
172+
#define PEDSTD_SB_TIME (50 * 16 + 12)
173+
#define PEDSTD_PEAKTHRSH (57 * 16 + 8)
174+
#define PEDSTD_TIML (50 * 16 + 10)
175+
#define PEDSTD_TIMH (50 * 16 + 14)
176+
#define PEDSTD_PEAK (57 * 16 + 4)
177+
#define PEDSTD_STEPCTR (54 * 16)
178+
#define PEDSTD_STEPCTR2 (58 * 16 + 8)
179+
#define PEDSTD_TIMECTR (60 * 16 + 4)
180+
#define PEDSTD_DECI (58 * 16)
181+
#define PEDSTD_SB2 (60 * 16 + 14)
182+
#define STPDET_TIMESTAMP (18 * 16 + 8)
183+
#define PEDSTEP_IND (19 * 16 + 4)
184+
#define PED_Y_RATIO (17 * 16 + 0)
185+
186+
// SMD
187+
#define SMD_VAR_TH (141 * 16 + 12)
188+
#define SMD_VAR_TH_DRIVE (143 * 16 + 12)
189+
#define SMD_DRIVE_TIMER_TH (143 * 16 + 8)
190+
#define SMD_TILT_ANGLE_TH (179 * 16 + 12)
191+
#define BAC_SMD_ST_TH (179 * 16 + 8)
192+
#define BAC_ST_ALPHA4 (180 * 16 + 12)
193+
#define BAC_ST_ALPHA4A (176 * 16 + 12)
194+
195+
// Wake on Motion
196+
#define WOM_ENABLE (64 * 16 + 14)
197+
#define WOM_STATUS (64 * 16 + 6)
198+
#define WOM_THRESHOLD_DMP (64 * 16) // Renamed by PaulZC to avoid duplication with the Bank 2 Reg 0x13
199+
#define WOM_CNTR_TH (64 * 16 + 12)
200+
201+
// Activity Recognition
202+
#define BAC_RATE (48 * 16 + 10)
203+
#define BAC_STATE (179 * 16 + 0)
204+
#define BAC_STATE_PREV (179 * 16 + 4)
205+
#define BAC_ACT_ON (182 * 16 + 0)
206+
#define BAC_ACT_OFF (183 * 16 + 0)
207+
#define BAC_STILL_S_F (177 * 16 + 0)
208+
#define BAC_RUN_S_F (177 * 16 + 4)
209+
#define BAC_DRIVE_S_F (178 * 16 + 0)
210+
#define BAC_WALK_S_F (178 * 16 + 4)
211+
#define BAC_SMD_S_F (178 * 16 + 8)
212+
#define BAC_BIKE_S_F (178 * 16 + 12)
213+
#define BAC_E1_SHORT (146 * 16 + 0)
214+
#define BAC_E2_SHORT (146 * 16 + 4)
215+
#define BAC_E3_SHORT (146 * 16 + 8)
216+
#define BAC_VAR_RUN (148 * 16 + 12)
217+
#define BAC_TILT_INIT (181 * 16 + 0)
218+
#define BAC_MAG_ON (225 * 16 + 0)
219+
#define BAC_PS_ON (74 * 16 + 0)
220+
#define BAC_BIKE_PREFERENCE (173 * 16 + 8)
221+
#define BAC_MAG_I2C_ADDR (229 * 16 + 8)
222+
#define BAC_PS_I2C_ADDR (75 * 16 + 4)
223+
#define BAC_DRIVE_CONFIDENCE (144 * 16 + 0)
224+
#define BAC_WALK_CONFIDENCE (144 * 16 + 4)
225+
#define BAC_SMD_CONFIDENCE (144 * 16 + 8)
226+
#define BAC_BIKE_CONFIDENCE (144 * 16 + 12)
227+
#define BAC_STILL_CONFIDENCE (145 * 16 + 0)
228+
#define BAC_RUN_CONFIDENCE (145 * 16 + 4)
229+
#define BAC_MODE_CNTR (150 * 16)
230+
#define BAC_STATE_T_PREV (185 * 16 + 4)
231+
#define BAC_ACT_T_ON (184 * 16 + 0)
232+
#define BAC_ACT_T_OFF (184 * 16 + 4)
233+
#define BAC_STATE_WRDBS_PREV (185 * 16 + 8)
234+
#define BAC_ACT_WRDBS_ON (184 * 16 + 8)
235+
#define BAC_ACT_WRDBS_OFF (184 * 16 + 12)
236+
#define BAC_ACT_ON_OFF (190 * 16 + 2)
237+
#define PREV_BAC_ACT_ON_OFF (188 * 16 + 2)
238+
#define BAC_CNTR (48 * 16 + 2)
239+
240+
// Flip/Pick-up
241+
#define FP_VAR_ALPHA (245 * 16 + 8)
242+
#define FP_STILL_TH (246 * 16 + 4)
243+
#define FP_MID_STILL_TH (244 * 16 + 8)
244+
#define FP_NOT_STILL_TH (246 * 16 + 8)
245+
#define FP_VIB_REJ_TH (241 * 16 + 8)
246+
#define FP_MAX_PICKUP_T_TH (244 * 16 + 12)
247+
#define FP_PICKUP_TIMEOUT_TH (248 * 16 + 8)
248+
#define FP_STILL_CONST_TH (246 * 16 + 12)
249+
#define FP_MOTION_CONST_TH (240 * 16 + 8)
250+
#define FP_VIB_COUNT_TH (242 * 16 + 8)
251+
#define FP_STEADY_TILT_TH (247 * 16 + 8)
252+
#define FP_STEADY_TILT_UP_TH (242 * 16 + 12)
253+
#define FP_Z_FLAT_TH_MINUS (243 * 16 + 8)
254+
#define FP_Z_FLAT_TH_PLUS (243 * 16 + 12)
255+
#define FP_DEV_IN_POCKET_TH (76 * 16 + 12)
256+
#define FP_PICKUP_CNTR (247 * 16 + 4)
257+
#define FP_RATE (240 * 16 + 12)
258+
259+
// Gyro FSR
260+
#define GYRO_FULLSCALE (72 * 16 + 12)
261+
94262
// Accel FSR
95263
// The DMP scales accel raw data internally to align 1g as 2^25.
96264
// To do this and output hardware unit again as configured FSR, write 0x4000000 to ACC_SCALE DMP register, and write 0x40000 to ACC_SCALE2 DMP register.
97265
#define ACC_SCALE (30 * 16 + 0) // 32-bit: Write accel scaling value for internal use
98266
#define ACC_SCALE2 (79 * 16 + 4) // 32-bit: Write accel scaling down value
99-
// pedometer
100-
#define PEDSTD_STEPCTR (54 * 16) // 32-bit: step count (big endian)
101-
#define PEDSTD_TIMECTR (60 * 16 + 4) // 32-bit: walk time (big endian)
102-
// Activity Recognition (BAC)
103-
#define BAC_RATE (48 * 16 + 10) // 16-bit
104-
// parameters for accel calibration
105-
#define ACCEL_CAL_RATE (94 * 16 + 4) // 16-bit
106-
#define ACCEL_ALPHA_VAR (91 * 16) // 32-bit: 1026019965 (225Hz) 977872018 (112Hz) 882002213 (56Hz)
107-
#define ACCEL_A_VAR (92 * 16) // 32-bit: 47721859 (225Hz) 95869806 (112Hz) 191739611 (56Hz)
108-
// parameters for compass calibration
109-
#define CPASS_TIME_BUFFER (112 * 16 + 14) // 16-bit: running rate of compass. e.g. 70 (70Hz)
110-
// gains
111-
#define ACCEL_ONLY_GAIN (16 * 16 + 12) // 32-bit: 15252014 (225Hz) 30504029 (112Hz) 61117001 (56Hz)
112-
#define GYRO_SF (19 * 16) // 32-bit: gyro scaling factor
267+
268+
// EIS authentication
269+
#define EIS_AUTH_INPUT (160 * 16 + 4)
270+
#define EIS_AUTH_OUTPUT (160 * 16 + 0)
271+
272+
// B2S
273+
#define B2S_RATE (48 * 16 + 8)
274+
275+
// B2S mounting matrix
276+
#define B2S_MTX_00 (208 * 16)
277+
#define B2S_MTX_01 (208 * 16 + 4)
278+
#define B2S_MTX_02 (208 * 16 + 8)
279+
#define B2S_MTX_10 (208 * 16 + 12)
280+
#define B2S_MTX_11 (209 * 16)
281+
#define B2S_MTX_12 (209 * 16 + 4)
282+
#define B2S_MTX_20 (209 * 16 + 8)
283+
#define B2S_MTX_21 (209 * 16 + 12)
284+
#define B2S_MTX_22 (210 * 16)
285+
286+
// Dmp3 orientation parameters (Q30) initialization
287+
#define Q0_QUAT6 (33 * 16 + 0)
288+
#define Q1_QUAT6 (33 * 16 + 4)
289+
#define Q2_QUAT6 (33 * 16 + 8)
290+
#define Q3_QUAT6 (33 * 16 + 12)
291+
113292

114293
enum DMP_ODR_Registers {
115294
DMP_ODR_Reg_Accel = ODR_ACCEL, // ODR_ACCEL Register for accel ODR
@@ -385,23 +564,26 @@ typedef struct // DMP Secondary On/Off data
385564
#define icm_20948_DMP_Header2_Bytes 2
386565
#define icm_20948_DMP_Raw_Accel_Bytes 6
387566
#define icm_20948_DMP_Raw_Gyro_Bytes 6
567+
#define icm_20948_DMP_Gyro_Bias_Bytes 6
388568
#define icm_20948_DMP_Compass_Bytes 6
389569
#define icm_20948_DMP_ALS_Bytes 8
390570
#define icm_20948_DMP_Quat6_Bytes 12
391571
#define icm_20948_DMP_Quat9_Bytes 14
572+
// <-- lcm20948MPUFifoControl.c suggests icm_20948_DMP_Step_Detector_Bytes comes here <--
392573
#define icm_20948_DMP_PQuat6_Bytes 6
393574
#define icm_20948_DMP_Geomag_Bytes 14
394575
#define icm_20948_DMP_Pressure_Bytes 6
395-
#define icm_20948_DMP_Gyro_Calibr_Bytes 12
576+
#define icm_20948_DMP_Gyro_Calibr_Bytes 12 // lcm20948MPUFifoControl.c suggests icm_20948_DMP_Gyro_Calibr_Bytes does not exist?
396577
#define icm_20948_DMP_Compass_Calibr_Bytes 12
397-
#define icm_20948_DMP_Step_Detector_Bytes 4
578+
#define icm_20948_DMP_Step_Detector_Bytes 4 // See note above
398579
#define icm_20948_DMP_Accel_Accuracy_Bytes 2
399580
#define icm_20948_DMP_Gyro_Accuracy_Bytes 2
400581
#define icm_20948_DMP_Compass_Accuracy_Bytes 2
401-
#define icm_20948_DMP_Fsync_Detection_Bytes 2
582+
#define icm_20948_DMP_Fsync_Detection_Bytes 2 // lcm20948MPUFifoControl.c suggests icm_20948_DMP_Fsync_Detection_Bytes does not exist?
402583
#define icm_20948_DMP_Pickup_Bytes 2
403584
#define icm_20948_DMP_Activity_Recognition_Bytes 6
404585
#define icm_20948_DMP_Secondary_On_Off_Bytes 2
586+
#define icm_20948_DMP_Footer_Bytes 2
405587

406588
// ICM-20948 data is big-endian. We need to make it little-endian when writing into icm_20948_DMP_data_t
407589
const int DMP_Quat9_Byte_Ordering[icm_20948_DMP_Quat9_Bytes] =
@@ -448,7 +630,7 @@ typedef struct
448630
int16_t Y;
449631
int16_t Z;
450632
} Data;
451-
} Raw_Gyro;
633+
} Raw_Gyro; // Note: may also include 3*16 gyro bias?
452634
union
453635
{
454636
uint8_t Bytes[icm_20948_DMP_Compass_Bytes];

0 commit comments

Comments
 (0)