ISSDK  1.7
IoT Sensing Software Development Kit
fxos8700_drv.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted (subject to the limitations in the disclaimer below) provided
9  * that the following conditions are met:
10  *
11  * o Redistributions of source code must retain the above copyright notice, this list
12  * of conditions and the following disclaimer.
13  *
14  * o Redistributions in binary form must reproduce the above copyright notice, this
15  * list of conditions and the following disclaimer in the documentation and/or
16  * other materials provided with the distribution.
17  *
18  * o Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
30  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /**
36  * @file fxos8700_drv.h
37  * @brief The fxos8700_drv.h file describes the fxos8700 driver interface and structures.
38  */
39 
40 #ifndef FXOS8700_DRV_H_
41 #define FXOS8700_DRV_H_
42 
43 /* Standard C Included Files */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "fxos8700.h"
48 #include "sensor_io_i2c.h"
49 #include "sensor_io_spi.h"
50 #include "register_io_i2c.h"
51 #include "register_io_spi.h"
52 
53 /*******************************************************************************
54  * Definitions
55  ******************************************************************************/
56 /*!
57  * @brief This defines the sensor specific information for SPI.
58  */
59 typedef struct
60 {
61  registerDeviceInfo_t deviceInfo; /*!< SPI device context. */
62  ARM_DRIVER_SPI *pCommDrv; /*!< Pointer to the i2c driver. */
63  bool isInitialized; /*!< whether sensor is intialized or not.*/
64  spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/
66 
67 /*!
68  * @brief This defines the sensor specific information for I2C.
69  */
70 typedef struct
71 {
72  registerDeviceInfo_t deviceInfo; /*!< I2C device context. */
73  ARM_DRIVER_I2C *pCommDrv; /*!< Pointer to the i2c driver. */
74  bool isInitialized; /*!< whether sensor is intialized or not.*/
75  uint16_t slaveAddress; /*!< slave address.*/
77 
78 /*! @brief This structure defines the fxos8700 raw data buffer.*/
79 typedef struct
80 {
81  uint32_t timestamp; /*! The time, this sample was recorded. */
82  int16_t accel[3]; /*!< The accel data */
83  int16_t mag[3]; /*!< The mag data */
85 
86 /*! @brief This structure defines the fxos8700 raw accel data buffer.*/
87 typedef struct
88 {
89  uint32_t timestamp; /*! The time, this sample was recorded. */
90  int16_t accel[3]; /*!< The accel data */
92 
93 /*! @def FXOS8700_SPI_MAX_MSG_SIZE
94  * @brief The MAX size of SPI message. */
95 #define FXOS8700_SPI_MAX_MSG_SIZE (64)
96 
97 /*! @def FXOS8700_SPI_CMD_LEN
98  * @brief The size of the Sensor specific SPI Header. */
99 #define FXOS8700_SPI_CMD_LEN (2)
100 
101 /*! @def FXOS8700_SS_ACTIVE_VALUE
102  * @brief Is the Slave Select Pin Active Low or High. */
103 #define FXOS8700_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
104 
105 /*******************************************************************************
106  * APIs
107  ******************************************************************************/
108 
109 /*! @brief The interface function to initialize the sensor.
110  * @details This function initialize the sensor and sensor handle.
111  * @param[in] pSensorHandle handle to the sensor.
112  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
113  * @param[in] index the I2C device number.
114  * @param[in] sAddress slave address of the device on the bus.
115  * @param[in] whoami WHO_AM_I value of the device.
116  * @constraints This should be the first API to be called.
117  * Application has to ensure that previous instances of these APIs have exited before invocation.
118  * @reeentrant No
119  * @return ::FXOS8700_I2C_Initialize() returns the status .
120  */
122  fxos8700_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi);
123 
124 /*! @brief : The interface function to set the I2C Idle Task.
125  * @param[in] : fxos8700_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
126  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
127  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
128  * @return void.
129  * @constraints This can be called any number of times only after FXOS8700_I2C_Initialize().
130  * Application has to ensure that previous instances of these APIs have exited before invocation.
131  * @reeentrant No
132  */
134  registeridlefunction_t idleTask,
135  void *userParam);
136 
137 /*! @brief The interface function to configure he sensor.
138  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
139  * @param[in] pSensorHandle handle to the sensor.
140  * @param[in] pRegWriteList pointer to the register list.
141  * @constraints This can be called any number of times only after FXOS8700_I2C_Initialize().
142  * Application has to ensure that previous instances of these APIs have exited before invocation.
143  * @reeentrant No
144  * @return ::FXOS8700_I2C_Configure() returns the status .
145  */
147 
148 /*! @brief The interface function to read the sensor data.
149  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
150  * @param[in] pSensorHandle handle to the sensor.
151  * @param[in] pReadList pointer to the list of device registers and values to read.
152  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
153  * command read in the list.
154  * @constraints This can be called any number of times only after FXOS8700_I2C_Initialize().
155  * Application has to ensure that previous instances of these APIs have exited before invocation.
156  * @reeentrant No
157  * @return ::FXOS8700_I2C_ReadData() returns the status .
158  */
160  const registerreadlist_t *pReadList,
161  uint8_t *pBuffer);
162 
163 /*! @brief The interface function to De Initialize sensor..
164  * @details This function made sensor in a power safe state and de initialize its handle.
165  * @param[in] pSensorHandle handle to the sensor.
166  * @constraints This can be called only after FXOS8700_I2C_Initialize().
167  * Application has to ensure that previous instances of these APIs have exited before invocation.
168  * @reeentrant No
169  * @return ::FXOS8700_I2C_Deinit() returns the status .
170  */
172 
173 /*! @brief The interface function to initialize the sensor.
174  * @details This function initializes the sensor and sensor handle.
175  * @param[in] pSensorHandle handle to the sensor.
176  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
177  * @param[in] index the I2C device number.
178  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
179  * @param[in] whoami WHO_AM_I value of the device.
180  * @constraints This should be the first API to be called.
181  * Application has to ensure that previous instances of these APIs have exited before invocation.
182  * @reeentrant No
183  * @return ::FXOS8700_SPI_Initialize() returns the status .
184  */
186  ARM_DRIVER_SPI *pBus,
187  uint8_t index,
188  void *pSlaveSelect,
189  uint8_t whoAmi);
190 
191 /*! @brief : The interface function to set the SPI Idle Task.
192  * @param[in] : fxos8700_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
193  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
194  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
195  * @return void.
196  * @constraints This can be called any number of times only after FXOS8700_SPI_Initialize().
197  * Application has to ensure that previous instances of these APIs have exited before invocation.
198  * @reeentrant No
199  */
201  registeridlefunction_t idleTask,
202  void *userParam);
203 
204 /*! @brief The interface function to configure he sensor.
205  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
206  * @param[in] pSensorHandle handle to the sensor.
207  * @param[in] pRegWriteList pointer to the register list.
208  * @constraints This can be called any number of times only after FXOS8700_SPI_Initialize().
209  * Application has to ensure that previous instances of these APIs have exited before invocation.
210  * @reeentrant No
211  * @return ::FXOS8700_SPI_Configure() returns the status .
212  */
214 
215 /*! @brief The interface function to read the sensor data.
216  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
217  * @param[in] pSensorHandle handle to the sensor.
218  * @param[in] pReadList pointer to the list of device registers and values to read.
219  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
220  * command read in the list.
221  * @constraints This can be called any number of times only after FXOS8700_SPI_Initialize().
222  * Application has to ensure that previous instances of these APIs have exited before invocation.
223  * @reeentrant No
224  * @return ::FXOS8700_SPI_ReadData() returns the status .
225  */
227  const registerreadlist_t *pReadList,
228  uint8_t *pBuffer);
229 
230 /*! @brief The interface function to De Initialize sensor..
231  * @details This function made sensor in a power safe state and de initialize its handle.
232  * @param[in] pSensorHandle handle to the sensor.
233  * @constraints This can be called only after after FXOS8700_SPI_Initialize().
234  * Application has to ensure that previous instances of these APIs have exited before invocation.
235  * @reeentrant No
236  * @return ::FXOS8700_SPI_Deinit() returns the status.
237  */
239 
240 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
241  * @details This function prepares the SPI Read Command Header with register address and
242  * R/W bit encoded as the Sensor.
243  * @param[out] pCmdOut handle to the output buffer.
244  * @param[in] offset the address of the register to start reading from.
245  * @param[in] size number of bytes to read.
246  * @constraints None
247  * Application has to ensure that previous instances of these APIs have exited before invocation.
248  * @reeentrant No
249  * @return :: None.
250  */
251 void FXOS8700_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
252 
253 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
254  * @details This function prepares the SPI Write Command Header with register address and
255  * R/W bit encoded as the Sensor.
256  * @param[out] pCmdOut handle to the output buffer.
257  * @param[in] offset the address of the register to start writing from.
258  * @param[in] size number of bytes to write.
259  * @constraints None
260  * Application has to ensure that previous instances of these APIs have exited before invocation.
261  * @reeentrant No
262  * @return :: None.
263  */
264 void FXOS8700_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
265 
266 #endif // FXOS8700_DRV_H_
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
int32_t FXOS8700_I2C_ReadData(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxos8700_drv.c:331
int32_t FXOS8700_I2C_Deinit(fxos8700_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: fxos8700_drv.c:360
This structure defines the fxos8700 raw data buffer.
Definition: fxos8700_drv.h:79
registerDeviceInfo_t deviceInfo
Definition: fxos8700_drv.h:61
ARM_DRIVER_SPI * pCommDrv
Definition: fxos8700_drv.h:62
ARM_DRIVER_I2C * pCommDrv
Definition: fxos8700_drv.h:73
int32_t FXOS8700_SPI_ReadData(fxos8700_spi_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: fxos8700_drv.c:195
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
The fxos8700.h file contains the register definitions for FXOS8700 sensor driver. ...
This defines the sensor specific information for I2C.
Definition: fxos8700_drv.h:70
void FXOS8700_I2C_SetIdleTask(fxos8700_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: fxos8700_drv.c:278
void FXOS8700_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: fxos8700_drv.c:73
This structure defines the fxos8700 raw accel data buffer.
Definition: fxos8700_drv.h:87
spiSlaveSpecificParams_t slaveParams
Definition: fxos8700_drv.h:64
int32_t FXOS8700_SPI_Configure(fxos8700_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxos8700_drv.c:150
int32_t FXOS8700_SPI_Initialize(fxos8700_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t whoAmi)
The interface function to initialize the sensor.
Definition: fxos8700_drv.c:93
void FXOS8700_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: fxos8700_drv.c:56
registerDeviceInfo_t deviceInfo
Definition: fxos8700_drv.h:72
The sensor_io_spi.h file declares low-level interface functions for reading and writing sensor regist...
void FXOS8700_SPI_SetIdleTask(fxos8700_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
Definition: fxos8700_drv.c:142
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
uint32_t size
This defines the sensor specific information for SPI.
Definition: fxos8700_drv.h:59
This structure defines the Write command List.
Definition: sensor_drv.h:94
This structure defines the Read command List.
Definition: sensor_drv.h:104
int32_t FXOS8700_SPI_Deinit(fxos8700_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: fxos8700_drv.c:224
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:128
This structure defines the spi slave command format.
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
int32_t FXOS8700_I2C_Configure(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: fxos8700_drv.c:286
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...
int32_t FXOS8700_I2C_Initialize(fxos8700_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: fxos8700_drv.c:248