NHS31xx SW API
accel_internal.h
1 /*
2  * Copyright 2018-2019 NXP
3  * This software is owned or controlled by NXP and may only be used strictly
4  * in accordance with the applicable license terms. By expressly accepting
5  * such terms or by downloading, installing, activating and/or otherwise using
6  * the software, you are agreeing that you have read, and that you agree to
7  * comply with and are bound by, such license terms. If you do not agree to
8  * be bound by the applicable license terms, then you may not retain, install,
9  * activate or otherwise use the software.
10  */
11 
12 #ifndef __ACCEL_INTERNAL_H_
13 #define __ACCEL_INTERNAL_H_
14 
15 #include <stdint.h>
16 #include <stdbool.h>
17 #include "accel.h"
18 
19 #define ACCEL_BUFFER_SIZE 32
20 
26 #define ACCEL_SHOCK_FSMR ACCEL_FSMR_16G
27 
33 #define ACCEL_SHOCK_ODR ACCEL_ODR_100HZ
34 
40 #define ACCEL_SHAKE_FSMR ACCEL_FSMR_8G
41 
47 #define ACCEL_SHAKE_ODR ACCEL_ODR_25HZ
48 
54 #define ACCEL_VIBRATION_FSMR ACCEL_FSMR_4G
55 
61 #define ACCEL_VIBRATION_ODR ACCEL_ODR_50HZ
62 
68 #define ACCEL_TILT_FSMR ACCEL_FSMR_2G
69 
75 #define ACCEL_TILT_ODR ACCEL_ODR_12HZ
76 
77 /* ------------------------------------------------------------------------- */
78 
82 typedef enum ACCEL_FSMR
83 {
84  ACCEL_FSMR_2G,
85  ACCEL_FSMR_4G,
86  ACCEL_FSMR_8G,
87  ACCEL_FSMR_16G,
88 } ACCEL_FSMR_T;
89 
94 typedef enum ACCEL_ODR
95 {
96  ACCEL_ODR_1HZ,
97  ACCEL_ODR_3HZ,
98  ACCEL_ODR_6HZ,
99  ACCEL_ODR_12HZ,
100  ACCEL_ODR_25HZ,
101  ACCEL_ODR_50HZ,
102  ACCEL_ODR_100HZ,
103  ACCEL_ODR_200HZ,
104  ACCEL_ODR_400HZ,
110  ACCEL_ODR_COUNT
111 } ACCEL_ODR_T;
112 
114 typedef struct ACCEL_AXES_FLAGS {
115  int x;
116  int y;
117  int z;
119 
123 typedef enum ACCEL_TILT_STATUS {
124  ACCEL_TILT_STATUS_UNKNOWN = 0,
125 
133  ACCEL_TILT_STATUS_PORTRAIT_UP = 0x01,
134 
142  ACCEL_TILT_STATUS_PORTRAIT_DOWN = 0x02,
143 
151  ACCEL_TILT_STATUS_LANDSCAPE_RIGHT = 0x04,
152 
160  ACCEL_TILT_STATUS_LANDSCAPE_LEFT = 0x08,
161 
165  ACCEL_TILT_STATUS_FRONT = 0x10,
166 
170  ACCEL_TILT_STATUS_BACK = 0x20,
171 
173  ACCEL_TILT_STATUS_COUNT = 6
174 } ACCEL_TILT_STATUS_T;
175 
181 typedef struct ACCEL_INTERRUPT_STATUS_S {
182 #if ACCEL_SHOCK_ENABLE || ACCEL_SHAKE_ENABLE || ACCEL_VIBRATION_ENABLE
183 
187 
192 #endif
193 
194 #if ACCEL_TILT_ENABLE
195 
199 
205 #endif
206 
213 
214 /* ------------------------------------------------------------------------- */
215 
220 bool Accel_TimerCb(void);
221 void Accel_TimerSet(ACCEL_ODR_T odr, unsigned int timeout);
232 int Accel_TimerCalculateDebounce(ACCEL_ODR_T odr, int duration);
233 
234 void Accel_I2cInit(void);
235 void Accel_I2cDeInit(void);
236 uint8_t Accel_I2cReadReg(uint8_t reg);
237 bool Accel_I2cWriteReg(uint8_t reg, uint8_t val);
238 
239 /* ------------------------------------------------------------------------- */
240 
241 #if ACCEL_SHOCK_ENABLE
242 bool Accel_Shock_Start(void);
243 void Accel_Shock_Stop(void);
244 void Accel_Shock_SetParams(ACCEL_SHOCK_PARAMS_T * pVibration);
245 void Accel_Shock_Detect(const ACCEL_INTERRUPT_STATUS_T status);
246 #endif
247 
248 #if ACCEL_SHAKE_ENABLE
249 bool Accel_Shake_Start(void);
250 void Accel_Shake_Stop(void);
251 void Accel_Shake_SetParams(ACCEL_SHAKE_PARAMS_T * pVibration);
252 void Accel_Shake_Detect(const ACCEL_INTERRUPT_STATUS_T status);
253 #endif
254 
255 #if ACCEL_VIBRATION_ENABLE
256 bool Accel_Vibration_Start(void);
257 void Accel_Vibration_Stop(void);
258 void Accel_Vibration_SetParams(ACCEL_VIBRATION_PARAMS_T * pVibration);
259 void Accel_Vibration_Detect(const ACCEL_INTERRUPT_STATUS_T status);
260 #endif
261 
262 #if ACCEL_TILT_ENABLE
263 bool Accel_Tilt_Start(bool shock, bool shake, bool vibration);
264 void Accel_Tilt_Stop(void);
265 void Accel_Tilt_SetParams(ACCEL_TILT_PARAMS_T * pTilt);
266 void Accel_Tilt_Detect(const ACCEL_INTERRUPT_STATUS_T status);
267 #endif
268 
269 /* ------------------------------------------------------------------------- */
270 
282 void Accel_SetThresholds(int level);
283 
292 void Accel_SetWatermark(int watermark);
293 
294 ACCEL_INTERRUPT_STATUS_T Accel_GetInterruptStatus(void);
295 
296 bool Accel_ProgramShock(int amplitude);
297 bool Accel_ProgramShake(int amplitude);
298 bool Accel_ProgramVibration(int amplitude);
299 bool Accel_ProgramTilt(bool shock, bool shake, bool vibration, int waitTime);
300 
301 void Accel_Reset(bool shock, bool shake, bool vibration, bool tilt);
302 ACCEL_FSMR_T Accel_Disable(void);
303 void Accel_Enable(void);
304 
305 #endif
bool thresholdsExceeded
Definition: accel_internal.h:186
bool timerExpired
Definition: accel_internal.h:211
int y
Definition: accel_internal.h:116
ACCEL_AXES_FLAGS_T flags
Definition: accel_internal.h:191
Definition: accel_internal.h:181
bool orientationChanged
Definition: accel_internal.h:198
Definition: accel_params.h:121
Definition: accel_params.h:26
Definition: accel_params.h:65
Definition: accel_params.h:90
int x
Definition: accel_internal.h:115
int tiltStatus
Definition: accel_internal.h:204
int z
Definition: accel_internal.h:117
Definition: accel_internal.h:114