1 /*
2 * Copyright 2022 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #ifndef _FSL_FXLS_H_
9 #define _FSL_FXLS_H_
10
11 #include "fsl_common.h"
12
13 #define FXLS8974CF_ACCEL_RESOLUTION_BITS 12
14
15 /*
16 * STATUS Register
17 */
18 #define INT_STATUS_REG 0x00
19
20 /*
21 * TEMPERATURE Value Register
22 */
23 #define TEMP_OUT_REG 0x01
24
25 /*
26 * VECTOR Magnitude Result Registers
27 */
28 #define VECM_LSB_REG 0x02
29 #define VECM_MSB_REG 0x03
30
31 /*
32 * XYZ Data Registers
33 */
34 #define OUT_X_LSB_REG 0x04
35 #define OUT_X_MSB_REG 0x05
36 #define OUT_Y_LSB_REG 0x06
37 #define OUT_Y_MSB_REG 0x07
38 #define OUT_Z_LSB_REG 0x08
39 #define OUT_Z_MSB_REG 0x09
40
41 /*
42 * XYZ Data Buffer Status Register
43 */
44 #define BUF_STATUS_REG 0x0B
45
46 /*
47 * XYZ Sample Data Registers
48 */
49 #define BUF_X_LSB_REG 0x0C
50 #define BUF_X_MSB_REG 0x0D
51 #define BUF_Y_LSB_REG 0x0E
52 #define BUF_Y_MSB_REG 0x0F
53 #define BUF_Z_LSB_REG 0x10
54 #define BUF_Z_MSB_REG 0x11
55
56 /*
57 * PRODUCT Revision Number Register
58 */
59 #define PROD_REV_REG 0x12
60
61 /*
62 * WHO_AM_I Device ID Register
63 */
64 #define WHO_AM_I_REG 0x13
65 /* Content */
66 #define kFXLS_WHO_AM_I_Device_ID 0x86U
67
68 /*
69 * CURRENT Device Operating Mode Register
70 */
71 #define SYS_MODE_REG 0x14
72
73 /*
74 * CONFIG Registers
75 */
76 #define SENS_CONFIG1_REG 0x15U
77 /* Content */
78 #define ACTIVE_MASK 0x01U
79
80 #define SENS_CONFIG2_REG 0x16
81
82 #define SENS_CONFIG3_REG 0x17
83
84 #define SENS_CONFIG4_REG 0x18
85
86 #define SENS_CONFIG5_REG 0x19
87
88 /*
89 * MODE Registers
90 */
91 #define WAKE_IDLE_LSB_REG 0x1A
92 #define WAKE_IDLE_MSB_REG 0x1B
93 #define SLEEP_IDLE_LSB_REG 0x1C
94 #define SLEEP_IDLE_MSB_REG 0x1D
95 #define ASLP_COUNT_LSB_REG 0x1E
96 #define ASLP_COUNT_MSB_REG 0x1F
97
98 /*
99 * INTERRUPT Registers
100 */
101 #define INT_EN_REG 0x20
102 #define INT_PIN_SEL_REG 0x21
103
104 /* XYZ Offset Correction Registers */
105 #define OFF_X_REG 0x22
106 #define OFF_Y_REG 0x23
107 #define OFF_Z_REG 0x24
108
109 /* BUFFER Config Registers */
110 #define BUF_CONFIG1_REG 0x26
111 #define BUF_CONFIG2_REG 0x27
112
113 /*! @brief Define I2C access function. */
114 typedef status_t (*I2C_SendFunc_t)(uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint32_t txBuff);
115 typedef status_t (*I2C_ReceiveFunc_t)(
116 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize);
117
118 /*! @brief fxls8974cf configure definition. This structure should be global.*/
119 typedef struct _fxls_handle
120 {
121 /* Pointer to the user-defined I2C Send Data function. */
122 I2C_SendFunc_t I2C_SendFunc;
123 /* Pointer to the user-defined I2C Receive Data function. */
124 I2C_ReceiveFunc_t I2C_ReceiveFunc;
125 /* The I2C slave address . */
126 uint8_t slaveAddress;
127 } fxls_handle_t;
128
129 /*! @brief fxls8974cf sensor data structure. */
130 typedef struct _fxls_accel_raw_data
131 {
132 uint8_t accelXLSB; /* 8-bit X-axis LSB output acceleration data. */
133 uint8_t accelXMSB; /* 4-bit X-axis MSB output acceleration data. */
134 uint8_t accelYLSB; /* 8-bit Y-axis LSB output acceleration data. */
135 uint8_t accelYMSB; /* 4-bit Y-axis MSB output acceleration data. */
136 uint8_t accelZLSB; /* 8-bit Z-axis LSB output acceleration data. */
137 uint8_t accelZMSB; /* 4-bit Z-axis MSB output acceleration data. */
138 } fxls_accel_raw_data_t;
139
140 /*! @brief fxls8974cf synthesized accel data structure. */
141 typedef struct _fxls_accel_data
142 {
143 int16_t accelX; /* Synthesized 12-bit X-axis output acceleration data. */
144 int16_t accelY; /* Synthesized 12-bit Y-axis output acceleration data. */
145 int16_t accelZ; /* Synthesized 12-bit Z-axis output acceleration data. */
146 } fxls_accel_data_t;
147
148 /*! @brief fxls8974cf configure structure.*/
149 typedef struct _fxls_config
150 {
151 /* Pointer to the user-defined I2C Send Data function. */
152 I2C_SendFunc_t I2C_SendFunc;
153 /* Pointer to the user-defined I2C Receive Data function. */
154 I2C_ReceiveFunc_t I2C_ReceiveFunc;
155 /* The I2C slave address. */
156 uint8_t slaveAddress;
157 } fxls_config_t;
158
159 /*!
160 * @addtogroup fxls_common
161 * @{
162 */
163
164 #if defined(__cplusplus)
165 extern "C" {
166 #endif
167
168 /*!
169 * @brief Verify and initialize fxls_handleice
170 *
171 * @param fxls_handle The pointer to accel driver handle.
172 * @param config The configuration structure pointer to accel.
173 *
174 * @return kStatus_Success if success or kStatus_Fail if error.
175 */
176 status_t FXLS_Init(fxls_handle_t *fxls_handle, fxls_config_t *config);
177
178 /*!
179 * @brief Read data from sensors
180 *
181 * @param fxls_handle The pointer to accel driver handle.
182 * @param accelRawData The pointer to the buffer to hold sensor data.
183 *
184 * @return kStatus_Success if success or kStatus_Fail if error.
185 */
186 status_t FXLS_ReadAccelRawData(fxls_handle_t *fxls_handle, fxls_accel_raw_data_t *accelRawData);
187
188 /*!
189 * @brief Read data from sensors and synthesize the final accel data
190 *
191 * @param fxls_handle The pointer to accel driver handle.
192 * @param accelData The pointer to the buffer to hold accel data.
193 *
194 * @return kStatus_Success if success or kStatus_Fail if error.
195 */
196 status_t FXLS_ReadAccelData(fxls_handle_t *fxls_handle, fxls_accel_data_t *accelData);
197
198 /*!
199 * @brief Write value to register of sensor.
200 *
201 * @param handle The pointer to fxls8974cf driver handle.
202 * @param reg Register address.
203 * @param val Data want to write.
204 *
205 * @return kStatus_Success if success or kStatus_Fail if error.
206 */
207 status_t FXLS_WriteReg(fxls_handle_t *handle, uint8_t reg, uint8_t val);
208
209 /*!
210 * @brief Read n bytes start at register from sensor.
211 *
212 * @param handle The pointer to fxls8974cf driver handle.
213 * @param reg Register address.
214 * @param val The pointer to address which store data.
215 * @param bytesNumber Number of bytes receiver.
216 *
217 * @return kStatus_Success if success or kStatus_Fail if error.
218 */
219 status_t FXLS_ReadReg(fxls_handle_t *handle, uint8_t reg, uint8_t *val, uint8_t bytesNumber);
220
221 /*!
222 * @brief Get device accelerator resolution bits.
223 *
224 * @return accelerator resolution bits.
225 */
FXLS_GetResolutionBits(void)226 static inline uint8_t FXLS_GetResolutionBits(void)
227 {
228 return FXLS8974CF_ACCEL_RESOLUTION_BITS;
229 }
230
231 #if defined(__cplusplus)
232 }
233 #endif /* __cplusplus */
234
235 #endif /* _FSL_FXLS_H_ */
236