ISSDK  1.7
IoT Sensing Software Development Kit
fxls8471q_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 fxls8471q_drv.h
37  * @brief The fxls8471q_drv.h file describes the fxls8471q driver interface and structures.
38  */
39 
40 #ifndef FXLS8471Q_DRV_H_
41 #define FXLS8471Q_DRV_H_
42 
43 /* Standard C Includes */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "fxls8471q.h"
48 #include "sensor_io_spi.h"
49 #include "register_io_spi.h"
50 
51 /*******************************************************************************
52  * Definitions
53  ******************************************************************************/
54 /*!
55  * @brief This defines the sensor specific information for SPI.
56  */
57 typedef struct
58 {
59  registerDeviceInfo_t deviceInfo; /*!< SPI device context. */
60  ARM_DRIVER_SPI *pCommDrv; /*!< Pointer to the spi driver. */
61  bool isInitialized; /*!< Whether sensor is intialized or not.*/
62  spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/
64 
65 /*! @brief This structure defines the fxls8471q raw data buffer.*/
66 typedef struct
67 {
68  uint32_t timestamp; /*! The time, this sample was recorded. */
69  int16_t accel[3]; /*!< The accel data */
71 
72 /*! @def FXLS8471Q_ACCEL_DATA_SIZE
73  * @brief The size of the FXLS8471Q accel data. */
74 #define FXLS8471Q_ACCEL_DATA_SIZE (0x06) /* Size of the accel data*/
75 
76 /*! @def FXLS8471Q_SPI_MAX_MSG_SIZE
77  * @brief The MAX size of SPI message. */
78 #define FXLS8471Q_SPI_MAX_MSG_SIZE (64)
79 
80 /*! @def FXLS8471Q_SPI_CMD_LEN
81  * @brief The size of the Sensor specific SPI Header. */
82 #define FXLS8471Q_SPI_CMD_LEN (2)
83 
84 /*! @def FXLS8471Q_SS_ACTIVE_VALUE
85  * @brief Is the Slave Select Pin Active Low or High. */
86 #define FXLS8471Q_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
87 
88 /*******************************************************************************
89  * APIs
90  ******************************************************************************/
91 /*! @brief The interface function to initialize the sensor for I2C.
92  * @details This function initializes the sensor and sensor handle.
93  * @param[in] pSensorHandle handle to the sensor.
94  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
95  * @param[in] index the I2C device number.
96  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
97  * @param[in] whoami WHO_AM_I value of the device.
98  * @constraints This should be the first API to be called.
99  * Application has to ensure that previous instances of these APIs have exited before invocation.
100  * @reeentrant No
101  * @return ::FXLS8471Q_SPI_Initialize() returns the status .
102 */
104  ARM_DRIVER_SPI *pBus,
105  uint8_t index,
106  void *pSlaveSelect,
107  uint8_t whoAmi);
108 
109 /*! @brief : The interface function to set the SPI Idle Task.
110  * @param[in] : fxls8471q_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
111  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
112  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
113  * @return void.
114  * @constraints This can be called any number of times only after FXLS8471Q_SPI_Initialize().
115  * Application has to ensure that previous instances of these APIs have exited before invocation.
116  * @reeentrant No
117  */
119  registeridlefunction_t idleTask,
120  void *userParam);
121 
122 /*! @brief The interface function to configure he sensor.
123  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
124  * @param[in] pSensorHandle handle to the sensor.
125  * @param[in] pRegWriteList pointer to the register list.
126  * @constraints This can be called any number of times only after FXLS8471Q_SPI_Initialize().
127  * Application has to ensure that previous instances of these APIs have exited before invocation.
128  * @reeentrant No
129  * @return ::FXLS8471Q_SPI_Configure() returns the status .
130  */
132 
133 /*! @brief The interface function to read the sensor data.
134  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
135  * @param[in] pSensorHandle handle to the sensor.
136  * @param[in] pReadList pointer to the list of device registers and values to read.
137  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
138  * command read in the list.
139  * @constraints This can be called any number of times only after FXLS8471Q_SPI_Initialize().
140  * Application has to ensure that previous instances of these APIs have exited before invocation.
141  * @reeentrant No
142  * @return ::FXLS8471Q_SPI_ReadData() returns the status .
143  */
145  const registerreadlist_t *pReadList,
146  uint8_t *pBuffer);
147 
148 /*! @brief The interface function to De Initialize sensor..
149  * @details This function made sensor in a power safe state and de initialize its handle.
150  * @param[in] pSensorHandle handle to the sensor.
151  * @constraints This can be called only after after FXLS8471Q_SPI_Initialize().
152  * Application has to ensure that previous instances of these APIs have exited before invocation.
153  * @reeentrant No
154  * @return ::FXLS8471Q_SPI_Deinit() returns the status .
155  */
157 
158 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
159  * @details This function prepares the SPI Read Command Header with register address and
160  * R/W bit encoded as the Sensor.
161  * @param[out] pCmdOut handle to the output buffer.
162  * @param[in] offset the address of the register to start reading from.
163  * @param[in] size number of bytes to read.
164  * @constraints None
165  * Application has to ensure that previous instances of these APIs have exited before invocation.
166  * @reeentrant No
167  * @return :: None.
168  */
169 void FXLS8471Q_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
170 
171 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
172  * @details This function prepares the SPI Write Command Header with register address and
173  * R/W bit encoded as the Sensor.
174  * @param[out] pCmdOut handle to the output buffer.
175  * @param[in] offset the address of the register to start writing from.
176  * @param[in] size number of bytes to write.
177  * @constraints None
178  * Application has to ensure that previous instances of these APIs have exited before invocation.
179  * @reeentrant No
180  * @return :: None.
181  */
182 void FXLS8471Q_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
183 
184 #endif // FXLS8471Q_DRV_H_
void FXLS8471Q_SPI_SetIdleTask(fxls8471q_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
int32_t FXLS8471Q_SPI_Deinit(fxls8471q_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
registerDeviceInfo_t deviceInfo
Definition: fxls8471q_drv.h:59
int32_t FXLS8471Q_SPI_ReadData(fxls8471q_spi_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
spiSlaveSpecificParams_t slaveParams
Definition: fxls8471q_drv.h:62
int32_t FXLS8471Q_SPI_Configure(fxls8471q_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
This structure defines the fxls8471q raw data buffer.
Definition: fxls8471q_drv.h:66
The fxls8471q.h file contains the register definitions for fxls8471q sensor driver.
The sensor_io_spi.h file declares low-level interface functions for reading and writing sensor regist...
void FXLS8471Q_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: fxls8471q_drv.c:56
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: fxls8471q_drv.h:57
int32_t FXLS8471Q_SPI_Initialize(fxls8471q_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t whoAmi)
The interface function to initialize the sensor for I2C.
Definition: fxls8471q_drv.c:93
void FXLS8471Q_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: fxls8471q_drv.c:73
This structure defines the Write command List.
Definition: sensor_drv.h:94
This structure defines the Read command List.
Definition: sensor_drv.h:104
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...