ISSDK  1.8
IoT Sensing Software Development Kit
fxls8962_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 /**
10  * @file fxls8962_drv.h
11  * @brief The fxls8962_drv.h file describes the FXLS8962AF driver interface and structures.
12  */
13 
14 #ifndef FXLS8962_AF_H_
15 #define FXLS8962_AF_H_
16 
17 /* Standard C Includes */
18 #include <stdint.h>
19 
20 /* ISSDK Includes */
21 #include "fxls8962.h"
22 #include "sensor_io_i2c.h"
23 #include "sensor_io_spi.h"
24 #include "register_io_i2c.h"
25 #include "register_io_spi.h"
26 
27 /*******************************************************************************
28  * Definitions
29  ******************************************************************************/
30 /*!
31  * @brief This defines the sensor specific information for SPI.
32  */
33 typedef struct
34 {
35  registerDeviceInfo_t deviceInfo; /*!< SPI device context. */
36  ARM_DRIVER_SPI *pCommDrv; /*!< Pointer to the spi driver. */
37  bool isInitialized; /*!< Whether sensor is intialized or not.*/
38  spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/
40 
41 /*!
42  * @brief This defines the sensor specific information for I2C.
43  */
44 typedef struct
45 {
46  registerDeviceInfo_t deviceInfo; /*!< I2C device context. */
47  ARM_DRIVER_I2C *pCommDrv; /*!< Pointer to the i2c driver. */
48  bool isInitialized; /*!< whether sensor is intialized or not.*/
49  uint16_t slaveAddress; /*!< slave address.*/
51 
52 /*! @brief This structure defines the fxls8962 raw data buffer.*/
53 typedef struct
54 {
55  uint32_t timestamp; /*! The time, this sample was recorded. */
56  int16_t accel[3]; /*!< The accel data */
58 
59 /*! @def FXLS8962_SPI_MAX_MSG_SIZE
60  * @brief The MAX size of SPI message. */
61 #define FXLS8962_SPI_MAX_MSG_SIZE (64)
62 
63 /*! @def FXLS8962_SPI_CMD_LEN
64  * @brief The size of the Sensor specific SPI Header. */
65 #define FXLS8962_SPI_CMD_LEN (2)
66 
67 /*! @def FXLS8962_SS_ACTIVE_VALUE
68  * @brief Is the Slave Select Pin Active Low or High. */
69 #define FXLS8962_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
70 
71 /*******************************************************************************
72  * APIs
73  ******************************************************************************/
74 /*! @brief The interface function to initialize the sensor.
75  * @details This function initialize the sensor and sensor handle.
76  * @param[in] pSensorHandle handle to the sensor.
77  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
78  * @param[in] index the I2C device number.
79  * @param[in] sAddress slave address of the device on the bus.
80  * @param[in] whoami WHO_AM_I value of the device.
81  * @constraints This should be the first API to be called.
82  * Application has to ensure that previous instances of these APIs have exited before invocation.
83  * @reeentrant No
84  * @return ::FXLS8962_I2C_Initialize() returns the status .
85  */
87  fxls8962_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoAmi);
88 
89 /*! @brief : The interface function to set the I2C Idle Task.
90  * @param[in] : fxls8962_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
91  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
92  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
93  * @return void.
94  * @constraints This can be called any number of times only after FXLS8962_I2C_Initialize().
95  * Application has to ensure that previous instances of these APIs have exited before invocation.
96  * @reeentrant No
97  */
99  registeridlefunction_t idleTask,
100  void *userParam);
101 
102 /*! @brief The interface function to configure he sensor.
103  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
104  * @param[in] pSensorHandle handle to the sensor.
105  * @param[in] pRegWriteList pointer to the register list.
106  * @constraints This can be called any number of times only after FXLS8962_I2C_Initialize().
107  * Application has to ensure that previous instances of these APIs have exited before invocation.
108  * @reeentrant No
109  * @return ::FXLS8962_I2C_Configure() returns the status .
110  */
112 
113 /*! @brief The interface function to read the sensor data.
114  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
115  * @param[in] pSensorHandle handle to the sensor.
116  * @param[in] pReadList pointer to the list of device registers and values to read.
117  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
118  * command read in the list.
119  * @constraints This can be called any number of times only after FXLS8962_I2C_Initialize().
120  * Application has to ensure that previous instances of these APIs have exited before invocation.
121  * @reeentrant No
122  * @return ::FXLS8962_I2C_ReadData() returns the status .
123  */
125  const registerreadlist_t *pReadList,
126  uint8_t *pBuffer);
127 
128 /*! @brief The interface function to De Initialize sensor..
129  * @details This function made sensor in a power safe state and de initialize its handle.
130  * @param[in] pSensorHandle handle to the sensor.
131  * @constraints This can be called only after FXLS8962_I2C_Initialize().
132  * Application has to ensure that previous instances of these APIs have exited before invocation.
133  * @reeentrant No
134  * @return ::FXLS8962_I2C_DeInit() returns the status .
135  */
137 
138 /*! @brief The interface function to initialize the sensor.
139  * @details This function initializes the sensor and sensor handle.
140  * @param[in] pSensorHandle handle to the sensor.
141  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
142  * @param[in] index the I2C device number.
143  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
144  * @param[in] whoami WHO_AM_I value of the device.
145  * @constraints This should be the first API to be called.
146  * Application has to ensure that previous instances of these APIs have exited before invocation.
147  * @reeentrant No
148  * @return ::FXLS8962_SPI_Initialize() returns the status .
149  */
151  ARM_DRIVER_SPI *pBus,
152  uint8_t index,
153  void *pSlaveSelect,
154  uint8_t *whoAmi);
155 
156 /*! @brief : The interface function to set the SPI Idle Task.
157  * @param[in] : fxls8962_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
158  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
159  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
160  * @return void.
161  * @constraints This can be called any number of times only after FXLS8962_SPI_Initialize().
162  * Application has to ensure that previous instances of these APIs have exited before invocation.
163  * @reeentrant No
164  */
166  registeridlefunction_t idleTask,
167  void *userParam);
168 
169 /*! @brief The interface function to configure he sensor.
170  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
171  * @param[in] pSensorHandle handle to the sensor.
172  * @param[in] pRegWriteList pointer to the register list.
173  * @constraints This can be called any number of times only after FXLS8962_SPI_Initialize().
174  * Application has to ensure that previous instances of these APIs have exited before invocation.
175  * @reeentrant No
176  * @return ::FXLS8962_SPI_Configure() returns the status .
177  */
179 
180 /*! @brief The interface function to read the sensor data.
181  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
182  * @param[in] pSensorHandle handle to the sensor.
183  * @param[in] pReadList pointer to the list of device registers and values to read.
184  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
185  * command read in the list.
186  * @constraints This can be called any number of times only after FXLS8962_SPI_Initialize().
187  * Application has to ensure that previous instances of these APIs have exited before invocation.
188  * @reeentrant No
189  * @return ::FXLS8962_SPI_ReadData() returns the status .
190  */
192  const registerreadlist_t *pReadList,
193  uint8_t *pBuffer);
194 
195 /*! @brief The interface function to De Initialize sensor..
196  * @details This function made sensor in a power safe state and de initialize its handle.
197  * @param[in] pSensorHandle handle to the sensor.
198  * @constraints This can be called only after after FXLS8962_SPI_Initialize().
199  * Application has to ensure that previous instances of these APIs have exited before invocation.
200  * @reeentrant No
201  * @return ::FXLS8962_SPI_Deinit() returns the status .
202  */
204 
205 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
206  * @details This function prepares the SPI Read Command Header with register address and
207  * R/W bit encoded as the Sensor.
208  * @param[out] pCmdOut handle to the output buffer.
209  * @param[in] offset the address of the register to start reading from.
210  * @param[in] size number of bytes to read.
211  * @constraints None
212  * Application has to ensure that previous instances of these APIs have exited before invocation.
213  * @reeentrant No
214  * @return :: None.
215  */
216 void FXLS8962_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
217 
218 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
219  * @details This function prepares the SPI Write Command Header with register address and
220  * R/W bit encoded as the Sensor.
221  * @param[out] pCmdOut handle to the output buffer.
222  * @param[in] offset the address of the register to start writing from.
223  * @param[in] size number of bytes to write.
224  * @constraints None
225  * Application has to ensure that previous instances of these APIs have exited before invocation.
226  * @reeentrant No
227  * @return :: None.
228  */
229 void FXLS8962_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
230 
231 #endif // FXLS8962_AF_H_
uint32_t size
This structure defines the fxls8962 raw data buffer.
Definition: fxls8962_drv.h:53
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:102
int32_t FXLS8962_I2C_DeInit(fxls8962_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: fxls8962_drv.c:360
This structure defines the Write command List.
Definition: sensor_drv.h:68
The sensor_io_spi.h file declares low-level interface functions for reading and writing sensor regist...
void FXLS8962_I2C_SetIdleTask(fxls8962_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxls8962_drv.c:278
void FXLS8962_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: fxls8962_drv.c:31
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
This structure defines the spi slave command format.
void FXLS8962_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer)
The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
Definition: fxls8962_drv.c:48
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
int32_t FXLS8962_SPI_Deinit(fxls8962_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: fxls8962_drv.c:205
This defines the sensor specific information for I2C.
Definition: fxls8962_drv.h:44
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
int32_t FXLS8962_SPI_ReadData(fxls8962_spi_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxls8962_drv.c:176
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
This defines the sensor specific information for SPI.
Definition: fxls8962_drv.h:33
ARM_DRIVER_SPI * pCommDrv
Definition: fxls8962_drv.h:36
int32_t FXLS8962_I2C_Initialize(fxls8962_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoAmi)
The interface function to initialize the sensor.
Definition: fxls8962_drv.c:240
void FXLS8962_SPI_SetIdleTask(fxls8962_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
Definition: fxls8962_drv.c:123
registerDeviceInfo_t deviceInfo
Definition: fxls8962_drv.h:35
int32_t FXLS8962_I2C_ReadData(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxls8962_drv.c:331
int32_t FXLS8962_SPI_Configure(fxls8962_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxls8962_drv.c:131
ARM_DRIVER_I2C * pCommDrv
Definition: fxls8962_drv.h:47
int32_t FXLS8962_I2C_Configure(fxls8962_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxls8962_drv.c:286
This structure defines the Read command List.
Definition: sensor_drv.h:78
spiSlaveSpecificParams_t slaveParams
Definition: fxls8962_drv.h:38
This file contains the FXLS8962 Accelerometer register definitions, access macros, and device access functions.
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...
registerDeviceInfo_t deviceInfo
Definition: fxls8962_drv.h:46
int32_t FXLS8962_SPI_Initialize(fxls8962_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t *whoAmi)
The interface function to initialize the sensor.
Definition: fxls8962_drv.c:68