ISSDK  1.8
IoT Sensing Software Development Kit
fxas21002_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 fxas21002_drv.h
11  * @brief The fxas21002_drv.h file describes the fxas21002 driver interface and structures.
12  */
13 
14 #ifndef FXAS21002_DRV_H_
15 #define FXAS21002_DRV_H_
16 
17 /* Standard C Includes */
18 #include <stdint.h>
19 
20 /* ISSDK Includes */
21 #include "fxas21002.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 fxas21002 raw data buffer.*/
53 typedef struct
54 {
55  uint32_t timestamp; /*! The time, this sample was recorded. */
56  int16_t gyro[3]; /*!< The gyro data */
58 
59 /*! @def FXAS21002_GYRO_DATA_SIZE
60  * @brief The size of the FXAS21002 gyro data. */
61 #define FXAS21002_GYRO_DATA_SIZE (0x06) /* Size of the accel data*/
62 
63 /*! @def FXAS21002_SPI_MAX_MSG_SIZE
64  * @brief The MAX size of SPI message. */
65 #define FXAS21002_SPI_MAX_MSG_SIZE (64)
66 
67 /*! @def FXAS21002_SPI_CMD_LEN
68  * @brief The size of the Sensor specific SPI Header. */
69 #define FXAS21002_SPI_CMD_LEN (1)
70 
71 /*! @def FXAS21002_SS_ACTIVE_VALUE
72  * @brief Is the Slave Select Pin Active Low or High. */
73 #define FXAS21002_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
74 
75 /*******************************************************************************
76  * APIs
77  ******************************************************************************/
78 /*! @brief The interface function to initialize the sensor.
79  * @details This function initialize the sensor and sensor handle.
80  * @param[in] pSensorHandle handle to the sensor.
81  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
82  * @param[in] index the I2C device number.
83  * @param[in] sAddress slave address of the device on the bus.
84  * @param[in] whoami WHO_AM_I value of the device.
85  * @constraints This should be the first API to be called.
86  * Application has to ensure that previous instances of these APIs have exited before invocation.
87  * @reeentrant No
88  * @return ::FXAS21002_I2C_Initialize() returns the status .
89  */
91  ARM_DRIVER_I2C *pBus,
92  uint8_t index,
93  uint16_t sAddress,
94  uint8_t whoAmi);
95 
96 /*! @brief : The interface function to set the I2C Idle Task.
97  * @param[in] : fxas21002_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
98  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
99  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
100  * @return void.
101  * @constraints This can be called any number of times only after FXAS21002_I2C_Initialize().
102  * Application has to ensure that previous instances of these APIs have exited before invocation.
103  * @reeentrant No
104  */
106  registeridlefunction_t idleTask,
107  void *userParam);
108 
109 /*! @brief The interface function to configure he sensor.
110  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
111  * @param[in] pSensorHandle handle to the sensor.
112  * @param[in] pRegWriteList pointer to the register list.
113  * @constraints This can be called any number of times only after FXAS21002_I2C_Initialize().
114  * Application has to ensure that previous instances of these APIs have exited before invocation.
115  * @reeentrant No
116  * @return ::FXAS21002_I2C_Configure() returns the status .
117  */
119 
120 /*! @brief The interface function to read the sensor data.
121  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
122  * @param[in] pSensorHandle handle to the sensor.
123  * @param[in] pReadList pointer to the list of device registers and values to read.
124  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
125  * command read in the list.
126  * @constraints This can be called any number of times only after FXAS21002_I2C_Initialize().
127  * Application has to ensure that previous instances of these APIs have exited before invocation.
128  * @reeentrant No
129  * @return ::FXAS21002_I2C_ReadData() returns the status .
130  */
132  const registerreadlist_t *pReadList,
133  uint8_t *pBuffer);
134 
135 /*! @brief The interface function to De Initialize sensor..
136  * @details This function made sensor in a power safe state and de initialize its handle.
137  * @param[in] pSensorHandle handle to the sensor.
138  * @constraints This can be called only after FXAS21002_I2C_Initialize().
139  * Application has to ensure that previous instances of these APIs have exited before invocation.
140  * @reeentrant No
141  * @return ::FXAS21002_I2C_Deinit() returns the status .
142  */
144 
145 /*! @brief The interface function to initialize the sensor.
146  * @details This function initializes the sensor and sensor handle.
147  * @param[in] pSensorHandle handle to the sensor.
148  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
149  * @param[in] index the I2C device number.
150  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
151  * @param[in] whoami WHO_AM_I value of the device.
152  * @constraints This should be the first API to be called.
153  * Application has to ensure that previous instances of these APIs have exited before invocation.
154  * @reeentrant No
155  * @return ::FXAS21002_SPI_Initialize() returns the status .
156  */
158  ARM_DRIVER_SPI *pBus,
159  uint8_t index,
160  void *pSlaveSelect,
161  uint8_t whoAmi);
162 
163 /*! @brief : The interface function to set the SPI Idle Task.
164  * @param[in] : fxas21002_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
165  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
166  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
167  * @return void.
168  * @constraints This can be called any number of times only after FXAS21002_SPI_Initialize().
169  * Application has to ensure that previous instances of these APIs have exited before invocation.
170  * @reeentrant No
171  */
173  registeridlefunction_t idleTask,
174  void *userParam);
175 
176 /*! @brief The interface function to configure he sensor.
177  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
178  * @param[in] pSensorHandle handle to the sensor.
179  * @param[in] pRegWriteList pointer to the register list.
180  * @constraints This can be called any number of times only after FXAS21002_SPI_Initialize().
181  * Application has to ensure that previous instances of these APIs have exited before invocation.
182  * @reeentrant No
183  * @return ::FXAS21002_SPI_Configure() returns the status .
184  */
186 
187 /*! @brief The interface function to read the sensor data.
188  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
189  * @param[in] pSensorHandle handle to the sensor.
190  * @param[in] pReadList pointer to the list of device registers and values to read.
191  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
192  * command read in the list.
193  * @constraints This can be called any number of times only after FXAS21002_SPI_Initialize().
194  * Application has to ensure that previous instances of these APIs have exited before invocation.
195  * @reeentrant No
196  * @return ::FXAS21002_SPI_ReadData() returns the status .
197  */
199  const registerreadlist_t *pReadList,
200  uint8_t *pBuffer);
201 
202 /*! @brief The interface function to De Initialize sensor..
203  * @details This function made sensor in a power safe state and de initialize its handle.
204  * @param[in] pSensorHandle handle to the sensor.
205  * @constraints This can be called only after after FXAS21002_SPI_Initialize().
206  * Application has to ensure that previous instances of these APIs have exited before invocation.
207  * @reeentrant No
208  * @return ::FXAS21002_SPI_Deinit() returns the status .
209  */
211 
212 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
213  * @details This function prepares the SPI Read Command Header with register address and
214  * R/W bit encoded as the Sensor.
215  * @param[out] pCmdOut handle to the output buffer.
216  * @param[in] offset the address of the register to start reading from.
217  * @param[in] size number of bytes to read.
218  * @constraints None
219  * Application has to ensure that previous instances of these APIs have exited before invocation.
220  * @reeentrant No
221  * @return :: None.
222  */
223 void FXAS21002_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
224 
225 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
226  * @details This function prepares the SPI Write Command Header with register address and
227  * R/W bit encoded as the Sensor.
228  * @param[out] pCmdOut handle to the output buffer.
229  * @param[in] offset the address of the register to start writing from.
230  * @param[in] size number of bytes to write.
231  * @constraints None
232  * Application has to ensure that previous instances of these APIs have exited before invocation.
233  * @reeentrant No
234  * @return :: None.
235  */
236 void FXAS21002_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
237 
238 #endif // FXAS21002_DRV_H_
int32_t FXAS21002_SPI_Configure(fxas21002_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
uint32_t size
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:102
int32_t FXAS21002_SPI_Initialize(fxas21002_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t whoAmi)
The interface function to initialize the sensor.
Definition: fxas21002_drv.c:65
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...
This defines the sensor specific information for SPI.
Definition: fxas21002_drv.h:33
int32_t FXAS21002_SPI_Deinit(fxas21002_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
void FXAS21002_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: fxas21002_drv.c:30
This structure defines the spi slave command format.
This structure defines the fxas21002 raw data buffer.
Definition: fxas21002_drv.h:53
int32_t FXAS21002_I2C_Deinit(fxas21002_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
int32_t FXAS21002_I2C_ReadData(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
int32_t FXAS21002_I2C_Configure(fxas21002_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
registerDeviceInfo_t deviceInfo
Definition: fxas21002_drv.h:46
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
void FXAS21002_SPI_SetIdleTask(fxas21002_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
This defines the sensor specific information for I2C.
Definition: fxas21002_drv.h:44
void FXAS21002_I2C_SetIdleTask(fxas21002_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
spiSlaveSpecificParams_t slaveParams
Definition: fxas21002_drv.h:38
The fxas21002.h contains the fxas21002 sensor register definitions and its bit mask.
void FXAS21002_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: fxas21002_drv.c:46
int32_t FXAS21002_I2C_Initialize(fxas21002_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
The interface function to initialize the sensor.
This structure defines the Read command List.
Definition: sensor_drv.h:78
registerDeviceInfo_t deviceInfo
Definition: fxas21002_drv.h:35
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...
int32_t FXAS21002_SPI_ReadData(fxas21002_spi_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.