ISSDK  1.8
IoT Sensing Software Development Kit
isl29023_drv.c
Go to the documentation of this file.
1 /*
2  * Copyright 2018 NXP
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 /**
9  * @file isl29023_drv.c
10  * @brief The isl29023_drv.c file implements the isl29023 functional interface.
11  */
12 
13 //-----------------------------------------------------------------------
14 // ISSDK Includes
15 //-----------------------------------------------------------------------
16 #include "isl29023_drv.h"
17 
18 //-----------------------------------------------------------------------
19 // Functions
20 //-----------------------------------------------------------------------
22  isl29023_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t test)
23 {
25  uint8_t reg;
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 test.*/
38  status = Register_I2C_Read(pBus, &pSensorHandle->deviceInfo, sAddress, ISL29023_TEST, 1, &reg);
39  if ((ARM_DRIVER_OK != status) || (test != 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  return SENSOR_ERROR_NONE;
50 }
51 
53  registeridlefunction_t idleTask,
54  void *userParam)
55 {
56  pSensorHandle->deviceInfo.functionParam = userParam;
57  pSensorHandle->deviceInfo.idleFunction = idleTask;
58 }
59 
61 {
63 
64  /*! Validate for the correct handle and register write list.*/
65  if ((pSensorHandle == NULL) || (pRegWriteList == NULL))
66  {
68  }
69 
70  /*! Check whether sensor handle is initialized before applying configuration.*/
71  if (pSensorHandle->isInitialized != true)
72  {
73  return SENSOR_ERROR_INIT;
74  }
75 
76  /*! Apply the Sensor Configuration based on the Register Write List */
77  status = Sensor_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
78  pRegWriteList);
79  if (ARM_DRIVER_OK != status)
80  {
81  return SENSOR_ERROR_WRITE;
82  }
83 
84  return SENSOR_ERROR_NONE;
85 }
86 
88  const registerreadlist_t *pReadList,
89  uint8_t *pBuffer)
90 {
92 
93  /*! Validate for the correct handle and register read list.*/
94  if ((pSensorHandle == NULL) || (pReadList == NULL) || (pBuffer == NULL))
95  {
97  }
98 
99  /*! Check whether sensor handle is initialized before reading sensor data.*/
100  if (pSensorHandle->isInitialized != true)
101  {
102  return SENSOR_ERROR_INIT;
103  }
104 
105  /*! Parse through the read list and read the data one by one. */
106  status = Sensor_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
107  pReadList, pBuffer);
108  if (ARM_DRIVER_OK != status)
109  {
110  return SENSOR_ERROR_READ;
111  }
112 
113  return SENSOR_ERROR_NONE;
114 }
115 
117 {
118  int32_t status;
119 
120  if (pSensorHandle == NULL)
121  {
123  }
124 
125  /*! Check whether sensor handle is initialized before triggering sensor reset.*/
126  if (pSensorHandle->isInitialized != true)
127  {
128  return SENSOR_ERROR_INIT;
129  }
130 
131  /*! Trigger sensor device reset.*/
132  status = Register_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
134  if (ARM_DRIVER_OK != status)
135  {
136  return SENSOR_ERROR_WRITE;
137  }
138  else
139  {
140  /*! De-initialize sensor handle. */
141  pSensorHandle->isInitialized = false;
142  }
143 
144  return SENSOR_ERROR_NONE;
145 }
#define ISL29023_CMD_I_OP_MASK
Definition: isl29023.h:58
The isl29023_drv.h file describes the ISL29023 driver interface and structures.
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
#define ISL29023_CMD_I_OP_POWER_DOWN
Definition: isl29023.h:71
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 ISL29023_I2C_ReadData(isl29023_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
Definition: isl29023_drv.c:87
int32_t ISL29023_I2C_Configure(isl29023_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
Definition: isl29023_drv.c:60
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
int32_t ISL29023_I2C_DeInit(isl29023_i2c_sensorhandle_t *pSensorHandle)
The interface function to De Initialize sensor..
Definition: isl29023_drv.c:116
registerDeviceInfo_t deviceInfo
Definition: isl29023_drv.h:30
This defines the sensor specific information.
Definition: isl29023_drv.h:28
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
ARM_DRIVER_I2C * pCommDrv
Definition: isl29023_drv.h:31
int32_t ISL29023_I2C_Initialize(isl29023_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t test)
The interface function to initialize the sensor.
Definition: isl29023_drv.c:21
This structure defines the Read command List.
Definition: sensor_drv.h:78
void ISL29023_I2C_SetIdleTask(isl29023_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
Definition: isl29023_drv.c:52
registeridlefunction_t idleFunction
Definition: sensor_drv.h:104