ISSDK  1.8
IoT Sensing Software Development Kit
mpl3115_drv.c
Go to the documentation of this file.
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.c
11  * @brief The mpl3115_drv.c file implements the mpl3115 functional interface.
12  */
13 
14 //-----------------------------------------------------------------------
15 // ISSDK Includes
16 //-----------------------------------------------------------------------
17 #include "mpl3115_drv.h"
18 
19 //-----------------------------------------------------------------------
20 // Functions
21 //-----------------------------------------------------------------------
23  mpl3115_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
24 {
26  uint8_t reg;
27 
28  /*! Check the input parameters. */
29  if ((pSensorHandle == NULL) || (pBus == NULL))
30  {
32  }
33 
34  pSensorHandle->deviceInfo.deviceInstance = index;
35  pSensorHandle->deviceInfo.functionParam = NULL;
36  pSensorHandle->deviceInfo.idleFunction = NULL;
37 
38  /*! Read and store the device's WHO_AM_I.*/
39  status = Register_I2C_Read(pBus, &pSensorHandle->deviceInfo, sAddress, MPL3115_WHO_AM_I, 1, &reg);
40  if ((ARM_DRIVER_OK != status) || (whoAmi != reg))
41  {
42  pSensorHandle->isInitialized = false;
43  return SENSOR_ERROR_INIT;
44  }
45 
46  /*! Initialize the sensor handle. */
47  pSensorHandle->pCommDrv = pBus;
48  pSensorHandle->slaveAddress = sAddress;
49  pSensorHandle->isInitialized = true;
50  return SENSOR_ERROR_NONE;
51 }
52 
54  registeridlefunction_t idleTask,
55  void *userParam)
56 {
57  pSensorHandle->deviceInfo.functionParam = userParam;
58  pSensorHandle->deviceInfo.idleFunction = idleTask;
59 }
60 
62 {
64 
65  /*! Validate for the correct handle and register write list.*/
66  if ((pSensorHandle == NULL) || (pRegWriteList == NULL))
67  {
69  }
70 
71  /*! Check whether sensor handle is initialized before applying configuration.*/
72  if (pSensorHandle->isInitialized != true)
73  {
74  return SENSOR_ERROR_INIT;
75  }
76 
77  /*! Put the device into standby mode so that configuration can be applied.*/
78  status = Register_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
80  if (ARM_DRIVER_OK != status)
81  {
82  return SENSOR_ERROR_WRITE;
83  }
84 
85  /*! Apply the Sensor Configuration based on the Register Write List */
86  status = Sensor_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
87  pRegWriteList);
88  if (ARM_DRIVER_OK != status)
89  {
90  return SENSOR_ERROR_WRITE;
91  }
92 
93  /*! Put the device into active mode and ready for reading data.*/
94  status = Register_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
96  if (ARM_DRIVER_OK != status)
97  {
98  return SENSOR_ERROR_WRITE;
99  }
100 
101  return SENSOR_ERROR_NONE;
102 }
103 
105  const registerreadlist_t *pReadList,
106  uint8_t *pBuffer)
107 {
108  int32_t status;
109 
110  /*! Validate for the correct handle and register read list.*/
111  if ((pSensorHandle == NULL) || (pReadList == NULL) || (pBuffer == NULL))
112  {
114  }
115 
116  /*! Check whether sensor handle is initialized before reading sensor data.*/
117  if (pSensorHandle->isInitialized != true)
118  {
119  return SENSOR_ERROR_INIT;
120  }
121 
122  /*! Parse through the read list and read the data one by one. */
123  status = Sensor_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
124  pReadList, pBuffer);
125  if (ARM_DRIVER_OK != status)
126  {
127  return SENSOR_ERROR_READ;
128  }
129 
130  return SENSOR_ERROR_NONE;
131 }
132 
134 {
135  int32_t status;
136 
137  if (pSensorHandle == NULL)
138  {
140  }
141 
142  /*! Check whether sensor handle is initialized before triggering sensor reset.*/
143  if (pSensorHandle->isInitialized != true)
144  {
145  return SENSOR_ERROR_INIT;
146  }
147 
148  /*! Trigger sensor device reset.*/
149  status = Register_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
151  if (ARM_DRIVER_OK != status)
152  {
153  return SENSOR_ERROR_WRITE;
154  }
155  else
156  {
157  /*! De-initialize sensor handle. */
158  pSensorHandle->isInitialized = false;
159  }
160 
161  return SENSOR_ERROR_NONE;
162 }
#define MPL3115_CTRL_REG1_SBYB_ACTIVE
Definition: mpl3115.h:869
int32_t Sensor_I2C_Read(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registerreadlist_t *pReadList, uint8_t *pOutBuffer)
Read register data from a sensor.
This structure defines the Write command List.
Definition: sensor_drv.h:68
int32_t status
void MPL3115_I2C_SetIdleTask(mpl3115_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: mpl3115_drv.c:53
int32_t Register_I2C_Read(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, uint8_t length, uint8_t *pOutBuffer)
The interface function to read a sensor register.
int32_t Register_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, uint8_t value, uint8_t mask, bool repeatedStart)
The interface function to write a sensor register.
int32_t MPL3115_I2C_ReadData(mpl3115_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: mpl3115_drv.c:104
The mpl3115_drv.h file describes the MPL3115 driver interface and structures.
int32_t MPL3115_I2C_DeInit(mpl3115_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: mpl3115_drv.c:133
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
int32_t Sensor_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, const registerwritelist_t *pRegWriteList)
Write register data to a sensor.
Definition: sensor_io_i2c.c:71
#define MPL3115_CTRL_REG1_RST_EN
Definition: mpl3115.h:873
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
This defines the sensor specific information.
Definition: mpl3115_drv.h:36
int32_t MPL3115_I2C_Initialize(mpl3115_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: mpl3115_drv.c:22
#define MPL3115_CTRL_REG1_SBYB_MASK
Definition: mpl3115.h:846
#define MPL3115_CTRL_REG1_SBYB_STANDBY
Definition: mpl3115.h:868
ARM_DRIVER_I2C * pCommDrv
Definition: mpl3115_drv.h:39
This structure defines the Read command List.
Definition: sensor_drv.h:78
registerDeviceInfo_t deviceInfo
Definition: mpl3115_drv.h:38
registeridlefunction_t idleFunction
Definition: sensor_drv.h:104
int32_t MPL3115_I2C_Configure(mpl3115_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: mpl3115_drv.c:61
#define MPL3115_CTRL_REG1_RST_MASK
Definition: mpl3115.h:852