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 fxos8700_drv.h 11 * @brief The fxos8700_drv.h file describes the fxos8700 driver interface and structures. 12 */ 13 14 #ifndef FXOS8700_DRV_H_ 15 #define FXOS8700_DRV_H_ 16 17 /* Standard C Included Files */ 18 #include <stdint.h> 19 20 /* ISSDK Includes */ 21 #include "fxos8700.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 i2c driver. */ 37 bool isInitialized; /*!< whether sensor is intialized or not.*/ 38 spiSlaveSpecificParams_t slaveParams; /*!< Slave Specific Params.*/ 39 } fxos8700_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 } fxos8700_i2c_sensorhandle_t; 51 52 /*! @brief This structure defines the fxos8700 raw data buffer.*/ 53 typedef struct 54 { 55 uint32_t timestamp; /*! The time, this sample was recorded. */ 56 int16_t accel[3]; /*!< The accel data */ 57 int16_t mag[3]; /*!< The mag data */ 58 } fxos8700_accelmagdata_t; 59 60 /*! @brief This structure defines the fxos8700 raw accel data buffer.*/ 61 typedef struct 62 { 63 uint32_t timestamp; /*! The time, this sample was recorded. */ 64 int16_t accel[3]; /*!< The accel data */ 65 } fxos8700_acceldata_t; 66 67 /*! @def FXOS8700_SPI_MAX_MSG_SIZE 68 * @brief The MAX size of SPI message. */ 69 #define FXOS8700_SPI_MAX_MSG_SIZE (64) 70 71 /*! @def FXOS8700_SPI_CMD_LEN 72 * @brief The size of the Sensor specific SPI Header. */ 73 #define FXOS8700_SPI_CMD_LEN (2) 74 75 /*! @def FXOS8700_SS_ACTIVE_VALUE 76 * @brief Is the Slave Select Pin Active Low or High. */ 77 #define FXOS8700_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW 78 79 /******************************************************************************* 80 * APIs 81 ******************************************************************************/ 82 83 /*! @brief The interface function to initialize the sensor. 84 * @details This function initialize the sensor and sensor handle. 85 * @param[in] pSensorHandle handle to the sensor. 86 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 87 * @param[in] index the I2C device number. 88 * @param[in] sAddress slave address of the device on the bus. 89 * @param[in] whoami WHO_AM_I value of the device. 90 * @constraints This should be the first API to be called. 91 * Application has to ensure that previous instances of these APIs have exited before invocation. 92 * @reeentrant No 93 * @return ::FXOS8700_I2C_Initialize() returns the status . 94 */ 95 int32_t FXOS8700_I2C_Initialize( 96 fxos8700_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t whoAmi); 97 98 /*! @brief : The interface function to set the I2C Idle Task. 99 * @param[in] : fxos8700_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle. 100 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time. 101 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 102 * @return void. 103 * @constraints This can be called any number of times only after FXOS8700_I2C_Initialize(). 104 * Application has to ensure that previous instances of these APIs have exited before invocation. 105 * @reeentrant No 106 */ 107 void FXOS8700_I2C_SetIdleTask(fxos8700_i2c_sensorhandle_t *pSensorHandle, 108 registeridlefunction_t idleTask, 109 void *userParam); 110 111 /*! @brief The interface function to configure he sensor. 112 * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array. 113 * @param[in] pSensorHandle handle to the sensor. 114 * @param[in] pRegWriteList pointer to the register list. 115 * @constraints This can be called any number of times only after FXOS8700_I2C_Initialize(). 116 * Application has to ensure that previous instances of these APIs have exited before invocation. 117 * @reeentrant No 118 * @return ::FXOS8700_I2C_Configure() returns the status . 119 */ 120 int32_t FXOS8700_I2C_Configure(fxos8700_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList); 121 122 /*! @brief The interface function to read the sensor data. 123 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 124 * @param[in] pSensorHandle handle to the sensor. 125 * @param[in] pReadList pointer to the list of device registers and values to read. 126 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 127 * command read in the list. 128 * @constraints This can be called any number of times only after FXOS8700_I2C_Initialize(). 129 * Application has to ensure that previous instances of these APIs have exited before invocation. 130 * @reeentrant No 131 * @return ::FXOS8700_I2C_ReadData() returns the status . 132 */ 133 int32_t FXOS8700_I2C_ReadData(fxos8700_i2c_sensorhandle_t *pSensorHandle, 134 const registerreadlist_t *pReadList, 135 uint8_t *pBuffer); 136 137 /*! @brief The interface function to De Initialize sensor.. 138 * @details This function made sensor in a power safe state and de initialize its handle. 139 * @param[in] pSensorHandle handle to the sensor. 140 * @constraints This can be called only after FXOS8700_I2C_Initialize(). 141 * Application has to ensure that previous instances of these APIs have exited before invocation. 142 * @reeentrant No 143 * @return ::FXOS8700_I2C_Deinit() returns the status . 144 */ 145 int32_t FXOS8700_I2C_Deinit(fxos8700_i2c_sensorhandle_t *pSensorHandle); 146 147 /*! @brief The interface function to initialize the sensor. 148 * @details This function initializes the sensor and sensor handle. 149 * @param[in] pSensorHandle handle to the sensor. 150 * @param[in] pBus pointer to the CMSIS API compatible SPI bus object. 151 * @param[in] index the I2C device number. 152 * @param[in] pSlaveSelect slave select hndle of the device on the bus. 153 * @param[in] whoami WHO_AM_I value of the device. 154 * @constraints This should be the first API to be called. 155 * Application has to ensure that previous instances of these APIs have exited before invocation. 156 * @reeentrant No 157 * @return ::FXOS8700_SPI_Initialize() returns the status . 158 */ 159 int32_t FXOS8700_SPI_Initialize(fxos8700_spi_sensorhandle_t *pSensorHandle, 160 ARM_DRIVER_SPI *pBus, 161 uint8_t index, 162 void *pSlaveSelect, 163 uint8_t whoAmi); 164 165 /*! @brief : The interface function to set the SPI Idle Task. 166 * @param[in] : fxos8700_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle. 167 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time. 168 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 169 * @return void. 170 * @constraints This can be called any number of times only after FXOS8700_SPI_Initialize(). 171 * Application has to ensure that previous instances of these APIs have exited before invocation. 172 * @reeentrant No 173 */ 174 void FXOS8700_SPI_SetIdleTask(fxos8700_spi_sensorhandle_t *pSensorHandle, 175 registeridlefunction_t idleTask, 176 void *userParam); 177 178 /*! @brief The interface function to configure he sensor. 179 * @details This function configure the sensor with requested ODR, Range and registers in the regsiter pair array. 180 * @param[in] pSensorHandle handle to the sensor. 181 * @param[in] pRegWriteList pointer to the register list. 182 * @constraints This can be called any number of times only after FXOS8700_SPI_Initialize(). 183 * Application has to ensure that previous instances of these APIs have exited before invocation. 184 * @reeentrant No 185 * @return ::FXOS8700_SPI_Configure() returns the status . 186 */ 187 int32_t FXOS8700_SPI_Configure(fxos8700_spi_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList); 188 189 /*! @brief The interface function to read the sensor data. 190 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 191 * @param[in] pSensorHandle handle to the sensor. 192 * @param[in] pReadList pointer to the list of device registers and values to read. 193 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 194 * command read in the list. 195 * @constraints This can be called any number of times only after FXOS8700_SPI_Initialize(). 196 * Application has to ensure that previous instances of these APIs have exited before invocation. 197 * @reeentrant No 198 * @return ::FXOS8700_SPI_ReadData() returns the status . 199 */ 200 int32_t FXOS8700_SPI_ReadData(fxos8700_spi_sensorhandle_t *pSensorHandle, 201 const registerreadlist_t *pReadList, 202 uint8_t *pBuffer); 203 204 /*! @brief The interface function to De Initialize sensor.. 205 * @details This function made sensor in a power safe state and de initialize its handle. 206 * @param[in] pSensorHandle handle to the sensor. 207 * @constraints This can be called only after after FXOS8700_SPI_Initialize(). 208 * Application has to ensure that previous instances of these APIs have exited before invocation. 209 * @reeentrant No 210 * @return ::FXOS8700_SPI_Deinit() returns the status. 211 */ 212 int32_t FXOS8700_SPI_Deinit(fxos8700_spi_sensorhandle_t *pSensorHandle); 213 214 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. 215 * @details This function prepares the SPI Read Command Header with register address and 216 * R/W bit encoded as the Sensor. 217 * @param[out] pCmdOut handle to the output buffer. 218 * @param[in] offset the address of the register to start reading from. 219 * @param[in] size number of bytes to read. 220 * @constraints None 221 * Application has to ensure that previous instances of these APIs have exited before invocation. 222 * @reeentrant No 223 * @return :: None. 224 */ 225 void FXOS8700_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size); 226 227 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header. 228 * @details This function prepares the SPI Write Command Header with register address and 229 * R/W bit encoded as the Sensor. 230 * @param[out] pCmdOut handle to the output buffer. 231 * @param[in] offset the address of the register to start writing from. 232 * @param[in] size number of bytes to write. 233 * @constraints None 234 * Application has to ensure that previous instances of these APIs have exited before invocation. 235 * @reeentrant No 236 * @return :: None. 237 */ 238 void FXOS8700_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer); 239 240 #endif // FXOS8700_DRV_H_ 241