ISSDK  1.7
IoT Sensing Software Development Kit
mma9553_drv.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 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 mma9553_drv.h
37  * @brief The mma9553_drv.h file describes the MMA9553L driver interface and structures.
38  */
39 
40 #ifndef MMA9553_DRV_H_
41 #define MMA9553_DRV_H_
42 
43 /* Standard C Includes */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "mma9553.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 spi 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 mma9553 pedometer data buffer. */
79 typedef struct
80 {
81  uint32_t timestamp; /*! The time, this sample was recorded. */
82  int16_t accel[3]; /*! The raw accel data */
84 
85 /*! @brief This structure defines the Size of response for pedometer data read command. */
86 typedef struct
87 {
88  uint8_t responseHeader[MMA9553_HDR_SIZE]; /*! The response header for the read command. */
89  uint16_t statusRegister; /*! Status register. */
90  uint16_t stepCount; /*! Step Counter. */
91  uint16_t distance; /*! Distance covered. */
92  uint16_t speed; /*! Walking Speed. */
93  uint16_t calories; /*! Calories burnt. */
94  uint16_t sleepCount; /*! Sleep Counter. */
96 
97 /*! @def MMA9553_COCO_ERROR_MASK
98  * @brief The Error Bit Mask in COCO Byte. */
99 #define MMA9553_COCO_ERROR_MASK (0x7F)
100 
101 /*! @def MMA9553_SPI_MAX_MSG_SIZE
102  * @brief The MAX size of SPI message. */
103 #define MMA9553_SPI_MAX_MSG_SIZE (64)
104 
105 /*! @def MMA9553_SPI_CMD_LEN
106  * @brief The size of the Sensor specific SPI Header. */
107 #define MMA9553_SPI_CMD_LEN (1)
108 
109 /*! @def MMA9553_SS_ACTIVE_VALUE
110  * @brief Is the Slave Select Pin Active Low or High. */
111 #define MMA9553_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
112 
113 /*******************************************************************************
114  * APIs
115  ******************************************************************************/
116 /*! @brief The interface function to initialize the sensor.
117  * @details This function initialize the sensor and sensor handle.
118  * @param[in] pSensorHandle handle to the sensor.
119  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
120  * @param[in] index the I2C device number.
121  * @param[in] sAddress slave address of the device on the bus.
122  * @constraints This should be the first API to be called.
123  * Application has to ensure that previous instances of these APIs have exited before invocation.
124  * @reeentrant No
125  * @return ::MMA9553_I2C_Initialize() returns the status .
126  */
128  ARM_DRIVER_I2C *pBus,
129  uint8_t index,
130  uint16_t sAddress);
131 
132 /*! @brief : The interface function to set the I2C Idle Task.
133  * @param[in] : mma9553_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
134  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
135  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
136  * @return void.
137  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
138  * Application has to ensure that previous instances of these APIs have exited before invocation.
139  * @reeentrant No
140  */
142  registeridlefunction_t idleTask,
143  void *userParam);
144 
145 /*! @brief The interface function to configure he sensor.
146  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
147  * @param[in] pSensorHandle handle to the sensor.
148  * @param[in] pCommandList pointer to the command write list.
149  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
150  * Application has to ensure that previous instances of these APIs have exited before invocation.
151  * @reeentrant No
152  * @return ::MMA9553_I2C_Configure() returns the status.
153  */
155 
156 /*! @brief The interface function to read the sensor data.
157  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
158  * @param[in] pSensorHandle handle to the sensor.
159  * @param[in] pCommandList pointer to the command read list.
160  * @param[in] pReadList pointer to the list of device registers and values to read.
161  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
162  * command read in the list.
163  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
164  * Application has to ensure that previous instances of these APIs have exited before invocation.
165  * @reeentrant No
166  * @return ::MMA9553_I2C_CommandResponse() returns the status .
167  */
169  const registercommandlist_t *pCommandList,
170  const registerreadlist_t *pReadList,
171  uint8_t *pBuffer);
172 
173 /*! @brief The interface function to De Initialize sensor..
174  * @details This function made sensor in a power safe state and de initialize its handle.
175  * @param[in] pSensorHandle handle to the sensor.
176  * @constraints This can be called only after MMA9553_I2C_Initialize().
177  * Application has to ensure that previous instances of these APIs have exited before invocation.
178  * @reeentrant No
179  * @return ::MMA9553_I2C_DeInit() returns the status .
180  */
182 
183 /*! @brief The interface function to initialize the sensor.
184  * @details This function initializes the sensor and sensor handle.
185  * @param[in] pSensorHandle handle to the sensor.
186  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
187  * @param[in] index the I2C device number.
188  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
189  * @param[in] pReset reset handle of the device on the bus.
190  * @constraints This should be the first API to be called.
191  * Application has to ensure that previous instances of these APIs have exited before invocation.
192  * @reeentrant No
193  * @return ::MMA9553_SPI_Initialize() returns the status .
194  */
196  mma9553_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, void *pReset);
197 
198 /*! @brief : The interface function to set the SPI Idle Task.
199  * @param[in] : mma9553_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
200  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
201  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
202  * @return void.
203  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
204  * Application has to ensure that previous instances of these APIs have exited before invocation.
205  * @reeentrant No
206  */
208  registeridlefunction_t idleTask,
209  void *userParam);
210 
211 /*! @brief The interface function to configure he sensor.
212  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
213  * @param[in] pSensorHandle handle to the sensor.
214  * @param[in] pCommandList pointer to the command list.
215  * @constraints This can be called any number of times only after FXAS21002_SPI_Initialize().
216  * Application has to ensure that previous instances of these APIs have exited before invocation.
217  * @reeentrant No
218  * @return ::MMA9553_SPI_Configure() returns the status .
219  */
221 
222 /*! @brief The interface function to read the sensor data.
223  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
224  * @param[in] pSensorHandle handle to the sensor.
225  * @param[in] pCommandList pointer to the command read list.
226  * @param[in] pReadList pointer to the list of device registers and values to read.
227  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
228  * command read in the list.
229  * @constraints This can be called any number of times only after MMA9553_SPI_Initialize().
230  * Application has to ensure that previous instances of these APIs have exited before invocation.
231  * @reeentrant No
232  * @return ::MMA9553_SPI_CommandResponse() returns the status .
233  */
235  const registercommandlist_t *pCommandList,
236  const registerreadlist_t *pReadList,
237  uint8_t *pBuffer);
238 
239 /*! @brief The interface function to De Initialize sensor..
240  * @details This function made sensor in a power safe state and de initialize its handle.
241  * @param[in] pSensorHandle handle to the sensor.
242  * @constraints This can be called only after after MMA9553_SPI_Initialize().
243  * Application has to ensure that previous instances of these APIs have exited before invocation.
244  * @reeentrant No
245  * @return ::MMA9553_SPI_DeInit() returns the status .
246  */
248 
249 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
250  * @details This function prepares the SPI Read Command Header with register address and
251  * R/W bit encoded as the Sensor.
252  * @param[out] pCmdOut handle to the output buffer.
253  * @param[in] offset the address of the register to start reading from.
254  * @param[in] size number of bytes to read.
255  * @constraints None
256  * Application has to ensure that previous instances of these APIs have exited before invocation.
257  * @reeentrant No
258  * @return :: None.
259  */
260 void MMA9553_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
261 
262 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
263  * @details This function prepares the SPI Write Command Header with register address and
264  * R/W bit encoded as the Sensor.
265  * @param[out] pCmdOut handle to the output buffer.
266  * @param[in] offset the address of the register to start writing from.
267  * @param[in] size number of bytes to write.
268  * @constraints None
269  * Application has to ensure that previous instances of these APIs have exited before invocation.
270  * @reeentrant No
271  * @return :: None.
272  */
273 void MMA9553_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
274 
275 #endif // MMA9553_DRV_H_
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
void MMA9553_I2C_SetIdleTask(mma9553_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mma9553_drv.c:440
ARM_DRIVER_SPI * pCommDrv
Definition: mma9553_drv.h:62
This structure defines the Size of response for pedometer data read command.
Definition: mma9553_drv.h:86
int32_t MMA9553_SPI_CommandResponse(mma9553_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma9553_drv.c:321
This defines the sensor specific information for I2C.
Definition: mma9553_drv.h:70
This defines the sensor specific information for SPI.
Definition: mma9553_drv.h:59
This structure defines the mma9553 pedometer data buffer.
Definition: mma9553_drv.h:79
int32_t MMA9553_SPI_Initialize(mma9553_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, void *pReset)
The interface function to initialize the sensor.
Definition: mma9553_drv.c:183
int32_t MMA9553_SPI_DeInit(mma9553_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma9553_drv.c:364
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
The mma9553.h contains the MMA9553L Digital Pedometer command definitions and access macros...
void MMA9553_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: mma9553_drv.c:163
int32_t MMA9553_SPI_Configure(mma9553_spi_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList)
The interface function to configure he sensor.
Definition: mma9553_drv.c:256
void MMA9553_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size)
The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. ...
Definition: mma9553_drv.c:146
int32_t MMA9553_I2C_Initialize(mma9553_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress)
The interface function to initialize the sensor.
Definition: mma9553_drv.c:395
registerDeviceInfo_t deviceInfo
Definition: mma9553_drv.h:72
registerDeviceInfo_t deviceInfo
Definition: mma9553_drv.h:61
int32_t MMA9553_I2C_Configure(mma9553_i2c_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList)
The interface function to configure he sensor.
Definition: mma9553_drv.c:448
spiSlaveSpecificParams_t slaveParams
Definition: mma9553_drv.h:64
The sensor_io_spi.h file declares low-level interface functions for reading and writing sensor regist...
int32_t MMA9553_I2C_CommandResponse(mma9553_i2c_sensorhandle_t *pSensorHandle, const registercommandlist_t *pCommandList, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma9553_drv.c:513
int32_t MMA9553_I2C_DeInit(mma9553_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma9553_drv.c:555
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
uint32_t size
#define MMA9553_HDR_SIZE
Size of fixed header bytes in sensor commands.
Definition: mma9553.h:13
ARM_DRIVER_I2C * pCommDrv
Definition: mma9553_drv.h:73
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 Block command List.
Definition: sensor_drv.h:113
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...
void MMA9553_SPI_SetIdleTask(mma9553_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the SPI Idle Task.
Definition: mma9553_drv.c:248
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...