1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8 #ifndef _FSL_FXOS_H_
9 #define _FSL_FXOS_H_
10
11 #include "fsl_common.h"
12
13 #define FXOS8700CQ_ACCEL_RESOLUTION_BITS 14
14
15 /*
16 * STATUS Register
17 */
18 #define STATUS_00_REG 0x00
19
20 #define ZYXOW_MASK 0x80
21 #define ZOW_MASK 0x40
22 #define YOW_MASK 0x20
23 #define XOW_MASK 0x10
24 #define ZYXDR_MASK 0x08
25 #define ZDR_MASK 0x04
26 #define YDR_MASK 0x02
27 #define XDR_MASK 0x01
28
29 /*
30 * F_STATUS FIFO Status Register
31 */
32 #define F_STATUS_REG 0x00
33
34 #define F_OVF_MASK 0x80
35 #define F_WMRK_FLAG_MASK 0x40
36 #define F_CNT5_MASK 0x20
37 #define F_CNT4_MASK 0x10
38 #define F_CNT3_MASK 0x08
39 #define F_CNT2_MASK 0x04
40 #define F_CNT1_MASK 0x02
41 #define F_CNT0_MASK 0x01
42 #define F_CNT_MASK 0x3F
43
44 /*
45 * XYZ Data Registers
46 */
47 #define OUT_X_MSB_REG 0x01
48 #define OUT_X_LSB_REG 0x02
49 #define OUT_Y_MSB_REG 0x03
50 #define OUT_Y_LSB_REG 0x04
51 #define OUT_Z_MSB_REG 0x05
52 #define OUT_Z_LSB_REG 0x06
53
54 /*
55 * F_SETUP FIFO Setup Register
56 */
57 #define F_SETUP_REG 0x09
58
59 #define F_MODE1_MASK 0x80
60 #define F_MODE0_MASK 0x40
61 #define F_WMRK5_MASK 0x20
62 #define F_WMRK4_MASK 0x10
63 #define F_WMRK3_MASK 0x08
64 #define F_WMRK2_MASK 0x04
65 #define F_WMRK1_MASK 0x02
66 #define F_WMRK0_MASK 0x01
67 #define F_MODE_MASK 0xC0
68 #define F_WMRK_MASK 0x3F
69
70 #define F_MODE_DISABLED 0x00
71 #define F_MODE_CIRCULAR (F_MODE0_MASK)
72 #define F_MODE_FILL (F_MODE1_MASK)
73 #define F_MODE_TRIGGER (F_MODE1_MASK + F_MODE0_MASK)
74
75 /*
76 * TRIG_CFG FIFO Trigger Configuration Register
77 */
78 #define TRIG_CFG_REG 0x0A
79
80 #define TRIG_TRANS_MASK 0x20
81 #define TRIG_LNDPRT_MASK 0x10
82 #define TRIG_PULSE_MASK 0x08
83 #define TRIG_FF_MT_MASK 0x04
84
85 /*
86 * SYSMOD System Mode Register
87 */
88 #define SYSMOD_REG 0x0B
89
90 #define FGERR_MASK 0x80 /* MMA8451 only */
91 #define FGT_4_MASK 0x40 /* MMA8451 only */
92 #define FGT_3_MASK 0x20 /* MMA8451 only */
93 #define FGT_2_MASK 0x10 /* MMA8451 only */
94 #define FGT_1_MASK 0x08 /* MMA8451 only */
95 #define FGT_0_MASK 0x04 /* MMA8451 only */
96 #define FGT_MASK 0x7C /* MMA8451 only */
97 #define SYSMOD1_MASK 0x02
98 #define SYSMOD0_MASK 0x01
99 #define SYSMOD_MASK 0x03
100
101 #define SYSMOD_STANDBY 0x00
102 #define SYSMOD_WAKE (SYSMOD0_MASK)
103 #define SYSMOD_SLEEP (SYSMOD1_MASK)
104
105 /*
106 * INT_SOURCE System Interrupt Status Register
107 */
108 #define INT_SOURCE_REG 0x0C
109
110 #define SRC_ASLP_MASK 0x80
111 #define SRC_FIFO_MASK 0x40
112 #define SRC_TRANS_MASK 0x20
113 #define SRC_LNDPRT_MASK 0x10
114 #define SRC_PULSE_MASK 0x08
115 #define SRC_FF_MT_MASK 0x04
116 #define SRC_DRDY_MASK 0x01
117
118 /*
119 * WHO_AM_I Device ID Register
120 */
121 #define WHO_AM_I_REG 0x0D
122
123 /* Content */
124 #define kFXOS_WHO_AM_I_Device_ID 0xC7U
125
126 /* XYZ_DATA_CFG Sensor Data Configuration Register */
127 #define XYZ_DATA_CFG_REG 0x0E
128
129 #define HPF_OUT_MASK 0x10
130 #define FS1_MASK 0x02
131 #define FS0_MASK 0x01
132 #define FS_MASK 0x03
133
134 #define FULL_SCALE_2G 0x00
135 #define FULL_SCALE_4G (FS0_MASK)
136 #define FULL_SCALE_8G (FS1_MASK)
137
138 /* HP_FILTER_CUTOFF High Pass Filter Register */
139 #define HP_FILTER_CUTOFF_REG 0x0F
140
141 #define PULSE_HPF_BYP_MASK 0x20
142 #define PULSE_LPF_EN_MASK 0x10
143 #define SEL1_MASK 0x02
144 #define SEL0_MASK 0x01
145 #define SEL_MASK 0x03
146
147 /*
148 * PL_STATUS Portrait/Landscape Status Register
149 */
150 #define PL_STATUS_REG 0x10
151
152 #define NEWLP_MASK 0x80
153 #define LO_MASK 0x40
154 #define LAPO1_MASK 0x04
155 #define LAPO0_MASK 0x02
156 #define BAFRO_MASK 0x01
157 #define LAPO_MASK 0x06
158
159 /*
160 * PL_CFG Portrait/Landscape Configuration Register
161 */
162 #define PL_CFG_REG 0x11
163
164 #define DBCNTM_MASK 0x80
165 #define PL_EN_MASK 0x40
166
167 /*
168 * PL_COUNT Portrait/Landscape Debounce Register
169 */
170 #define PL_COUNT_REG 0x12
171
172 /*
173 * PL_BF_ZCOMP Back/Front and Z Compensation Register
174 */
175 #define PL_BF_ZCOMP_REG 0x13
176
177 #define BKFR1_MASK 0x80
178 #define BKFR0_MASK 0x40
179 #define ZLOCK2_MASK 0x04
180 #define ZLOCK1_MASK 0x02
181 #define ZLOCK0_MASK 0x01
182 #define BKFR_MASK 0xC0
183 #define ZLOCK_MASK 0x07
184
185 /*
186 * PL_P_L_THS Portrait to Landscape Threshold Register
187 */
188 #define PL_P_L_THS_REG 0x14
189
190 #define P_L_THS4_MASK 0x80
191 #define P_L_THS3_MASK 0x40
192 #define P_L_THS2_MASK 0x20
193 #define P_L_THS1_MASK 0x10
194 #define P_L_THS0_MASK 0x08
195 #define HYS2_MASK 0x04
196 #define HYS1_MASK 0x02
197 #define HYS0_MASK 0x01
198 #define P_L_THS_MASK 0xF8
199 #define HYS_MASK 0x07
200
201 /*
202 * FF_MT_CFG Freefall and Motion Configuration Register
203 */
204 #define FF_MT_CFG_REG 0x15
205
206 #define ELE_MASK 0x80
207 #define OAE_MASK 0x40
208 #define ZEFE_MASK 0x20
209 #define YEFE_MASK 0x10
210 #define XEFE_MASK 0x08
211
212 /*
213 * FF_MT_SRC Freefall and Motion Source Registers
214 */
215 #define FF_MT_SRC_REG 0x16
216
217 #define EA_MASK 0x80
218 #define ZHE_MASK 0x20
219 #define ZHP_MASK 0x10
220 #define YHE_MASK 0x08
221 #define YHP_MASK 0x04
222 #define XHE_MASK 0x02
223 #define XHP_MASK 0x01
224
225 /*
226 * FF_MT_THS Freefall and Motion Threshold Registers
227 * TRANSIENT_THS Transient Threshold Register
228 */
229 #define FT_MT_THS_REG 0x17
230 #define TRANSIENT_THS_REG 0x1F
231
232 #define DBCNTM_MASK 0x80
233 #define THS6_MASK 0x40
234 #define THS5_MASK 0x20
235 #define THS4_MASK 0x10
236 #define THS3_MASK 0x08
237 #define THS2_MASK 0x04
238 #define TXS1_MASK 0x02
239 #define THS0_MASK 0x01
240 #define THS_MASK 0x7F
241
242 /* FF_MT_COUNT Freefall Motion Count Registers */
243 #define FF_MT_COUNT_REG 0x18
244
245 /* TRANSIENT_CFG Transient Configuration Register */
246 #define TRANSIENT_CFG_REG 0x1D
247
248 #define TELE_MASK 0x10
249 #define ZTEFE_MASK 0x08
250 #define YTEFE_MASK 0x04
251 #define XTEFE_MASK 0x02
252 #define HPF_BYP_MASK 0x01
253
254 /* TRANSIENT_SRC Transient Source Register */
255 #define TRANSIENT_SRC_REG 0x1E
256
257 #define TEA_MASK 0x40
258 #define ZTRANSE_MASK 0x20
259 #define Z_TRANS_POL_MASK 0x10
260 #define YTRANSE_MASK 0x08
261 #define Y_TRANS_POL_MASK 0x04
262 #define XTRANSE_MASK 0x02
263 #define X_TRANS_POL_MASK 0x01
264
265 /* TRANSIENT_COUNT Transient Debounce Register */
266 #define TRANSIENT_COUNT_REG 0x20
267
268 /* PULSE_CFG Pulse Configuration Register */
269 #define PULSE_CFG_REG 0x21
270
271 #define DPA_MASK 0x80
272 #define PELE_MASK 0x40
273 #define ZDPEFE_MASK 0x20
274 #define ZSPEFE_MASK 0x10
275 #define YDPEFE_MASK 0x08
276 #define YSPEFE_MASK 0x04
277 #define XDPEFE_MASK 0x02
278 #define XSPEFE_MASK 0x01
279
280 /* PULSE_SRC Pulse Source Register */
281 #define PULSE_SRC_REG 0x22
282
283 #define PEA_MASK 0x80
284 #define AXZ_MASK 0x40
285 #define AXY_MASK 0x20
286 #define AXX_MASK 0x10
287 #define DPE_MASK 0x08
288 #define POLZ_MASK 0x04
289 #define POLY_MASK 0x02
290 #define POLX_MASK 0x01
291
292 /* PULSE_THS XYZ Pulse Threshold Registers */
293 #define PULSE_THSX_REG 0x23
294 #define PULSE_THSY_REG 0x24
295 #define PULSE_THSZ_REG 0x25
296
297 #define PTHS_MASK 0x7F
298
299 /* PULSE_TMLT Pulse Time Window Register */
300 #define PULSE_TMLT_REG 0x26
301
302 /* PULSE_LTCY Pulse Latency Timer Register */
303 #define PULSE_LTCY_REG 0x27
304
305 /* PULSE_WIND Second Pulse Time Window Register */
306 #define PULSE_WIND_REG 0x28
307
308 /* ASLP_COUNT Auto Sleep Inactivity Timer Register */
309 #define ASLP_COUNT_REG 0x29
310
311 /* CTRL_REG1 System Control 1 Register */
312 #define CTRL_REG1 0x2A
313
314 #define ASLP_RATE1_MASK 0x80
315 #define ASLP_RATE0_MASK 0x40
316 #define DR2_MASK 0x20
317 #define DR1_MASK 0x10
318 #define DR0_MASK 0x08U
319 #define LNOISE_MASK 0x04
320 #define FREAD_MASK 0x02
321 #define ACTIVE_MASK 0x01U
322 #define ASLP_RATE_MASK 0xC0
323 #define DR_MASK 0x38
324
325 #define ASLP_RATE_20MS 0x00
326 #define ASLP_RATE_80MS (ASLP_RATE0_MASK)
327 #define ASLP_RATE_160MS (ASLP_RATE1_MASK)
328 #define ASLP_RATE_640MS (ASLP_RATE1_MASK + ASLP_RATE0_MASK)
329
330 #define ASLP_RATE_50HZ (ASLP_RATE_20MS)
331 #define ASLP_RATE_12_5HZ (ASLP_RATE_80MS)
332 #define ASLP_RATE_6_25HZ (ASLP_RATE_160MS)
333 #define ASLP_RATE_1_56HZ (ASLP_RATE_640MS)
334
335 #define HYB_ASLP_RATE_25HZ (ASLP_RATE_20MS)
336 #define HYB_ASLP_RATE_6_25HZ (ASLP_RATE_80MS)
337 #define HYB_ASLP_RATE_1_56HZ (ASLP_RATE_160MS)
338 #define HYB_ASLP_RATE_0_8HZ (ASLP_RATE_640MS)
339
340 #define DATA_RATE_1250US 0x00
341 #define DATA_RATE_2500US (DR0_MASK)
342 #define DATA_RATE_5MS (DR1_MASK)
343 #define DATA_RATE_10MS (DR1_MASK + DR0_MASK)
344 #define DATA_RATE_20MS (DR2_MASK)
345 #define DATA_RATE_80MS (DR2_MASK + DR0_MASK)
346 #define DATA_RATE_160MS (DR2_MASK + DR1_MASK)
347 #define DATA_RATE_640MS (DR2_MASK + DR1_MASK + DR0_MASK)
348
349 #define DATA_RATE_800HZ (DATA_RATE_1250US)
350 #define DATA_RATE_400HZ (DATA_RATE_2500US)
351 #define DATA_RATE_200HZ (DATA_RATE_5MS)
352 #define DATA_RATE_100HZ (DATA_RATE_10MS)
353 #define DATA_RATE_50HZ (DATA_RATE_20MS)
354 #define DATA_RATE_12_5HZ (DATA_RATE_80MS)
355 #define DATA_RATE_6_25HZ (DATA_RATE_160MS)
356 #define DATA_RATE_1_56HZ (DATA_RATE_640MS)
357
358 /* for hybrid (TO, Aug 2012) */
359 #define HYB_DATA_RATE_400HZ (DATA_RATE_1250US)
360 #define HYB_DATA_RATE_200HZ (DATA_RATE_2500US)
361 #define HYB_DATA_RATE_100HZ (DATA_RATE_5MS)
362 #define HYB_DATA_RATE_50HZ (DATA_RATE_10MS)
363 #define HYB_DATA_RATE_25HZ (DATA_RATE_20MS)
364 #define HYB_DATA_RATE_6_25HZ (DATA_RATE_80MS)
365 #define HYB_DATA_RATE_3_15HZ (DATA_RATE_160MS)
366 #define HYB_DATA_RATE_0_8HZ (DATA_RATE_640MS)
367
368 #define ACTIVE (ACTIVE_MASK)
369 #define STANDBY 0x00
370
371 /* CTRL_REG2 System Control 2 Register */
372 #define CTRL_REG2 0x2B
373
374 #define ST_MASK 0x80
375 #define RST_MASK 0x40
376 #define SMODS1_MASK 0x10
377 #define SMODS0_MASK 0x08
378 #define SLPE_MASK 0x04
379 #define MODS1_MASK 0x02
380 #define MODS0_MASK 0x01
381 #define SMODS_MASK 0x18
382 #define MODS_MASK 0x03
383
384 #define SMOD_NORMAL 0x00
385 #define SMOD_LOW_NOISE (SMODS0_MASK)
386 #define SMOD_HIGH_RES (SMODS1_MASK)
387 #define SMOD_LOW_POWER (SMODS1_MASK + SMODS0_MASK)
388
389 #define MOD_NORMAL 0x00
390 #define MOD_LOW_NOISE (MODS0_MASK)
391 #define MOD_HIGH_RES (MODS1_MASK)
392 #define MOD_LOW_POWER (MODS1_MASK + MODS0_MASK)
393
394 /* CTRL_REG3 Interrupt Control Register */
395 #define CTRL_REG3 0x2C
396
397 #define FIFO_GATE_MASK 0x80
398 #define WAKE_TRANS_MASK 0x40
399 #define WAKE_LNDPRT_MASK 0x20
400 #define WAKE_PULSE_MASK 0x10
401 #define WAKE_FF_MT_MASK 0x08
402 #define IPOL_MASK 0x02
403 #define PP_OD_MASK 0x01
404
405 /* CTRL_REG4 Interrupt Enable Register */
406 #define CTRL_REG4 0x2D
407
408 #define INT_EN_ASLP_MASK 0x80
409 #define INT_EN_FIFO_MASK 0x40
410 #define INT_EN_TRANS_MASK 0x20
411 #define INT_EN_LNDPRT_MASK 0x10
412 #define INT_EN_PULSE_MASK 0x08
413 #define INT_EN_FF_MT_MASK 0x04
414 #define INT_EN_DRDY_MASK 0x01
415
416 /* CTRL_REG5 Interrupt Configuration Register */
417 #define CTRL_REG5 0x2E
418
419 #define INT_CFG_ASLP_MASK 0x80
420 #define INT_CFG_FIFO_MASK 0x40
421 #define INT_CFG_TRANS_MASK 0x20
422 #define INT_CFG_LNDPRT_MASK 0x10
423 #define INT_CFG_PULSE_MASK 0x08
424 #define INT_CFG_FF_MT_MASK 0x04
425 #define INT_CFG_DRDY_MASK 0x01
426
427 /* XYZ Offset Correction Registers */
428 #define OFF_X_REG 0x2F
429 #define OFF_Y_REG 0x30
430 #define OFF_Z_REG 0x31
431
432 /* M_DR_STATUS Register */
433 #define M_DR_STATUS_REG 0x32
434
435 #define ZYXOW_MASK 0x80
436 #define ZOW_MASK 0x40
437 #define YOW_MASK 0x20
438 #define XOW_MASK 0x10
439 #define ZYXDR_MASK 0x08
440 #define ZDR_MASK 0x04
441 #define YDR_MASK 0x02
442 #define XDR_MASK 0x01
443
444 /* MAG XYZ Data Registers */
445 #define M_OUT_X_MSB_REG 0x33
446 #define M_OUT_X_LSB_REG 0x34
447 #define M_OUT_Y_MSB_REG 0x35
448 #define M_OUT_Y_LSB_REG 0x36
449 #define M_OUT_Z_MSB_REG 0x37
450 #define M_OUT_Z_LSB_REG 0x38
451
452 /* MAG CMP Data Registers */
453 #define CMP_X_MSB_REG 0x39
454 #define CMP_X_LSB_REG 0x3A
455 #define CMP_Y_MSB_REG 0x3B
456 #define CMP_Y_LSB_REG 0x3C
457 #define CMP_Z_MSB_REG 0x3D
458 #define CMP_Z_LSB_REG 0x3E
459
460 /* MAG XYZ Offset Correction Registers */
461 #define M_OFF_X_MSB_REG 0x3F
462 #define M_OFF_X_LSB_REG 0x40
463 #define M_OFF_Y_MSB_REG 0x41
464 #define M_OFF_Y_LSB_REG 0x42
465 #define M_OFF_Z_MSB_REG 0x43
466 #define M_OFF_Z_LSB_REG 0x44
467
468 /* MAG MAX XYZ Registers */
469 #define MAX_X_MSB_REG 0x45
470 #define MAX_X_LSB_REG 0x46
471 #define MAX_Y_MSB_REG 0x47
472 #define MAX_Y_LSB_REG 0x48
473 #define MAX_Z_MSB_REG 0x49
474 #define MAX_Z_LSB_REG 0x4A
475
476 /* MAG MIN XYZ Registers */
477 #define MIN_X_MSB_REG 0x4B
478 #define MIN_X_LSB_REG 0x4C
479 #define MIN_Y_MSB_REG 0x4D
480 #define MIN_Y_LSB_REG 0x4E
481 #define MIN_Z_MSB_REG 0x4F
482 #define MIN_Z_LSB_REG 0x50
483
484 /* TEMP Registers */
485 #define TEMP_REG 0x51
486
487 /* M_THS CONFIG Registers */
488 #define M_THS_CFG_REG 0x52
489
490 /* M_THS SRC Registers */
491 #define M_THS_SRC_REG 0x53
492
493 /* MAG THRESHOLD XYZ Registers */
494 #define M_THS_X_MSB_REG 0x54
495 #define M_THS_X_LSB_REG 0x55
496 #define M_THS_Y_MSB_REG 0x56
497 #define M_THS_Y_LSB_REG 0x57
498 #define M_THS_Z_MSB_REG 0x58
499 #define M_THS_Z_LSB_REG 0x59
500
501 /* M_THS COUNT Registers */
502 #define M_THS_COUNT 0x5A
503
504 /* MAG CTRL_REG1 System Control 1 Register */
505 #define M_CTRL_REG1 0x5B
506
507 #define M_ACAL_MASK 0x80
508 #define M_RST_MASK 0x40U
509 #define M_OST_MASK 0x20
510 #define M_OSR2_MASK 0x10
511 #define M_OSR1_MASK 0x08
512 #define M_OSR0_MASK 0x04
513 #define M_HMS1_MASK 0x02
514 #define M_HMS0_MASK 0x01
515 #define M_OSR_MASK 0x1CU
516 #define M_HMS_MASK 0x03U
517
518 /* OSR Selections */
519 #define M_OSR_1_56_HZ 0x00
520 #define M_OSR_6_25_HZ M_OSR0_MASK
521 #define M_OSR_12_5_HZ M_OSR1_MASK
522 #define M_OSR_50_HZ M_OSR1_MASK + M_OSR0_MASK
523 #define M_OSR_100_HZ M_OSR2_MASK
524 #define M_OSR_200_HZ M_OSR2_MASK + M_OSR0_MASK
525 #define M_OSR_400_HZ M_OSR2_MASK + M_OSR1_MASK
526 #define M_OSR_800_HZ M_OSR2_MASK + M_OSR1_MASK + M_OSR0_MASK
527
528 /* Hybrid Mode Selection */
529 #define ACCEL_ACTIVE 0x00
530 #define MAG_ACTIVE M_HMS0_MASK
531 #define HYBRID_ACTIVE (M_HMS1_MASK | M_HMS0_MASK)
532
533 /* MAG CTRL_REG2 System Control 2 Register */
534 #define M_CTRL_REG2 0x5C
535
536 #define M_HYB_AUTOINC_MASK 0x20
537 #define M_MAXMIN_DIS_MASK 0x10
538 #define M_MAXMIN_DIS_THS_MASK 0x08
539 #define M_MAXMIN_RST_MASK 0x04
540 #define M_RST_CNT1_MASK 0x02
541 #define M_RST_CNT0_MASK 0x01
542
543 /* Mag Auto-Reset De-Gauss Frequency */
544 #define RST_ODR_CYCLE 0x00
545 #define RST_16_ODR_CYCLE M_RST_CNT0_MASK
546 #define RST_512_ODR_CYCLE M_RST_CNT1_MASK
547 #define RST_DISABLED M_RST_CNT1_MASK + M_RST_CNT0_MASK
548
549 /* MAG CTRL_REG3 System Control 3 Register */
550 #define M_CTRL_REG3 0x5D
551
552 #define M_RAW_MASK 0x80
553 #define M_ASLP_OS_2_MASK 0x40
554 #define M_ASLP_OS_1_MASK 0x20
555 #define M_ASLP_OS_0_MASK 0x10
556 #define M_THS_XYZ_MASK 0x08
557 #define M_ST_Z_MASK 0x04
558 #define M_ST_XY1_MASK 0x02
559 #define M_ST_XY0_MASK 0x01
560 #define M_ASLP_OSR_MASK 0x70
561 #define M_ST_XY_MASK 0x03
562
563 /* OSR Selections */
564 #define M_ASLP_OSR_1_56_HZ 0x00
565 #define M_ASLP_OSR_6_25_HZ M_ASLP_OS_0_MASK
566 #define M_ASLP_OSR_12_5_HZ M_ASLP_OS_1_MASK
567 #define M_ASLP_OSR_50_HZ M_ASLP_OS_1_MASK + M_ASLP_OS_0_MASK
568 #define M_ASLP_OSR_100_HZ M_ASLP_OS_2_MASK
569 #define M_ASLP_OSR_200_HZ M_ASLP_OS_2_MASK + M_ASLP_OS_0_MASK
570 #define M_ASLP_OSR_400_HZ M_ASLP_OS_2_MASK + M_ASLP_OS_1_MASK
571 #define M_ASLP_OSR_800_HZ M_ASLP_OS_2_MASK + M_ASLP_OS_1_MASK + M_ASLP_OS_0_MASK
572
573 /* MAG INT SOURCE Register */
574 #define M_INT_SOURCE 0x5E
575
576 #define SRC_M_DRDY_MASK 0x04
577 #define SRC_M_VECM_MASK 0x02
578 #define SRC_M_THS_MASK 0x01
579
580 /* ACCEL VECTOR CONFIG Register */
581 #define A_VECM_CFG 0x5F
582
583 #define A_VECM_INIT_CFG_MASK 0x40
584 #define A_VECM_INIT_EN_MASK 0x20
585 #define A_VECM_WAKE_EN_MASK 0x10
586 #define A_VECM_EN_MASK 0x08
587 #define A_VECM_UPDM_MASK 0x04
588 #define A_VECM_INITM_MASK 0x02
589 #define A_VECM_ELE_MASK 0x01
590
591 /* ACCEL VECTOR THS MSB AND LSB Register */
592 #define A_VECM_THS_MSB 0x60
593
594 #define A_VECM_DBCNTM_MASK 0x80
595
596 #define A_VECM_THS_LSB 0x61
597
598 /* ACCEL VECTOR CNT Register */
599 #define A_VECM_CNT 0x62
600
601 /* ACCEL INITIAL XYZ VECTORS Register */
602 #define A_VECM_INITX_MSB 0x63
603 #define A_VECM_INITX_LSB 0x64
604 #define A_VECM_INITY_MSB 0x65
605 #define A_VECM_INITY_LSB 0x66
606 #define A_VECM_INITZ_MSB 0x67
607 #define A_VECM_INITZ_LSB 0x68
608
609 /* MAG VECTOR CONFIG Register */
610 #define M_VECM_CFG 0x69
611
612 #define M_VECM_INIT_CFG_MASK 0x40
613 #define M_VECM_INIT_EN_MASK 0x20
614 #define M_VECM_WAKE_EN_MASK 0x10
615 #define M_VECM_EN_MASK 0x08
616 #define M_VECM_UPDM_MASK 0x04
617 #define M_VECM_INITM_MASK 0x02
618 #define M_VECM_ELE_MASK 0x01
619
620 /* MAG VECTOR THS MSB AND LSB Register */
621 #define M_VECM_THS_MSB 0x6A
622
623 #define M_VECM_DBCNTM_MASK 0x80
624
625 #define M_VECM_THS_LSB 0x6B
626
627 /* MAG VECTOR CNT Register */
628 #define M_VECM_CNT 0x6C
629
630 /* MAG INITIAL XYZ VECTORS Register */
631 #define M_VECM_INITX_MSB 0x6D
632 #define M_VECM_INITX_LSB 0x6E
633 #define M_VECM_INITY_MSB 0x6F
634 #define M_VECM_INITY_LSB 0x70
635 #define M_VECM_INITZ_MSB 0x71
636 #define M_VECM_INITZ_LSB 0x72
637
638 /* ACCEL FFMT THS X MSB AND LSB Register */
639 #define A_FFMT_THS_X_MSB 0x73
640
641 #define A_FFMT_THS_XYZ_EN_MASK 0x80
642
643 #define A_FFMT_THS_X_LSB 0x74
644
645 #define A_FFMT_THS_X_LSB_MASK 0xFC
646
647 /* ACCEL FFMT THS Y MSB AND LSB Register */
648 #define A_FFMT_THS_Y_MSB 0x75
649
650 #define A_FFMT_THS_Y_EN_MASK 0x80
651
652 #define A_FFMT_THS_Y_LSB 0x76
653
654 #define A_FFMT_THS_Y_LSB_MASK 0xFC
655
656 /* ACCEL FFMT THS Z MSB AND LSB Register */
657 #define A_FFMT_THS_Z_MSB 0x77
658
659 #define A_FFMT_THS_Z_EN_MASK 0x80
660
661 #define A_FFMT_THS_Z_LSB 0x78
662
663 #define A_FFMT_THS_Z_LSB_MASK 0xFC
664
665 /* ACCEL TRANSIENT INIT Register */
666 #define A_TRAN_INIT_XYZ_MSB 0x79
667 #define A_TRAN_INIT_X_LSB 0x7A
668 #define A_TRAN_INIT_Y_LSB 0x7B
669 #define A_TRAN_INIT_Z_LSB 0x7C
670
671 /*! @brief Define I2C access function. */
672 typedef status_t (*I2C_SendFunc_t)(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
673 typedef status_t (*I2C_ReceiveFunc_t)(
674 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
675
676 /*! @brief fxos8700cq configure definition. This structure should be global.*/
677 typedef struct _fxos_handle
678 {
679 /* Pointer to the user-defined I2C Send Data function. */
680 I2C_SendFunc_t I2C_SendFunc;
681 /* Pointer to the user-defined I2C Receive Data function. */
682 I2C_ReceiveFunc_t I2C_ReceiveFunc;
683 /* The I2C slave address . */
684 uint8_t slaveAddress;
685 } fxos_handle_t;
686
687 typedef struct _fxos8700cq_data
688 {
689 uint8_t accelXMSB;
690 uint8_t accelXLSB;
691 uint8_t accelYMSB;
692 uint8_t accelYLSB;
693 uint8_t accelZMSB;
694 uint8_t accelZLSB;
695 uint8_t magXMSB;
696 uint8_t magXLSB;
697 uint8_t magYMSB;
698 uint8_t magYLSB;
699 uint8_t magZMSB;
700 uint8_t magZLSB;
701 } fxos_data_t;
702
703 /*! @brief fxos8700cq configure structure.*/
704 typedef struct _fxos_config
705 {
706 /* Pointer to the user-defined I2C Send Data function. */
707 I2C_SendFunc_t I2C_SendFunc;
708 /* Pointer to the user-defined I2C Receive Data function. */
709 I2C_ReceiveFunc_t I2C_ReceiveFunc;
710 /* The I2C slave address . */
711 uint8_t slaveAddress;
712 } fxos_config_t;
713
714 /*!
715 * @addtogroup fxos_common
716 * @{
717 */
718
719 #if defined(__cplusplus)
720 extern "C" {
721 #endif
722
723 /*!
724 * @brief Verify and initialize fxos_handleice: Hybrid mode with ODR=50Hz, Mag OSR=32, Acc OSR=Normal.
725 *
726 * @param fxos_handle The pointer to accel driver handle.
727 * @param config The configuration structure pointer to accel.
728 *
729 * @return kStatus_Success if success or kStatus_Fail if error.
730 */
731 status_t FXOS_Init(fxos_handle_t *fxos_handle, fxos_config_t *config);
732
733 /*!
734 * @brief Read data from sensors, assumes hyb_autoinc_mode is set in M_CTRL_REG2
735 *
736 * @param fxos_handle The pointer to accel driver handle.
737 * @param sensorData The pointer to the buffer to hold sensor data
738 *
739 * @return kStatus_Success if success or kStatus_Fail if error.
740 */
741 status_t FXOS_ReadSensorData(fxos_handle_t *fxos_handle, fxos_data_t *sensorData);
742
743 /*!
744 * @brief Write value to register of sensor.
745 *
746 * @param handle The pointer to fxos8700cq driver handle.
747 * @param reg Register address.
748 * @param val Data want to write.
749 *
750 * @return kStatus_Success if success or kStatus_Fail if error.
751 */
752 status_t FXOS_WriteReg(fxos_handle_t *handle, uint8_t reg, uint8_t val);
753
754 /*!
755 * @brief Read n bytes start at register from sensor.
756 *
757 * @param handle The pointer to fxos8700cq driver handle.
758 * @param reg Register address.
759 * @param val The pointer to address which store data.
760 * @param bytesNumber Number of bytes receiver.
761 *
762 * @return kStatus_Success if success or kStatus_Fail if error.
763 */
764 status_t FXOS_ReadReg(fxos_handle_t *handle, uint8_t reg, uint8_t *val, uint8_t bytesNumber);
765
766 /*!
767 * @brief Get device accelerator resolution bits.
768 *
769 * @return accelerator resolution bits.
770 */
FXOS_GetResolutionBits(void)771 static inline uint8_t FXOS_GetResolutionBits(void)
772 {
773 return FXOS8700CQ_ACCEL_RESOLUTION_BITS;
774 }
775
776 #if defined(__cplusplus)
777 }
778 #endif /* __cplusplus */
779
780 #endif /* _FSL_FXOS_H_ */
781