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 register_io_spi.h 11 * @brief The register_io_spi.h file declares low-level interface functions for reading 12 * and writing sensor registers using CMSIS APIs. 13 */ 14 15 #ifndef __REGISTER_IO_SPI_H__ 16 #define __REGISTER_IO_SPI_H__ 17 18 #include "Driver_SPI.h" 19 #include "sensor_drv.h" 20 21 #define SPI_SS_ACTIVE_LOW (ARM_SPI_SS_INACTIVE) 22 #define SPI_SS_ACTIVE_HIGH (ARM_SPI_SS_ACTIVE) 23 24 /*! Function pointer for the slave read information*/ 25 typedef void (*fpSpiReadPreprocessFn_t)(void *pCmdOut, uint32_t offset, uint32_t size); 26 /*! Function pointer for the slave write information*/ 27 typedef void (*fpSpiWritePreprocessFn_t)(void *pCmdOut, uint32_t offset, uint32_t size, void *pWritebuffer); 28 29 /*! @brief The SPI Slave Control Command Params SDK2.0 Driver. */ 30 typedef struct 31 { 32 void *pTargetSlavePinID; 33 uint8_t activeValue; 34 uint8_t cmdCode; 35 } spiControlParams_t; 36 37 /*! @brief The SPI Slave Transfer Command Params SDK2.0 Driver. */ 38 typedef struct spi_mater_SlaveCmd 39 { 40 uint32_t size; /*!< The tranfer size.*/ 41 uint8_t *pReadBuffer; /*!< The handle the readbuffer.*/ 42 uint8_t *pWriteBuffer; /*!< The handle the writecommand.*/ 43 } spiCmdParams_t; 44 45 /*! @brief This structure defines the spi slave command format. */ 46 typedef struct 47 { 48 fpSpiReadPreprocessFn_t pReadPreprocessFN; 49 fpSpiWritePreprocessFn_t pWritePreprocessFN; 50 void *pTargetSlavePinID; 51 uint8_t spiCmdLen; 52 uint8_t ssActiveValue; 53 } spiSlaveSpecificParams_t; 54 55 #if defined(SPI0) 56 /*! @brief The SPI0 device index. */ 57 #define SPI0_INDEX 0 58 59 /*! @brief Defines the SPI signal event handler. 60 * @details The Signal Event Handler function required by register_io_i2c.c. 61 * @param[in] event The SPI event that occured. 62 * @Constraints None 63 * @Reentrant Yes 64 * @return void 65 */ 66 void SPI0_SignalEvent_t(uint32_t event); 67 #endif 68 69 #if defined(SPI1) 70 /*! @brief The SPI1 device index. */ 71 #define SPI1_INDEX 1 72 73 /*! @brief Defines the SPI signal event handler. 74 * @details The Signal Event Handler function required by register_io_i2c.c. 75 * @param[in] event The SPI event that occured. 76 * @Constraints None 77 * @Reentrant Yes 78 * @return void 79 */ 80 void SPI1_SignalEvent_t(uint32_t event); 81 #endif 82 83 #if defined(SPI2) 84 /*! @brief The SPI2 device index. */ 85 #define SPI2_INDEX 2 86 87 /*! @brief Defines the SPI signal event handler. 88 * @details The Signal Event Handler function required by register_io_i2c.c. 89 * @param[in] event The SPI event that occured. 90 * @Constraints None 91 * @Reentrant Yes 92 * @return void 93 */ 94 void SPI2_SignalEvent_t(uint32_t event); 95 #endif 96 97 #if defined(SPI3) 98 /*! @brief The SPI3 device index. */ 99 #define SPI3_INDEX 3 100 101 /*! @brief Defines the SPI signal event handler. 102 * @details The Signal Event Handler function required by register_io_i2c.c. 103 * @param[in] event The SPI event that occured. 104 * @Constraints None 105 * @Reentrant Yes 106 * @return void 107 */ 108 void SPI3_SignalEvent_t(uint32_t event); 109 #endif 110 111 #if defined(SPI4) 112 /*! @brief The SPI4 device index. */ 113 #define SPI4_INDEX 4 114 115 /*! @brief Defines the SPI signal event handler. 116 * @details The Signal Event Handler function required by register_io_i2c.c. 117 * @param[in] event The SPI event that occured. 118 * @Constraints None 119 * @Reentrant Yes 120 * @return void 121 */ 122 void SPI4_SignalEvent_t(uint32_t event); 123 #endif 124 125 #if defined(SPI5) 126 /*! @brief The SPI5 device index. */ 127 #define SPI5_INDEX 5 128 129 /*! @brief Defines the SPI signal event handler. 130 * @details The Signal Event Handler function required by register_io_i2c.c. 131 * @param[in] event The SPI event that occured. 132 * @Constraints None 133 * @Reentrant Yes 134 * @return void 135 */ 136 void SPI5_SignalEvent_t(uint32_t event); 137 #endif 138 139 #if defined(SPI6) 140 /*! @brief The SPI6 device index. */ 141 #define SPI6_INDEX 6 142 143 /*! @brief Defines the SPI signal event handler. 144 * @details The Signal Event Handler function required by register_io_i2c.c. 145 * @param[in] event The SPI event that occured. 146 * @Constraints None 147 * @Reentrant Yes 148 * @return void 149 */ 150 void SPI6_SignalEvent_t(uint32_t event); 151 #endif 152 153 #if defined(SPI7) 154 /*! @brief The SPI7 device index. */ 155 #define SPI7_INDEX 7 156 157 /*! @brief Defines the SPI signal event handler. 158 * @details The Signal Event Handler function required by register_io_i2c.c. 159 * @param[in] event The SPI event that occured. 160 * @Constraints None 161 * @Reentrant Yes 162 * @return void 163 */ 164 void SPI7_SignalEvent_t(uint32_t event); 165 #endif 166 167 #if defined(SPI8) 168 /*! @brief The SPI8 device index. */ 169 #define SPI8_INDEX 8 170 171 /*! @brief Defines the SPI signal event handler. 172 * @details The Signal Event Handler function required by register_io_i2c.c. 173 * @param[in] event The SPI event that occured. 174 * @Constraints None 175 * @Reentrant Yes 176 * @return void 177 */ 178 void SPI8_SignalEvent_t(uint32_t event); 179 #endif 180 181 /*! 182 * @brief The interface function to block write to a sensor register. 183 * 184 * @param ARM_DRIVER_SPI *pCommDrv - The SPI driver to use. 185 * @param registerDeviceInfo_t *devInfo - The SPI device number and idle function. 186 * @param void *pWriteParams - the sensor's SPI slave select params. 187 * @param uint8_t offset - The register/offset to write to 188 * @param uint8_t *pBuffer - The buffer containing bytes to write. 189 * @param uint8_t bytesToWrite - A number of bytes to write. 190 * 191 * @return ARM_DRIVER_OK if success or ARM_DRIVER_ERROR if error. 192 */ 193 int32_t Register_SPI_BlockWrite(ARM_DRIVER_SPI *pCommDrv, 194 registerDeviceInfo_t *devInfo, 195 void *pWriteParams, 196 uint8_t offset, 197 const uint8_t *pBuffer, 198 uint8_t bytesToWrite); 199 200 /*! 201 * @brief The interface function to write a sensor register. 202 * 203 * @param ARM_DRIVER_SPI *pCommDrv - The SPI driver to use. 204 * @param registerDeviceInfo_t *devInfo - The SPI device number and idle function. 205 * @param void *pWriteParams - the sensor's SPI slave select params. 206 * @param uint8_t offset - The register/offset to write to 207 * @param uint8_t value - The value to write to the register 208 * @param uint8_t mask - A mask value to use when writing. 209 * A non-zero mask indicates that a read-modify-write operation should be used. 210 * where only the bits set in the mask will be updated according to the value param. 211 * @return ARM_DRIVER_OK if success or ARM_DRIVER_ERROR if error. 212 */ 213 int32_t Register_SPI_Write(ARM_DRIVER_SPI *pCommDrv, 214 registerDeviceInfo_t *devInfo, 215 void *pWriteParams, 216 uint8_t offset, 217 uint8_t value, 218 uint8_t mask); 219 220 /*! 221 * @brief The interface function to read a sensor register. 222 * 223 * @param ARM_DRIVER_SPI *pCommDrv - The SPI driver to use. 224 * @param registerDeviceInfo_t *devInfo - The SPI device number and idle function. 225 * @param void *pReadParams - the sensor's SPI slave select params. 226 * @param uint8_t offset - The register/offset to read from 227 * @param uint8_t length - The number of bytes to read 228 * @param uint8_t *pOutBuffer - The pointer to the buffer to store the register value read. 229 * 230 * @return ARM_DRIVER_OK if success or ARM_DRIVER_ERROR if error. 231 */ 232 int32_t Register_SPI_Read(ARM_DRIVER_SPI *pCommDrv, 233 registerDeviceInfo_t *devInfo, 234 void *pReadParams, 235 uint8_t offset, 236 uint8_t length, 237 uint8_t *pOutBuffer); 238 239 #endif // __REGISTER_IO_SPI_H__ 240