ISSDK  1.7
IoT Sensing Software Development Kit
mag3110_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 mag3110_drv.h
37  * @brief The mag3110_drv.h file describes the MAG3110 driver interface and structures.
38  */
39 
40 #ifndef MAG3110_FI_H_
41 #define MAG3110_FI_H_
42 
43 /* Standard C Includes */
44 #include <stdint.h>
45 
46 /* ISSDK Includes */
47 #include "mag3110.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 mag3110 data buffer.*/
64 typedef struct
65 {
66  uint32_t timestamp; /*!< Time stamp value in micro-seconds. */
67  int16_t mag[3]; /*!< Sensor Magnetic Strength output: signed 16-bits. */
69 
70 /*******************************************************************************
71  * APIs
72  ******************************************************************************/
73 /*! @brief The interface function to initialize the sensor.
74  * @details This function initialize the sensor and sensor handle.
75  * @param[in] pSensorHandle handle to the sensor.
76  * @param[in] pBus pointer to the CMSIS API compatible I2C bus object.
77  * @param[in] index the I2C device number.
78  * @param[in] sAddress slave address of the device on the bus.
79  * @param[in] whoami WHO_AM_I value of the device.
80  * @constraints This should be the first API to be called.
81  * Application has to ensure that previous instances of these APIs have exited before invocation.
82  * @reeentrant No
83  * @return ::MAG3110_I2C_Initialize() returns the status.
84  */
86  mag3110_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi);
87 
88 /*! @brief : The interface function to set the I2C Idle Task.
89  * @param[in] : mag3110_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
90  * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
91  * @param[in] : void *userParam, the pointer to the user idle ftask parameters.
92  * @return void.
93  * @constraints This can be called any number of times only after MAG3110_I2C_Initialize().
94  * Application has to ensure that previous instances of these APIs have exited before invocation.
95  * @reeentrant No
96  */
98  registeridlefunction_t idleTask,
99  void *userParam);
100 
101 /*! @brief The interface function to configure he sensor.
102  * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
103  * @param[in] pSensorHandle handle to the sensor.
104  * @param[in] pRegWriteList pointer to the register list.
105  * @constraints This can be called any number of times only after MAG3110_I2C_Initialize().
106  * Application has to ensure that previous instances of these APIs have exited before invocation.
107  * @reeentrant No
108  * @return ::MAG3110_I2C_Configure() returns the status.
109  */
111 
112 /*! @brief The interface function to read the sensor data.
113  * @details This function read the sensor data out from the device and returns raw data in a byte stream.
114  * @param[in] pSensorHandle handle to the sensor.
115  * @param[in] pReadList pointer to the list of device registers and values to read.
116  * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based
117  * command read in the list.
118  * @constraints This can be called any number of times only after MAG3110_I2C_Initialize().
119  * Application has to ensure that previous instances of these APIs have exited before invocation.
120  * @reeentrant No
121  * @return ::MAG3110_I2C_ReadData() returns the status .
122  */
124  const registerreadlist_t *pReadList,
125  uint8_t *pBuffer);
126 
127 /*! @brief The interface function to De Initialize sensor..
128  * @details This function made sensor in a power safe state and de initialize its handle.
129  * @param[in] pSensorHandle handle to the sensor.
130  * @constraints This can be called only after MAG3110_I2C_Initialize() has been called.
131  * Application has to ensure that previous instances of these APIs have exited before invocation.
132  * @reeentrant No
133  * @return ::MAG3110_I2C_DeInit() returns the status.
134  */
136 
137 /*!
138 * @brief Calibrates the magnetometer reading by determining the current hard iron offset.
139 * @details This function must be periodically called during the program execution to constantly
140 * calibrate the magnetometer sensor.
141 * @param [in/out] xValue Magnetometer X-axis reading.
142 * @param [in/out] yValue Magnetometer Y-Axis reading.
143 * @param [in/out] zValue Magnetometer Z-Axis reading.
144 * @constraints This function should be called after each ODR on acquired data.
145 * @reeentrant No
146 * @return void
147 */
148 void MAG3110_CalibrateHardIronOffset(int16_t* xValue, int16_t* yValue, int16_t* zValue);
149 
150 #endif // MAG3110_FI_H_
The register_io_i2c.h file declares low-level interface functions for reading and writing sensor regi...
This defines the sensor specific information.
Definition: mag3110_drv.h:55
ARM_DRIVER_I2C * pCommDrv
Definition: mag3110_drv.h:58
int32_t MAG3110_I2C_DeInit(mag3110_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mag3110_drv.c:159
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:123
uint32_t timestamp
Definition: mag3110_drv.h:66
The mag3110.h contains the MAG3110 Magnetic sensor register definitions, access macros, and device access functions.
This structure defines the mag3110 data buffer.
Definition: mag3110_drv.h:64
void MAG3110_I2C_SetIdleTask(mag3110_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mag3110_drv.c:79
int32_t MAG3110_I2C_Configure(mag3110_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: mag3110_drv.c:87
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
registerDeviceInfo_t deviceInfo
Definition: mag3110_drv.h:57
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
int32_t MAG3110_I2C_Initialize(mag3110_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: mag3110_drv.c:48
int32_t MAG3110_I2C_ReadData(mag3110_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mag3110_drv.c:130
The sensor_io_i2c.h file declares low-level interface functions for reading and writing sensor regist...
void MAG3110_CalibrateHardIronOffset(int16_t *xValue, int16_t *yValue, int16_t *zValue)
Calibrates the magnetometer reading by determining the current hard iron offset.
Definition: mag3110_drv.c:190