ISSDK  1.8
IoT Sensing Software Development Kit
dbap_drv.c
Go to the documentation of this file.
1 /*
2 * Copyright 2020 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7 
8 
9 /**
10  * @file dbap_drv.c
11  * @brief The dbap_drv.c file implements the dbap functional interface.
12  */
13 
14 //-----------------------------------------------------------------------
15 // ISSDK Includes
16 //-----------------------------------------------------------------------
17 #include "gpio_driver.h"
18 #include "dbap_drv.h"
19 #include "systick_utils.h"
20 
22  dbap_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
23 {
25  uint8_t reg = 1;
26 
27  /*! Check the input parameters. */
28  if ((pSensorHandle == NULL) || (pBus == NULL))
29  {
31  }
32 
33  pSensorHandle->deviceInfo.deviceInstance = index;
34  pSensorHandle->deviceInfo.functionParam = NULL;
35  pSensorHandle->deviceInfo.idleFunction = NULL;
36 
37  /*! Read and store the device's WHO_AM_I.*/
38  status = Register_I2C_Read(pBus, &pSensorHandle->deviceInfo, sAddress, FXPS7250_WHO_AM_I, 1, &reg);
39  if ((ARM_DRIVER_OK != status) || (whoAmi != reg))
40  {
41  pSensorHandle->isInitialized = false;
42  return SENSOR_ERROR_INIT;
43  }
44 
45  /*! Initialize the sensor handle. */
46  pSensorHandle->pCommDrv = pBus;
47  pSensorHandle->slaveAddress = sAddress;
48  pSensorHandle->isInitialized = true;
49 
50  return SENSOR_ERROR_NONE;
51 }
52 
53 void DBAP_I2C_SetIdleTask(dbap_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
54 {
55  pSensorHandle->deviceInfo.functionParam = userParam;
56  pSensorHandle->deviceInfo.idleFunction = idleTask;
57 }
58 
60 {
62 
63  /*! Validate for the correct handle and register write list.*/
64  if ((pSensorHandle == NULL) || (pRegWriteList == NULL))
65  {
67  }
68 
69  /*! Check whether sensor handle is initialized before applying configuration.*/
70  if (pSensorHandle->isInitialized != true)
71  {
72  return SENSOR_ERROR_INIT;
73  }
74 
75  /*! Apply the Sensor Configuration based on the Register Write List */
76  status = Sensor_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
77  pRegWriteList);
78  if (ARM_DRIVER_OK != status)
79  {
80  return SENSOR_ERROR_WRITE;
81  }
82 
83  return SENSOR_ERROR_NONE;
84 }
85 
87  const registerreadlist_t *pReadList,
88  uint8_t *pBuffer)
89 {
91 
92  /*! Validate for the correct handle and register read list.*/
93  if ((pSensorHandle == NULL) || (pReadList == NULL) || (pBuffer == NULL))
94  {
96  }
97 
98  /*! Check whether sensor handle is initialized before reading sensor data.*/
99  if (pSensorHandle->isInitialized != true)
100  {
101  return SENSOR_ERROR_INIT;
102  }
103 
104  /*! Parse through the read list and read the data one by one. */
105  status = Sensor_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
106  pReadList, pBuffer);
107  if (ARM_DRIVER_OK != status)
108  {
109  return SENSOR_ERROR_READ;
110  }
111 
112  return SENSOR_ERROR_NONE;
113 }
114 
int32_t DBAP_I2C_ReadData(dbap_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: dbap_drv.c:86
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
This defines the sensor specific information for I2C.
Definition: dbap_drv.h:33
void DBAP_I2C_SetIdleTask(dbap_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: dbap_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.
The dbap_drv.h file describes the DBAP driver interface and structures.
ARM_DRIVER_I2C * pCommDrv
Definition: dbap_drv.h:36
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
registerDeviceInfo_t deviceInfo
Definition: dbap_drv.h:35
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
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
Definition: sensor_drv.h:97
int32_t DBAP_I2C_Initialize(dbap_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: dbap_drv.c:21
This structure defines the Read command List.
Definition: sensor_drv.h:78
ARM Systick Utilities.
int32_t DBAP_I2C_Configure(dbap_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: dbap_drv.c:59
registeridlefunction_t idleFunction
Definition: sensor_drv.h:104