ISSDK  1.8
IoT Sensing Software Development Kit
mma9553_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 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 mma9553_drv.h
11  * @brief The mma9553_drv.h file describes the MMA9553L driver interface and structures.
12  */
13 
14 #ifndef MMA9553_DRV_H_
15 #define MMA9553_DRV_H_
16 
17 /* Standard C Includes */
18 #include <stdint.h>
19 
20 /* ISSDK Includes */
21 #include "mma9553.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 mma9553 pedometer data buffer. */
53 typedef struct
54 {
55  uint32_t timestamp; /*! The time, this sample was recorded. */
56  int16_t accel[3]; /*! The raw accel data */
58 
59 /*! @brief This structure defines the Size of response for pedometer data read command. */
60 typedef struct
61 {
62  uint8_t responseHeader[MMA9553_HDR_SIZE]; /*! The response header for the read command. */
63  uint16_t statusRegister; /*! Status register. */
64  uint16_t stepCount; /*! Step Counter. */
65  uint16_t distance; /*! Distance covered. */
66  uint16_t speed; /*! Walking Speed. */
67  uint16_t calories; /*! Calories burnt. */
68  uint16_t sleepCount; /*! Sleep Counter. */
70 
71 /*! @def MMA9553_COCO_ERROR_MASK
72  * @brief The Error Bit Mask in COCO Byte. */
73 #define MMA9553_COCO_ERROR_MASK (0x7F)
74 
75 /*! @def MMA9553_SPI_MAX_MSG_SIZE
76  * @brief The MAX size of SPI message. */
77 #define MMA9553_SPI_MAX_MSG_SIZE (64)
78 
79 /*! @def MMA9553_SPI_CMD_LEN
80  * @brief The size of the Sensor specific SPI Header. */
81 #define MMA9553_SPI_CMD_LEN (1)
82 
83 /*! @def MMA9553_SS_ACTIVE_VALUE
84  * @brief Is the Slave Select Pin Active Low or High. */
85 #define MMA9553_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW
86 
87 /*******************************************************************************
88  * APIs
89  ******************************************************************************/
90 /*! @brief The interface function to initialize the sensor.
91  * @details This function initialize the sensor and sensor handle.
92  * @param[in] pSensorHandle handle to the sensor.
93  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
94  * @param[in] index the I2C device number.
95  * @param[in] sAddress slave address of the device on the bus.
96  * @constraints This should be the first API to be called.
97  * Application has to ensure that previous instances of these APIs have exited before invocation.
98  * @reeentrant No
99  * @return ::MMA9553_I2C_Initialize() returns the status .
100  */
102  ARM_DRIVER_I2C *pBus,
103  uint8_t index,
104  uint16_t sAddress);
105 
106 /*! @brief : The interface function to set the I2C Idle Task.
107  * @param[in] : mma9553_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
108  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
109  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
110  * @return void.
111  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
112  * Application has to ensure that previous instances of these APIs have exited before invocation.
113  * @reeentrant No
114  */
116  registeridlefunction_t idleTask,
117  void *userParam);
118 
119 /*! @brief The interface function to configure he sensor.
120  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
121  * @param[in] pSensorHandle handle to the sensor.
122  * @param[in] pCommandList pointer to the command write list.
123  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
124  * Application has to ensure that previous instances of these APIs have exited before invocation.
125  * @reeentrant No
126  * @return ::MMA9553_I2C_Configure() returns the status.
127  */
129 
130 /*! @brief The interface function to read the sensor data.
131  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
132  * @param[in] pSensorHandle handle to the sensor.
133  * @param[in] pCommandList pointer to the command read list.
134  * @param[in] pReadList pointer to the list of device registers and values to read.
135  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
136  * command read in the list.
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  * @return ::MMA9553_I2C_CommandResponse() returns the status .
141  */
143  const registercommandlist_t *pCommandList,
144  const registerreadlist_t *pReadList,
145  uint8_t *pBuffer);
146 
147 /*! @brief The interface function to De Initialize sensor..
148  * @details This function made sensor in a power safe state and de initialize its handle.
149  * @param[in] pSensorHandle handle to the sensor.
150  * @constraints This can be called only after MMA9553_I2C_Initialize().
151  * Application has to ensure that previous instances of these APIs have exited before invocation.
152  * @reeentrant No
153  * @return ::MMA9553_I2C_DeInit() returns the status .
154  */
156 
157 /*! @brief The interface function to initialize the sensor.
158  * @details This function initializes the sensor and sensor handle.
159  * @param[in] pSensorHandle handle to the sensor.
160  * @param[in] pBus pointer to the CMSIS API compatible SPI bus object.
161  * @param[in] index the I2C device number.
162  * @param[in] pSlaveSelect slave select hndle of the device on the bus.
163  * @param[in] pReset reset handle of the device on the bus.
164  * @constraints This should be the first API to be called.
165  * Application has to ensure that previous instances of these APIs have exited before invocation.
166  * @reeentrant No
167  * @return ::MMA9553_SPI_Initialize() returns the status .
168  */
170  mma9553_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, void *pReset);
171 
172 /*! @brief : The interface function to set the SPI Idle Task.
173  * @param[in] : mma9553_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle.
174  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time.
175  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
176  * @return void.
177  * @constraints This can be called any number of times only after MMA9553_I2C_Initialize().
178  * Application has to ensure that previous instances of these APIs have exited before invocation.
179  * @reeentrant No
180  */
182  registeridlefunction_t idleTask,
183  void *userParam);
184 
185 /*! @brief The interface function to configure he sensor.
186  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
187  * @param[in] pSensorHandle handle to the sensor.
188  * @param[in] pCommandList pointer to the command list.
189  * @constraints This can be called any number of times only after FXAS21002_SPI_Initialize().
190  * Application has to ensure that previous instances of these APIs have exited before invocation.
191  * @reeentrant No
192  * @return ::MMA9553_SPI_Configure() returns the status .
193  */
195 
196 /*! @brief The interface function to read the sensor data.
197  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
198  * @param[in] pSensorHandle handle to the sensor.
199  * @param[in] pCommandList pointer to the command read list.
200  * @param[in] pReadList pointer to the list of device registers and values to read.
201  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
202  * command read in the list.
203  * @constraints This can be called any number of times only after MMA9553_SPI_Initialize().
204  * Application has to ensure that previous instances of these APIs have exited before invocation.
205  * @reeentrant No
206  * @return ::MMA9553_SPI_CommandResponse() returns the status .
207  */
209  const registercommandlist_t *pCommandList,
210  const registerreadlist_t *pReadList,
211  uint8_t *pBuffer);
212 
213 /*! @brief The interface function to De Initialize sensor..
214  * @details This function made sensor in a power safe state and de initialize its handle.
215  * @param[in] pSensorHandle handle to the sensor.
216  * @constraints This can be called only after after MMA9553_SPI_Initialize().
217  * Application has to ensure that previous instances of these APIs have exited before invocation.
218  * @reeentrant No
219  * @return ::MMA9553_SPI_DeInit() returns the status .
220  */
222 
223 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header.
224  * @details This function prepares the SPI Read Command Header with register address and
225  * R/W bit encoded as the Sensor.
226  * @param[out] pCmdOut handle to the output buffer.
227  * @param[in] offset the address of the register to start reading from.
228  * @param[in] size number of bytes to read.
229  * @constraints None
230  * Application has to ensure that previous instances of these APIs have exited before invocation.
231  * @reeentrant No
232  * @return :: None.
233  */
234 void MMA9553_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size);
235 
236 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header.
237  * @details This function prepares the SPI Write Command Header with register address and
238  * R/W bit encoded as the Sensor.
239  * @param[out] pCmdOut handle to the output buffer.
240  * @param[in] offset the address of the register to start writing from.
241  * @param[in] size number of bytes to write.
242  * @constraints None
243  * Application has to ensure that previous instances of these APIs have exited before invocation.
244  * @reeentrant No
245  * @return :: None.
246  */
247 void MMA9553_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer);
248 
249 #endif // MMA9553_DRV_H_
#define MMA9553_HDR_SIZE
Size of fixed header bytes in sensor commands.
Definition: mma9553.h:14
uint32_t size
This structure defines the device specific info required by register I/O.
Definition: sensor_drv.h:102
This defines the sensor specific information for I2C.
Definition: mma9553_drv.h:44
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:487
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:222
int32_t MMA9553_I2C_DeInit(mma9553_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma9553_drv.c:529
This structure defines the Size of response for pedometer data read command.
Definition: mma9553_drv.h:60
The register_io_spi.h file declares low-level interface functions for reading and writing sensor regi...
This structure defines the Block command List.
Definition: sensor_drv.h:87
This defines the sensor specific information for SPI.
Definition: mma9553_drv.h:33
This structure defines the spi slave command format.
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:369
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
This structure defines the mma9553 pedometer data buffer.
Definition: mma9553_drv.h:53
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
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:295
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
registerDeviceInfo_t deviceInfo
Definition: mma9553_drv.h:35
spiSlaveSpecificParams_t slaveParams
Definition: mma9553_drv.h:38
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:414
ARM_DRIVER_SPI * pCommDrv
Definition: mma9553_drv.h:36
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:230
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:157
int32_t MMA9553_SPI_DeInit(mma9553_spi_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma9553_drv.c:338
This structure defines the Read command List.
Definition: sensor_drv.h:78
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:422
ARM_DRIVER_I2C * pCommDrv
Definition: mma9553_drv.h:47
registerDeviceInfo_t deviceInfo
Definition: mma9553_drv.h:46
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:120
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...
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:137