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 diff_p_drv.h 11 * @brief The diff_p_drv.h file describes the DIFF_P driver interface and structures. 12 */ 13 14 #ifndef DIFF_P_FI_H_ 15 #define DIFF_P_FI_H_ 16 17 /* Standard C Includes */ 18 #include <stdint.h> 19 20 /* ISSDK Includes */ 21 #include "diff_p.h" 22 #include "sensor_io_i2c.h" 23 #include "sensor_io_spi.h" 24 #include "register_io_i2c.h" 25 #include "register_io_spi.h" 26 27 /******************************************************************************* 28 * Definitions 29 ******************************************************************************/ 30 /*! 31 * @brief This defines the sensor specific information for SPI. 32 */ 33 typedef struct 34 { 35 registerDeviceInfo_t deviceInfo; /*!< SPI device context. */ 36 ARM_DRIVER_SPI *pCommDrv; /*!< Pointer to the spi driver. */ 37 bool isInitialized; /*!< Whether sensor is intialized or not.*/ 38 spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/ 39 } diff_p_spi_sensorhandle_t; 40 41 /*! 42 * @brief This defines the sensor specific information for I2C. 43 */ 44 typedef struct 45 { 46 registerDeviceInfo_t deviceInfo; /*!< I2C device context. */ 47 ARM_DRIVER_I2C *pCommDrv; /*!< Pointer to the i2c driver. */ 48 bool isInitialized; /*!< whether sensor is intialized or not.*/ 49 uint16_t slaveAddress; /*!< slave address.*/ 50 } diff_p_i2c_sensorhandle_t; 51 52 /*! @brief This structure defines the diff_p data buffer in Pressure Mode.*/ 53 typedef struct 54 { 55 uint32_t timestamp; /*!< Time stamp value in micro-seconds. */ 56 int16_t pressure; /*!< Sensor pressure output: unsigned 16-bits justified to MSBs. */ 57 int8_t temperature; /*!< Sensor temperature output; 2's complement 8-bits justified to MSBs. */ 58 } diff_p_pressuredata_t; 59 60 /*! @def DIFF_P_SPI_MAX_MSG_SIZE 61 * @brief The MAX size of SPI message. */ 62 #define DIFF_P_SPI_MAX_MSG_SIZE (64) 63 64 /*! @def DIFF_P_SPI_CMD_LEN 65 * @brief The size of the Sensor specific SPI Header. */ 66 #define DIFF_P_SPI_CMD_LEN (1) 67 68 /*! @def DIFF_P_SS_ACTIVE_VALUE 69 * @brief Is the Slave Select Pin Active Low or High. */ 70 #define DIFF_P_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW 71 72 /******************************************************************************* 73 * APIs 74 ******************************************************************************/ 75 /*! @brief The interface function to initialize the sensor. 76 * @details This function initialize the sensor and sensor handle. 77 * @param[in] pSensorHandle handle to the sensor. 78 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 79 * @param[in] index the I2C device number. 80 * @param[in] sAddress slave address of the device on the bus. 81 * @param[in] whoami WHO_AM_I value of the device. 82 * @constraints This should be the first API to be called. 83 * Application has to ensure that previous instances of these APIs have exited before invocation. 84 * @reeentrant No 85 * @return ::DIFF_P_I2C_Initialize() returns the status. 86 */ 87 int32_t DIFF_P_I2C_Initialize( 88 diff_p_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi); 89 90 /*! @brief : The interface function to set the I2C Idle Task. 91 * @param[in] : diff_p_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle. 92 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time. 93 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 94 * @return void. 95 * @constraints This can be called any number of times only after DIFF_P_I2C_Initialize(). 96 * Application has to ensure that previous instances of these APIs have exited before invocation. 97 * @reeentrant No 98 */ 99 void DIFF_P_I2C_SetIdleTask(diff_p_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam); 100 101 /*! @brief The interface function to configure he sensor. 102 * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array. 103 * @param[in] pSensorHandle handle to the sensor. 104 * @param[in] pRegWriteList pointer to the register list. 105 * @constraints This can be called any number of times only after DIFF_P_I2C_Initialize(). 106 * Application has to ensure that previous instances of these APIs have exited before invocation. 107 * @reeentrant No 108 * @return ::DIFF_P_I2C_Configure() returns the status. 109 */ 110 int32_t DIFF_P_I2C_Configure(diff_p_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList); 111 112 /*! @brief The interface function to read the sensor data. 113 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 114 * @param[in] pSensorHandle handle to the sensor. 115 * @param[in] pReadList pointer to the list of device registers and values to read. 116 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 117 * command read in the list. 118 * @constraints This can be called only after DIFF_P_I2C_Initialize(). 119 * Application has to ensure that previous instances of these APIs have exited before invocation. 120 * @reeentrant No 121 * @return ::DIFF_P_I2C_ReadData() returns the status . 122 */ 123 int32_t DIFF_P_I2C_ReadData(diff_p_i2c_sensorhandle_t *pSensorHandle, 124 const registerreadlist_t *pReadList, 125 uint8_t *pBuffer); 126 127 /*! @brief The interface function to De Initialize sensor.. 128 * @details This function made sensor in a power safe state and de initialize its handle. 129 * @param[in] pSensorHandle handle to the sensor. 130 * @constraints This can be called only after DIFF_P_I2C_Initialize() has been called. 131 * Application has to ensure that previous instances of these APIs have exited before invocation. 132 * @reeentrant No 133 * @return ::DIFF_P_I2C_DeInit() returns the status. 134 */ 135 int32_t DIFF_P_I2C_DeInit(diff_p_i2c_sensorhandle_t *pSensorHandle); 136 137 /*! @brief The interface function to initialize the sensor. 138 * @details This function initializes the sensor and sensor handle. 139 * @param[in] pSensorHandle handle to the sensor. 140 * @param[in] pBus pointer to the CMSIS API compatible SPI bus object. 141 * @param[in] index the I2C device number. 142 * @param[in] pSlaveSelect slave select hndle of the device on the bus. 143 * @param[in] whoami WHO_AM_I value of the device. 144 * @constraints This should be the first API to be called. 145 * Application has to ensure that previous instances of these APIs have exited before invocation. 146 * @reeentrant No 147 * @return ::DIFF_P_SPI_Initialize() returns the status . 148 */ 149 int32_t DIFF_P_SPI_Initialize( 150 diff_p_spi_sensorhandle_t *pSensorHandle, ARM_DRIVER_SPI *pBus, uint8_t index, void *pSlaveSelect, uint8_t whoAmi); 151 152 /*! @brief : The interface function to set the SPI Idle Task. 153 * @param[in] : diff_p_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle. 154 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time. 155 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 156 * @return void. 157 * @constraints This can be called any number of times only after DIFF_P_SPI_Initialize(). 158 * Application has to ensure that previous instances of these APIs have exited before invocation. 159 * @reeentrant No 160 */ 161 void DIFF_P_SPI_SetIdleTask(diff_p_spi_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam); 162 163 /*! @brief The interface function to configure he sensor. 164 * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array. 165 * @param[in] pSensorHandle handle to the sensor. 166 * @param[in] pRegWriteList pointer to the register list. 167 * @constraints This can be called any number of times only after DIFF_P_SPI_Initialize(). 168 * Application has to ensure that previous instances of these APIs have exited before invocation. 169 * @reeentrant No 170 * @return ::DIFF_P_SPI_Configure() returns the status . 171 */ 172 int32_t DIFF_P_SPI_Configure(diff_p_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList); 173 174 /*! @brief The interface function to read the sensor data. 175 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 176 * @param[in] pSensorHandle handle to the sensor. 177 * @param[in] pReadList pointer to the list of device registers and values to read. 178 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 179 * command read in the list. 180 * @constraints This can be called any number of times only after DIFF_P_SPI_Initialize(). 181 * Application has to ensure that previous instances of these APIs have exited before invocation. 182 * @reeentrant No 183 * @return ::DIFF_P_SPI_ReadData() returns the status . 184 */ 185 int32_t DIFF_P_SPI_ReadData(diff_p_spi_sensorhandle_t *pSensorHandle, 186 const registerreadlist_t *pReadList, 187 uint8_t *pBuffer); 188 189 /*! @brief The interface function to De Initialize sensor.. 190 * @details This function made sensor in a power safe state and de initialize its handle. 191 * @param[in] pSensorHandle handle to the sensor. 192 * @constraints This can be called only after after DIFF_P_SPI_Initialize(). 193 * Application has to ensure that previous instances of these APIs have exited before invocation. 194 * @reeentrant No 195 * @return ::DIFF_P_SPI_Deinit() returns the status . 196 */ 197 int32_t DIFF_P_SPI_DeInit(diff_p_spi_sensorhandle_t *pSensorHandle); 198 199 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. 200 * @details This function prepares the SPI Read Command Header with register address and 201 * R/W bit encoded as the Sensor. 202 * @param[out] pCmdOut handle to the output buffer. 203 * @param[in] offset the address of the register to start reading from. 204 * @param[in] size number of bytes to read. 205 * @constraints None 206 * Application has to ensure that previous instances of these APIs have exited before invocation. 207 * @reeentrant No 208 * @return :: None. 209 */ 210 void DIFF_P_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size); 211 212 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header. 213 * @details This function prepares the SPI Write Command Header with register address and 214 * R/W bit encoded as the Sensor. 215 * @param[out] pCmdOut handle to the output buffer. 216 * @param[in] offset the address of the register to start writing from. 217 * @param[in] size number of bytes to write. 218 * @constraints None 219 * Application has to ensure that previous instances of these APIs have exited before invocation. 220 * @reeentrant No 221 * @return :: None. 222 */ 223 void DIFF_P_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer); 224 225 #endif // DIFF_P_FI_H_ 226