1 /* 2 * Copyright 2023 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 /** 9 * @file fxls8961_drv.h 10 * @brief The fxls8961_drv.h file describes the FXLS8961AF (Chiron S&C) driver interface and structures. 11 */ 12 13 #ifndef FXLS8961_AF_H_ 14 #define FXLS8961_AF_H_ 15 16 /* Standard C Includes */ 17 #include <stdint.h> 18 19 /* ISSDK Includes */ 20 #include "fxls8961.h" 21 #include "sensor_io_i2c.h" 22 #include "sensor_io_spi.h" 23 #include "register_io_i2c.h" 24 #include "register_io_spi.h" 25 26 /******************************************************************************* 27 * Definitions 28 ******************************************************************************/ 29 /*! 30 * @brief This defines the sensor specific information for SPI. 31 */ 32 typedef struct 33 { 34 registerDeviceInfo_t deviceInfo; /*!< SPI device context. */ 35 ARM_DRIVER_SPI *pCommDrv; /*!< Pointer to the spi driver. */ 36 bool isInitialized; /*!< Whether sensor is intialized or not.*/ 37 spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/ 38 } fxls8961_spi_sensorhandle_t; 39 40 /*! 41 * @brief This defines the sensor specific information for I2C. 42 */ 43 typedef struct 44 { 45 registerDeviceInfo_t deviceInfo; /*!< I2C device context. */ 46 ARM_DRIVER_I2C *pCommDrv; /*!< Pointer to the i2c driver. */ 47 bool isInitialized; /*!< whether sensor is intialized or not.*/ 48 uint16_t slaveAddress; /*!< slave address.*/ 49 } fxls8961_i2c_sensorhandle_t; 50 51 /*! @brief This structure defines the fxls8961 raw data buffer.*/ 52 typedef struct 53 { 54 uint32_t timestamp; /*! The time, this sample was recorded. */ 55 int16_t accel[3]; /*!< The accel data */ 56 } fxls8961_acceldata_t; 57 58 /*! @def fxls8961_SPI_MAX_MSG_SIZE 59 * @brief The MAX size of SPI message. */ 60 #define FXLS8961_SPI_MAX_MSG_SIZE (64) 61 62 /*! @def FXLS8961_SPI_CMD_LEN 63 * @brief The size of the Sensor specific SPI Header. */ 64 #define FXLS8961_SPI_CMD_LEN (2) 65 66 /*! @def FXLS8961_SS_ACTIVE_VALUE 67 * @brief Is the Slave Select Pin Active Low or High. */ 68 #define FXLS8961_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW 69 70 /******************************************************************************* 71 * APIs 72 ******************************************************************************/ 73 /*! @brief The interface function to initialize the sensor. 74 * @details This function initialize the sensor and sensor handle. 75 * @param[in] pSensorHandle handle to the sensor. 76 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 77 * @param[in] index the I2C device number. 78 * @param[in] sAddress slave address of the device on the bus. 79 * @param[in] whoami WHO_AM_I value of the device. 80 * @constraints This should be the first API to be called. 81 * Application has to ensure that previous instances of these APIs have exited before invocation. 82 * @reeentrant No 83 * @return ::FXLS8961_I2C_Initialize() returns the status . 84 */ 85 int32_t FXLS8961_I2C_Initialize( 86 fxls8961_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoAmi); 87 88 /*! @brief : The interface function to set the I2C Idle Task. 89 * @param[in] : fxls8961_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle. 90 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time. 91 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 92 * @return void. 93 * @constraints This can be called any number of times only after FXLS8961_I2C_Initialize(). 94 * Application has to ensure that previous instances of these APIs have exited before invocation. 95 * @reeentrant No 96 */ 97 void FXLS8961_I2C_SetIdleTask(fxls8961_i2c_sensorhandle_t *pSensorHandle, 98 registeridlefunction_t idleTask, 99 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 FXLS8961_I2C_Initialize(). 106 * Application has to ensure that previous instances of these APIs have exited before invocation. 107 * @reeentrant No 108 * @return ::FXLS8961_I2C_Configure() returns the status . 109 */ 110 int32_t FXLS8961_I2C_Configure(fxls8961_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 any number of times only after FXLS8961_I2C_Initialize(). 119 * Application has to ensure that previous instances of these APIs have exited before invocation. 120 * @reeentrant No 121 * @return ::FXLS8961_I2C_ReadData() returns the status . 122 */ 123 int32_t FXLS8961_I2C_ReadData(fxls8961_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 FXLS8961_I2C_Initialize(). 131 * Application has to ensure that previous instances of these APIs have exited before invocation. 132 * @reeentrant No 133 * @return ::FXLS8961_I2C_DeInit() returns the status . 134 */ 135 int32_t FXLS8961_I2C_DeInit(fxls8961_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 ::FXLS8961_SPI_Initialize() returns the status . 148 */ 149 int32_t FXLS8961_SPI_Initialize(fxls8961_spi_sensorhandle_t *pSensorHandle, 150 ARM_DRIVER_SPI *pBus, 151 uint8_t index, 152 void *pSlaveSelect, 153 uint8_t *whoAmi); 154 155 /*! @brief : The interface function to set the SPI Idle Task. 156 * @param[in] : fxls8961_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle. 157 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time. 158 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 159 * @return void. 160 * @constraints This can be called any number of times only after FXLS8961_SPI_Initialize(). 161 * Application has to ensure that previous instances of these APIs have exited before invocation. 162 * @reeentrant No 163 */ 164 void FXLS8961_SPI_SetIdleTask(fxls8961_spi_sensorhandle_t *pSensorHandle, 165 registeridlefunction_t idleTask, 166 void *userParam); 167 168 /*! @brief The interface function to configure he sensor. 169 * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array. 170 * @param[in] pSensorHandle handle to the sensor. 171 * @param[in] pRegWriteList pointer to the register list. 172 * @constraints This can be called any number of times only after FXLS8961_SPI_Initialize(). 173 * Application has to ensure that previous instances of these APIs have exited before invocation. 174 * @reeentrant No 175 * @return ::FXLS8961_SPI_Configure() returns the status . 176 */ 177 int32_t FXLS8961_SPI_Configure(fxls8961_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList); 178 179 /*! @brief The interface function to read the sensor data. 180 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 181 * @param[in] pSensorHandle handle to the sensor. 182 * @param[in] pReadList pointer to the list of device registers and values to read. 183 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 184 * command read in the list. 185 * @constraints This can be called any number of times only after FXLS8961_SPI_Initialize(). 186 * Application has to ensure that previous instances of these APIs have exited before invocation. 187 * @reeentrant No 188 * @return ::FXLS8961_SPI_ReadData() returns the status . 189 */ 190 int32_t FXLS8961_SPI_ReadData(fxls8961_spi_sensorhandle_t *pSensorHandle, 191 const registerreadlist_t *pReadList, 192 uint8_t *pBuffer); 193 194 /*! @brief The interface function to De Initialize sensor.. 195 * @details This function made sensor in a power safe state and de initialize its handle. 196 * @param[in] pSensorHandle handle to the sensor. 197 * @constraints This can be called only after after FXLS8961_SPI_Initialize(). 198 * Application has to ensure that previous instances of these APIs have exited before invocation. 199 * @reeentrant No 200 * @return ::FXLS8961_SPI_Deinit() returns the status . 201 */ 202 int32_t FXLS8961_SPI_Deinit(fxls8961_spi_sensorhandle_t *pSensorHandle); 203 204 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. 205 * @details This function prepares the SPI Read Command Header with register address and 206 * R/W bit encoded as the Sensor. 207 * @param[out] pCmdOut handle to the output buffer. 208 * @param[in] offset the address of the register to start reading from. 209 * @param[in] size number of bytes to read. 210 * @constraints None 211 * Application has to ensure that previous instances of these APIs have exited before invocation. 212 * @reeentrant No 213 * @return :: None. 214 */ 215 void FXLS8961_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size); 216 217 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header. 218 * @details This function prepares the SPI Write Command Header with register address and 219 * R/W bit encoded as the Sensor. 220 * @param[out] pCmdOut handle to the output buffer. 221 * @param[in] offset the address of the register to start writing from. 222 * @param[in] size number of bytes to write. 223 * @constraints None 224 * Application has to ensure that previous instances of these APIs have exited before invocation. 225 * @reeentrant No 226 * @return :: None. 227 */ 228 void FXLS8961_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer); 229 230 #endif // FXLS8961_AF_H_ 231