1 /*
2  * Copyright (c) 2015-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 mpl3115_drv.h
11  * @brief The mpl3115_drv.h file describes the MPL3115 driver interface and structures.
12  */
13 
14 #ifndef MPL3115_FI_H_
15 #define MPL3115_FI_H_
16 
17 /* Standard C Includes */
18 #include <stdint.h>
19 
20 /* ISSDK Includes */
21 #include "mpl3115.h"
22 #include "sensor_io_i2c.h"
23 #include "register_io_i2c.h"
24 
25 /*******************************************************************************
26  * Macros
27  ******************************************************************************/
28 #define MPL3115_PRESSURE_CONV_FACTOR (64)     /* Will give Pascals */
29 #define MPL3115_ALTITUDE_CONV_FACTOR (65536)  /* Will give meters above MSL */
30 #define MPL3115_TEMPERATURE_CONV_FACTOR (256) /* Will give �C */
31 
32 /*******************************************************************************
33  * Definitions
34  ******************************************************************************/
35 /*! @brief This defines the sensor specific information. */
36 typedef struct
37 {
38     registerDeviceInfo_t deviceInfo; /*!< I2C device context. */
39     ARM_DRIVER_I2C *pCommDrv;        /*!< Pointer to the i2c driver. */
40     bool isInitialized;              /*!< Init status.*/
41     uint16_t slaveAddress;           /*!< slave address.*/
42 } mpl3115_i2c_sensorhandle_t;
43 
44 /*! @brief This structure defines the mpl3115 data buffer in Pressure Mode.*/
45 typedef struct
46 {
47     uint32_t timestamp;  /*!< Time stamp value in micro-seconds. */
48     uint32_t pressure;   /*!< Sensor pressure output: unsigned 20-bits justified to MSBs. */
49     int16_t temperature; /*!< Sensor temperature output; 2's complement 12-bits justified to MSBs.
50                               MS 8-bits are integer degrees Celsius; LS 4-bits are fractional degrees Celsius. */
51 } mpl3115_pressuredata_t;
52 
53 /*! @brief This structure defines the mpl3115 data buffer in Altitude Mode.*/
54 typedef struct
55 {
56     uint32_t timestamp;  /*!< Time stamp value in micro-seconds. */
57     int32_t altitude;    /*!< Sensor pressure/altitude output: MS 16-bits are integer meters; LS 4-bits are fractional
58                               meters. */
59     int16_t temperature; /*!< Sensor temperature output; 2's complement 12-bits justified to MSBs.
60                               MS 8-bits are integer degrees Celsius; LS 4-bits are fractional degrees Celsius. */
61 } mpl3115_altitudedata_t;
62 
63 /*******************************************************************************
64  * APIs
65  ******************************************************************************/
66 /*! @brief       The interface function to initialize the sensor.
67  *  @details     This function initialize the sensor and sensor handle.
68  *  @param[in]   pSensorHandle  handle to the sensor.
69  *  @param[in]   pBus           pointer to the CMSIS API compatible I2C bus object.
70  *  @param[in]   index          the I2C device number.
71  *  @param[in]   sAddress       slave address of the device on the bus.
72  *  @param[in]   whoami         WHO_AM_I value of the device.
73  *  @constraints This should be the first API to be called.
74  *               Application has to ensure that previous instances of these APIs have exited before invocation.
75  *  @reeentrant  No
76  *  @return      ::MPL3115_I2C_Initialize() returns the status.
77  */
78 int32_t MPL3115_I2C_Initialize(
79     mpl3115_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi);
80 
81 /*! @brief      :  The interface function to set the I2C Idle Task.
82  *  @param[in]  :  mpl3115_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle.
83  *  @param[in]  :  registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time.
84  *  @param[in]  :  void *userParam, the pointer to the user idle ftask parameters.
85  *  @return        void.
86  *  @constraints   This can be called any number of times only after MPL3115_I2C_Initialize().
87  *                 Application has to ensure that previous instances of these APIs have exited before invocation.
88  *  @reeentrant    No
89  */
90 void MPL3115_I2C_SetIdleTask(mpl3115_i2c_sensorhandle_t *pSensorHandle,
91                              registeridlefunction_t idleTask,
92                              void *userParam);
93 
94 /*! @brief       The interface function to configure he sensor.
95  *  @details     This function configure the sensor with requested ODR, Range and registers in the regsiter pair array.
96  *  @param[in]   pSensorHandle      handle to the sensor.
97  *  @param[in]   pRegWriteList      pointer to the register list.
98  *  @constraints This can be called any number of times only after MPL3115_I2C_Initialize().
99  *               Application has to ensure that previous instances of these APIs have exited before invocation.
100  *  @reeentrant  No
101  *  @return      ::MPL3115_I2C_Configure() returns the status.
102  */
103 int32_t MPL3115_I2C_Configure(mpl3115_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList);
104 
105 /*! @brief       The interface function to read the sensor data.
106  *  @details     This function read the sensor data out from the device and returns raw data in a byte stream.
107  *  @param[in]   pSensorHandle  handle to the sensor.
108  *  @param[in]   pReadList      pointer to the list of device registers and values to read.
109  *  @param[out]  pBuffer        buffer which holds raw sensor data.This buffer may be back to back databuffer based
110  *                              command read in the list.
111  *  @constraints This can be called only after MPL3115_I2C_Initialize().
112  *               Application has to ensure that previous instances of these APIs have exited before invocation.
113  *  @reeentrant  No
114  *  @return      ::MPL3115_I2C_ReadData() returns the status .
115  */
116 int32_t MPL3115_I2C_ReadData(mpl3115_i2c_sensorhandle_t *pSensorHandle,
117                              const registerreadlist_t *pReadList,
118                              uint8_t *pBuffer);
119 
120 /*! @brief       The interface function to De Initialize sensor..
121  *  @details     This function made sensor in a power safe state and de initialize its handle.
122  *  @param[in]   pSensorHandle      handle to the sensor.
123  *  @constraints This can be called only after MPL3115_I2C_Initialize() has been called.
124  *               Application has to ensure that previous instances of these APIs have exited before invocation.
125  *  @reeentrant  No
126  *  @return      ::MPL3115_I2C_DeInit() returns the status.
127  */
128 int32_t MPL3115_I2C_DeInit(mpl3115_i2c_sensorhandle_t *pSensorHandle);
129 
130 #endif // MPL3115_FI_H_
131