1 /* 2 * Copyright (c) 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 fxlc95000_drv.h 11 * @brief The fxlc95000_drv.h file describes the FXLC95000L driver interface and structures. 12 */ 13 14 #ifndef MMA9553_DRV_H_ 15 #define MMA9553_DRV_H_ 16 17 /* Standard C Includes */ 18 #include <stdint.h> 19 20 /* ISSDK Includes */ 21 #include "fxlc95000.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 } fxlc95000_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 } fxlc95000_i2c_sensorhandle_t; 51 52 /*! @brief This structure defines the fxlc95000 pedometer data buffer. */ 53 typedef struct 54 { 55 uint32_t timestamp; /*! The time, this sample was recorded. */ 56 int16_t accel[3]; /*! The raw accel data */ 57 } fxlc95000_acceldata_t; 58 59 /*! @def FXLC95000_COCO_ERROR_MASK 60 * @brief The Error Bit Mask in COCO Byte. */ 61 #define FXLC95000_COCO_ERROR_MASK (0x7F) 62 63 /*! @def FXLC95000_SPI_MAX_MSG_SIZE 64 * @brief The MAX size of SPI message. */ 65 #define FXLC95000_SPI_MAX_MSG_SIZE (64) 66 67 /*! @def FXLC95000_SPI_CMD_LEN 68 * @brief The size of the Sensor specific SPI Header. */ 69 #define FXLC95000_SPI_CMD_LEN (1) 70 71 /*! @def FXLC95000_SS_ACTIVE_VALUE 72 * @brief Is the Slave Select Pin Active Low or High. */ 73 #define FXLC95000_SS_ACTIVE_VALUE SPI_SS_ACTIVE_LOW 74 75 /*! @def FXLC95000_ROM_CI_WRITE_MIN_LEN 76 * @brief The MIN Length of ROM CI_WRITE Data. */ 77 #define FXLC95000_ROM_CI_WRITE_MIN_LEN 4 78 79 /*! @def FXLC95000_ROM_CI_WRITE_MAX_LEN 80 * @brief The MAX Length of ROM CI_WRITE Data. */ 81 #define FXLC95000_ROM_CI_WRITE_MAX_LEN 24 82 83 /*! @def FXLC95000_ROM_CI_READ_WRITE_MAX_LEN 84 * @brief The MAX Length of ROM CI_READ_WRITE Command. */ 85 #define FXLC95000_ROM_CI_READ_WRITE_MAX_LEN 32 86 87 /*! @def FXLC95000_ROM_CI_READ_WRITE_HDR_LEN 88 * @brief The Length of ROM CI_READ_WRITE Command Header. */ 89 #define FXLC95000_ROM_CI_READ_WRITE_HDR_LEN 6 90 91 /*! @def FXLC95000_ROM_CI_READ_WRITE_ADDR_LEN 92 * @brief The Length of Address field in ROM CI_READ_WRITE Command Header. */ 93 #define FXLC95000_ROM_CI_READ_WRITE_ADDR_LEN 2 94 95 /*! @def FXLC95000_FLASH_PAYLOAD_ADDR_LEN 96 * @brief The Length of Address field in FLASH Payload form Host. */ 97 #define FXLC95000_FLASH_PAYLOAD_ADDR_LEN 4 98 99 /******************************************************************************* 100 * APIs 101 ******************************************************************************/ 102 /*! @brief The interface function to check if the sensor is in ROM CI Mode. 103 * @details This function checks the Response of Version Info command to determine if Sensor is in ROM CI Mode. 104 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 105 * @param[in] index the I2C device number. 106 * @param[in] sAddress slave address of the device on the bus. 107 * @constraints This can be called any time. 108 * Application has to ensure that previous instances of these APIs have exited before invocation. 109 * @reeentrant No 110 * @return ::FXLC95000_I2C_CheckRomMode() returns the status. 111 */ 112 int32_t FXLC95000_I2C_CheckRomMode(ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress); 113 114 /*! @brief The interface function to write ROM CI Commands. 115 * @details This function Writes ROM CI commands over I2C to the Sensor. 116 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 117 * @param[in] index the I2C device number. 118 * @param[in] sAddress slave address of the device on the bus. 119 * @param[in] pCommandList pointer to the command read list. 120 * @constraints This can be called only if Sensor is in ROM CI Mode. 121 * Application has to ensure that previous instances of these APIs have exited before invocation. 122 * @reeentrant No 123 * @return ::FXLC95000_I2C_FlashCommands() returns the status. 124 */ 125 int32_t FXLC95000_I2C_FlashCommands(ARM_DRIVER_I2C *pBus, 126 uint8_t index, 127 uint16_t sAddress, 128 const registercommandlist_t *pCommandList); 129 130 /*! @brief The interface function to write ROM CI Data Payload. 131 * @details This function Writes ROM CI Payload Bytes by creating formatted Commands and writing over I2C to the 132 * Sensor. 133 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 134 * @param[in] index the I2C device number. 135 * @param[in] sAddress slave address of the device on the bus. 136 * @param[in] pFlashBytes pointer to payload bytes of flash data. 137 * @param[in] numBytes the number of bytes of flash data to be written. 138 * @constraints This can be called only if Sensor is in ROM CI Mode. 139 * Application has to ensure that previous instances of these APIs have exited before invocation. 140 * @reeentrant No 141 * @return ::FXLC95000_I2C_FlashPayload() returns the status. 142 */ 143 int32_t FXLC95000_I2C_FlashPayload( 144 ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *pFlashBytes, uint8_t numBytes); 145 146 /*! @brief The interface function to initialize the sensor. 147 * @details This function initialize the sensor and sensor handle. 148 * @param[in] pSensorHandle handle to the sensor. 149 * @param[in] pBus pointer to the CMSIS API compatible I2C bus object. 150 * @param[in] index the I2C device number. 151 * @param[in] sAddress slave address of the device on the bus. 152 * @param[in] buildId FXLC95000 firmware buid number. 153 * @constraints This should be the first API to be called. 154 * Application has to ensure that previous instances of these APIs have exited before invocation. 155 * @reeentrant No 156 * @return ::FXLC95000_I2C_Initialize() returns the status . 157 */ 158 int32_t FXLC95000_I2C_Initialize(fxlc95000_i2c_sensorhandle_t *pSensorHandle, 159 ARM_DRIVER_I2C *pBus, 160 uint8_t index, 161 uint16_t sAddress, 162 uint16_t buildId); 163 164 /*! @brief : The interface function to set the I2C Idle Task. 165 * @param[in] : fxlc95000_i2c_sensorhandle_t *pSensorHandle, handle to the sensor handle. 166 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on I2C Idle Time. 167 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 168 * @return void. 169 * @constraints This can be called any number of times only after FXLC95000_I2C_Initialize(). 170 * Application has to ensure that previous instances of these APIs have exited before invocation. 171 * @reeentrant No 172 */ 173 void FXLC95000_I2C_SetIdleTask(fxlc95000_i2c_sensorhandle_t *pSensorHandle, 174 registeridlefunction_t idleTask, 175 void *userParam); 176 177 /*! @brief The interface function to read the sensor data. 178 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 179 * @param[in] pSensorHandle handle to the sensor. 180 * @param[in] pCommandList pointer to the command read list. 181 * @param[in] pReadList pointer to the list of device registers and values to read. 182 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 183 * command read in the list. 184 * @constraints This can be called any number of times only after FXLC95000_I2C_Initialize(). 185 * Application has to ensure that previous instances of these APIs have exited before invocation. 186 * @reeentrant No 187 * @return ::FXLC95000_I2C_CommandResponse() returns the status . 188 */ 189 int32_t FXLC95000_I2C_CommandResponse(fxlc95000_i2c_sensorhandle_t *pSensorHandle, 190 const registercommandlist_t *pCommandList, 191 const registerreadlist_t *pReadList, 192 uint8_t *pBuffer); 193 194 /*! @brief The interface function to initialize the sensor. 195 * @details This function initializes the sensor and sensor handle. 196 * @param[in] pSensorHandle handle to the sensor. 197 * @param[in] pBus pointer to the CMSIS API compatible SPI bus object. 198 * @param[in] index the I2C device number. 199 * @param[in] pSlaveSelect slave select hndle of the device on the bus. 200 * @param[in] pReset reset handle of the device on the bus. 201 * @param[in] buildId FXLC95000 firmware buid number. 202 * @constraints This should be the first API to be called. 203 * Application has to ensure that previous instances of these APIs have exited before invocation. 204 * @reeentrant No 205 * @return ::FXLC95000_SPI_Initialize() returns the status . 206 */ 207 int32_t FXLC95000_SPI_Initialize(fxlc95000_spi_sensorhandle_t *pSensorHandle, 208 ARM_DRIVER_SPI *pBus, 209 uint8_t index, 210 void *pSpiSelect, 211 void *pSlaveSelect, 212 void *pReset, 213 uint16_t buildId); 214 215 /*! @brief : The interface function to set the SPI Idle Task. 216 * @param[in] : fxlc95000_spi_sensorhandle_t *pSensorHandle, handle to the sensor handle. 217 * @param[in] : registeridlefunction_t idleTask, function pointer to the function to execute on SPI Idle Time. 218 * @param[in] : void *userParam, the pointer to the user idle ftask parameters. 219 * @return void. 220 * @constraints This can be called any number of times only after FXLC95000_SPI_Initialize(). 221 * Application has to ensure that previous instances of these APIs have exited before invocation. 222 * @reeentrant No 223 */ 224 void FXLC95000_SPI_SetIdleTask(fxlc95000_spi_sensorhandle_t *pSensorHandle, 225 registeridlefunction_t idleTask, 226 void *userParam); 227 228 /*! @brief The interface function to read the sensor data. 229 * @details This function read the sensor data out from the device and returns raw data in a byte stream. 230 * @param[in] pSensorHandle handle to the sensor. 231 * @param[in] pCommandList pointer to the command read list. 232 * @param[in] pReadList pointer to the list of device registers and values to read. 233 * @param[out] pBuffer buffer which holds raw sensor data.This buffer may be back to back databuffer based 234 * command read in the list. 235 * @constraints This can be called any number of times only after FXLC95000_SPI_Initialize(). 236 * Application has to ensure that previous instances of these APIs have exited before invocation. 237 * @reeentrant No 238 * @return ::FXLC95000_SPI_CommandResponse() returns the status . 239 */ 240 int32_t FXLC95000_SPI_CommandResponse(fxlc95000_spi_sensorhandle_t *pSensorHandle, 241 const registercommandlist_t *pCommandList, 242 const registerreadlist_t *pReadList, 243 uint8_t *pBuffer); 244 245 /*! @brief The SPI Read Pre-Process function to generate Sensor specific SPI Message Header. 246 * @details This function prepares the SPI Read Command Header with register address and 247 * R/W bit encoded as the Sensor. 248 * @param[out] pCmdOut handle to the output buffer. 249 * @param[in] offset the address of the register to start reading from. 250 * @param[in] size number of bytes to read. 251 * @constraints None 252 * Application has to ensure that previous instances of these APIs have exited before invocation. 253 * @reeentrant No 254 * @return :: None. 255 */ 256 void FXLC95000_SPI_ReadPreprocess(void *pCmdOut, uint32_t offset, uint32_t size); 257 258 /*! @brief The SPI Write Pre-Process function to generate Sensor specific SPI Message Header. 259 * @details This function prepares the SPI Write Command Header with register address and 260 * R/W bit encoded as the Sensor. 261 * @param[out] pCmdOut handle to the output buffer. 262 * @param[in] offset the address of the register to start writing from. 263 * @param[in] size number of bytes to write. 264 * @constraints None 265 * Application has to ensure that previous instances of these APIs have exited before invocation. 266 * @reeentrant No 267 * @return :: None. 268 */ 269 void FXLC95000_SPI_WritePreprocess(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer); 270 271 #endif // FXLC95000_DRV_H_ 272