ISSDK  1.7
IoT Sensing Software Development Kit
mma845x_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 mma845x_drv.h
37  * @brief The mma845x_drv.h file describes the MMA845x driver interface and structures.
38  */
39 
40 #ifndef MMA845x_DRV_H_
41 #define MMA845x_DRV_H_
42 
43 /* Standard C Includes */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "mma845x.h"
48 #include "sensor_io_i2c.h"
49 #include "register_io_i2c.h"
50 
51 /*******************************************************************************
52  * Definitions
53  ******************************************************************************/
54 /*! @brief This defines the sensor specific information. */
55 typedef struct
56 {
57  registerDeviceInfo_t deviceInfo; /*!< I2C device context. */
58  ARM_DRIVER_I2C *pCommDrv; /*!< Pointer to the i2c driver. */
59  bool isInitialized; /*!< Init status.*/
60  uint16_t slaveAddress; /*!< slave address.*/
62 
63 /*! @brief This structure defines the mma845x raw data buffer.*/
64 typedef struct
65 {
66  uint32_t timestamp; /*!< Time stamp value in micro-seconds. */
67  int16_t accel[3]; /*!< The accel data */
69 
70 /*! @def MMA845x_ACCEL_DATA_SIZE
71  * @brief The size of the MMA845x accel data.
72  */
73 #define MMA845x_ACCEL_DATA_SIZE (0x06)
74 
75 /*******************************************************************************
76  * APIs
77  ******************************************************************************/
78 /*! @brief The interface function to initialize the sensor.
79  * @details This function initialize the sensor and sensor handle.
80  * @param[in] pSensorHandle handle to the sensor.
81  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
82  * @param[in] index the I2C device number.
83  * @param[in] sAddress slave address of the device on the bus.
84  * @param[in] whoami WHO_AM_I value of the device.
85  * @constraints This should be the first API to be called.
86  * Application has to ensure that previous instances of these APIs have exited before invocation.
87  * @reeentrant No
88  * @return ::MMA845x_I2C_Initialize() returns the status.
89  */
91  mma845x_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi);
92 
93 /*! @brief : The interface function to set the I2C Idle Task.
94  * @param[in] : mma845x_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
95  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
96  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
97  * @return void.
98  * @constraints This can be called any number of times only after MMA845x_I2C_Initialize().
99  * Application has to ensure that previous instances of these APIs have exited before invocation.
100  * @reeentrant No
101  */
103  registeridlefunction_t idleTask,
104  void *userParam);
105 
106 /*! @brief The interface function to configure he sensor.
107  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
108  * @param[in] pSensorHandle handle to the sensor.
109  * @param[in] pRegWriteList pointer to the register list.
110  * @constraints This can be called any number of times only after MMA845x_I2C_Initialize().
111  * Application has to ensure that previous instances of these APIs have exited before invocation.
112  * @reeentrant No
113  * @return ::MMA845x_I2C_Configure() returns the status.
114  */
116 
117 /*! @brief The interface function to read the sensor data.
118  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
119  * @param[in] pSensorHandle handle to the sensor.
120  * @param[in] pReadList pointer to the list of device registers and values to read.
121  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
122  * command read in the list.
123  * @constraints This can be called any number of times only after MMA845x_I2C_Initialize().
124  * Application has to ensure that previous instances of these APIs have exited before invocation.
125  * @reeentrant No
126  * @return ::MMA845x_I2C_ReadData() returns the status.
127  */
129  const registerreadlist_t *pReadList,
130  uint8_t *pBuffer);
131 
132 /*! @brief The interface function to De Initialize sensor..
133  * @details This function made sensor in a power safe state and de initialize its handle.
134  * @param[in] pSensorHandle handle to the sensor.
135  * @constraints This can be called only after MMA845x_I2C_Initialize() has been called.
136  * Application has to ensure that previous instances of these APIs have exited before invocation.
137  * @reeentrant No
138  * @return ::MMA845x_I2C_Deinit() returns the status.
139  */
141 
142 #endif // MMA845x_DRV_H_
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
ARM_DRIVER_I2C * pCommDrv
Definition: mma845x_drv.h:58
int32_t MMA845x_I2C_ReadData(mma845x_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mma845x_drv.c:130
This defines the sensor specific information.
Definition: mma845x_drv.h:55
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
This structure defines the mma845x raw data buffer.
Definition: mma845x_drv.h:64
void MMA845x_I2C_SetIdleTask(mma845x_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mma845x_drv.c:79
int32_t MMA845x_I2C_Configure(mma845x_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: mma845x_drv.c:87
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
int32_t MMA845x_I2C_Deinit(mma845x_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mma845x_drv.c:159
The mma845x.h contains the MMA845x sensor register definitions and its bit mask.
registerDeviceInfo_t deviceInfo
Definition: mma845x_drv.h:57
int32_t MMA845x_I2C_Initialize(mma845x_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: mma845x_drv.c:48
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
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...