115 lines
3.3 KiB
C
115 lines
3.3 KiB
C
/*
|
|
* Copyright 2020 NXP
|
|
* All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
|
|
/**
|
|
* @file dbap_drv.c
|
|
* @brief The dbap_drv.c file implements the dbap functional interface.
|
|
*/
|
|
|
|
//-----------------------------------------------------------------------
|
|
// ISSDK Includes
|
|
//-----------------------------------------------------------------------
|
|
#include "gpio_driver.h"
|
|
#include "dbap_drv.h"
|
|
#include "systick_utils.h"
|
|
|
|
int32_t DBAP_I2C_Initialize(
|
|
dbap_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi)
|
|
{
|
|
int32_t status;
|
|
uint8_t reg = 1;
|
|
|
|
/*! Check the input parameters. */
|
|
if ((pSensorHandle == NULL) || (pBus == NULL))
|
|
{
|
|
return SENSOR_ERROR_INVALID_PARAM;
|
|
}
|
|
|
|
pSensorHandle->deviceInfo.deviceInstance = index;
|
|
pSensorHandle->deviceInfo.functionParam = NULL;
|
|
pSensorHandle->deviceInfo.idleFunction = NULL;
|
|
|
|
/*! Read and store the device's WHO_AM_I.*/
|
|
status = Register_I2C_Read(pBus, &pSensorHandle->deviceInfo, sAddress, FXPS7250_WHO_AM_I, 1, ®);
|
|
if ((ARM_DRIVER_OK != status) || (whoAmi != reg))
|
|
{
|
|
pSensorHandle->isInitialized = false;
|
|
return SENSOR_ERROR_INIT;
|
|
}
|
|
|
|
/*! Initialize the sensor handle. */
|
|
pSensorHandle->pCommDrv = pBus;
|
|
pSensorHandle->slaveAddress = sAddress;
|
|
pSensorHandle->isInitialized = true;
|
|
|
|
return SENSOR_ERROR_NONE;
|
|
}
|
|
|
|
void DBAP_I2C_SetIdleTask(dbap_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
|
|
{
|
|
pSensorHandle->deviceInfo.functionParam = userParam;
|
|
pSensorHandle->deviceInfo.idleFunction = idleTask;
|
|
}
|
|
|
|
int32_t DBAP_I2C_Configure(dbap_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
|
|
{
|
|
int32_t status;
|
|
|
|
/*! Validate for the correct handle and register write list.*/
|
|
if ((pSensorHandle == NULL) || (pRegWriteList == NULL))
|
|
{
|
|
return SENSOR_ERROR_INVALID_PARAM;
|
|
}
|
|
|
|
/*! Check whether sensor handle is initialized before applying configuration.*/
|
|
if (pSensorHandle->isInitialized != true)
|
|
{
|
|
return SENSOR_ERROR_INIT;
|
|
}
|
|
|
|
/*! Apply the Sensor Configuration based on the Register Write List */
|
|
status = Sensor_I2C_Write(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
|
|
pRegWriteList);
|
|
if (ARM_DRIVER_OK != status)
|
|
{
|
|
return SENSOR_ERROR_WRITE;
|
|
}
|
|
|
|
return SENSOR_ERROR_NONE;
|
|
}
|
|
|
|
int32_t DBAP_I2C_ReadData(dbap_i2c_sensorhandle_t *pSensorHandle,
|
|
const registerreadlist_t *pReadList,
|
|
uint8_t *pBuffer)
|
|
{
|
|
int32_t status;
|
|
|
|
/*! Validate for the correct handle and register read list.*/
|
|
if ((pSensorHandle == NULL) || (pReadList == NULL) || (pBuffer == NULL))
|
|
{
|
|
return SENSOR_ERROR_INVALID_PARAM;
|
|
}
|
|
|
|
/*! Check whether sensor handle is initialized before reading sensor data.*/
|
|
if (pSensorHandle->isInitialized != true)
|
|
{
|
|
return SENSOR_ERROR_INIT;
|
|
}
|
|
|
|
/*! Parse through the read list and read the data one by one. */
|
|
status = Sensor_I2C_Read(pSensorHandle->pCommDrv, &pSensorHandle->deviceInfo, pSensorHandle->slaveAddress,
|
|
pReadList, pBuffer);
|
|
if (ARM_DRIVER_OK != status)
|
|
{
|
|
return SENSOR_ERROR_READ;
|
|
}
|
|
|
|
return SENSOR_ERROR_NONE;
|
|
}
|
|
|