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