1 /* 2 * Copyright 2018-2021 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __HAL_SPI_ADAPTER_H__ 10 #define __HAL_SPI_ADAPTER_H__ 11 12 #include "fsl_common.h" 13 /*! 14 * @addtogroup SPI_Adapter 15 * @{ 16 */ 17 18 /******************************************************************************* 19 * Definitions 20 ******************************************************************************/ 21 /*! @brief Enable or disable Slave SPI DMA adapter mode (1 - enable, 0 - disable) */ 22 #ifndef HAL_SPI_SLAVE_DMA_ENABLE 23 #define HAL_SPI_SLAVE_DMA_ENABLE (0U) 24 #endif /* HAL_SPI_SLAVE_DMA_ENABLE */ 25 26 /*! @brief Enable or disable master SPI DMA adapter mode (1 - enable, 0 - disable) */ 27 #ifndef HAL_SPI_MASTER_DMA_ENABLE 28 #define HAL_SPI_MASTER_DMA_ENABLE (0U) 29 #endif /* HAL_SPI_SLAVE_DMA_ENABLE */ 30 31 /*! @brief Enable or disable slave SPI DMA adapter int mode (1 - enable, 0 - disable) */ 32 #ifndef HAL_SPI_SLAVE_DMA_INIT_ENABLE 33 #define HAL_SPI_SLAVE_DMA_INIT_ENABLE (0U) 34 #endif /* HAL_SPI_SLAVE_DMA_INIT_ENABLE */ 35 36 /*! @brief Enable or disable master SPI DMA adapter int mode (1 - enable, 0 - disable) */ 37 #ifndef HAL_SPI_MASTER_DMA_INIT_ENABLE 38 #define HAL_SPI_MASTER_DMA_INIT_ENABLE (0U) 39 #endif /* HAL_SPI_MASTER_DMA_INIT_ENABLE */ 40 41 /*! @brief spi master handle size.*/ 42 #define HAL_SPI_MASTER_HANDLE_SIZE (80U) 43 44 /*! @brief spi slave handle size.*/ 45 #define HAL_SPI_SLAVE_HANDLE_SIZE (80U) 46 47 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U)) 48 /*! @brief spi master handle size.*/ 49 #define HAL_SPI_SLAVE_DMA_HANDLE_SIZE (192U) 50 /*! 51 * @brief Defines the SPI slave handle 52 * 53 * This macro is used to define the SPI slave handle. 54 * Then use "(hal_spi_slave_handle_t)name" to get the SPI slave handle. 55 * 56 * The macro should be global and could be optional. You could also define SPI slave handle by yourself. 57 * 58 * This is an example, 59 * @code 60 * HAL_SPI_SLAVE_HANDLE_DEFINE(spiMasterHandle); 61 * @endcode 62 * 63 * @param name The name string of the SPI slave handle. 64 */ 65 #define HAL_SPI_SLAVE_DMA_HANDLE_DEFINE(name) \ 66 uint32_t name[(HAL_SPI_SLAVE_DMA_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 67 68 typedef void *hal_spi_slave_dma_handle_t; 69 70 #endif 71 72 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U)) 73 /*! @brief spi master handle size.*/ 74 #define HAL_SPI_MASTER_DMA_HANDLE_SIZE (224U) 75 76 /*! 77 * @brief Defines the SPI master handle 78 * 79 * This macro is used to define the SPI master handle. 80 * Then use "(hal_spi_master_handle_t)name" to get the SPI master handle. 81 * 82 * The macro should be global and could be optional. You could also define SPI master handle by yourself. 83 * 84 * This is an example, 85 * @code 86 * HAL_SPI_MASTER_HANDLE_DEFINE(spiMasterHandle); 87 * @endcode 88 * 89 * @param name The name string of the SPI master handle. 90 */ 91 #define HAL_SPI_MASTER_DMA_HANDLE_DEFINE(name) \ 92 uint32_t name[(HAL_SPI_MASTER_DMA_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 93 94 typedef void *hal_spi_master_dma_handle_t; 95 96 #endif 97 98 /*! @brief Return status for the spi driver.*/ 99 typedef enum _hal_spi_status 100 { 101 kStatus_HAL_SpiSuccess = kStatus_Success, /*!< Successfully */ 102 kStatus_HAL_SpiError = MAKE_STATUS(kStatusGroup_HAL_SPI, 1), /*!< spi error */ 103 kStatus_HAL_SpiBusy = MAKE_STATUS(kStatusGroup_HAL_SPI, 2), /*!< spi bus is busy */ 104 kStatus_HAL_SpiIdle = MAKE_STATUS(kStatusGroup_HAL_SPI, 3), /*!< spi is idle */ 105 } hal_spi_status_t; 106 107 /*! @brief spi clock polarity configuration.*/ 108 typedef enum _hal_spi_clock_polarity 109 { 110 kHAL_SpiClockPolarityActiveHigh = 0x0U, /*!< Active-high spi clock (idles low). */ 111 kHAL_SpiClockPolarityActiveLow /*!< Active-low spi clock (idles high). */ 112 } hal_spi_clock_polarity_t; 113 114 /*! @brief spi clock phase configuration.*/ 115 typedef enum _hal_spi_clock_phase 116 { 117 kHAL_SpiClockPhaseFirstEdge = 0x0U, /*!< First edge on SPSCK occurs at the middle of the first 118 * cycle of a data transfer. */ 119 kHAL_SpiClockPhaseSecondEdge /*!< First edge on SPSCK occurs at the start of the 120 * first cycle of a data transfer. */ 121 } hal_spi_clock_phase_t; 122 123 /*! @brief spi data shifter direction options.*/ 124 typedef enum _hal_spi_shift_direction 125 { 126 kHAL_SpiMsbFirst = 0x0U, /*!< Data transfers start with most significant bit. */ 127 kHAL_SpiLsbFirst /*!< Data transfers start with least significant bit. */ 128 } hal_spi_shift_direction_t; 129 130 /*! @brief spi master user configure structure.*/ 131 typedef struct _hal_spi_master_config 132 { 133 uint32_t srcClock_Hz; /*!< Clock source for spi in Hz */ 134 uint32_t baudRate_Bps; /*!< Baud Rate for spi in Hz */ 135 hal_spi_clock_polarity_t polarity; /*!< Clock polarity */ 136 hal_spi_clock_phase_t phase; /*!< Clock phase */ 137 hal_spi_shift_direction_t direction; /*!< MSB or LSB */ 138 uint8_t instance; /*!< Instance of the spi */ 139 bool enableMaster; /*!< Enable spi at initialization time */ 140 } hal_spi_master_config_t; 141 142 /*! @brief spi slave user configure structure.*/ 143 typedef struct _hal_spi_slave_config 144 { 145 hal_spi_clock_polarity_t polarity; /*!< Clock polarity */ 146 hal_spi_clock_phase_t phase; /*!< Clock phase */ 147 hal_spi_shift_direction_t direction; /*!< MSB or LSB */ 148 uint8_t instance; /*!< Instance of the spi */ 149 bool enableSlave; /*!< Enable spi at initialization time */ 150 } hal_spi_slave_config_t; 151 152 /*! @brief spi transfer structure */ 153 typedef struct _hal_spi_transfer 154 { 155 uint8_t *txData; /*!< Send buffer */ 156 uint8_t *rxData; /*!< Receive buffer */ 157 size_t dataSize; /*!< Transfer bytes */ 158 uint32_t flags; /*!< spi control flag.*/ 159 } hal_spi_transfer_t; 160 161 /*! @brief spi master handle.*/ 162 typedef void *hal_spi_master_handle_t; 163 164 /*! @brief spi slave handle.*/ 165 typedef void *hal_spi_slave_handle_t; 166 167 /*! 168 * @brief Defines the SPI master handle 169 * 170 * This macro is used to define the SPI master handle. 171 * Then use "(hal_spi_master_handle_t)name" to get the SPI master handle. 172 * 173 * The macro should be global and could be optional. You could also define SPI master handle by yourself. 174 * 175 * This is an example, 176 * @code 177 * HAL_SPI_MASTER_HANDLE_DEFINE(spiMasterHandle); 178 * @endcode 179 * 180 * @param name The name string of the SPI master handle. 181 */ 182 #define HAL_SPI_MASTER_HANDLE_DEFINE(name) \ 183 uint32_t name[(HAL_SPI_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 184 185 /*! 186 * @brief Defines the SPI slave handle 187 * 188 * This macro is used to define the SPI slave handle. 189 * Then use "(hal_spi_slave_handle_t)name" to get the SPI slave handle. 190 * 191 * The macro should be global and could be optional. You could also define SPI slave handle by yourself. 192 * 193 * This is an example, 194 * @code 195 * HAL_SPI_SLAVE_HANDLE_DEFINE(spiSlaveHandle); 196 * @endcode 197 * 198 * @param name The name string of the SPI slave handle. 199 */ 200 #define HAL_SPI_SLAVE_HANDLE_DEFINE(name) \ 201 uint32_t name[(HAL_SPI_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t)] 202 203 /*! @brief spi master callback for finished transmit */ 204 typedef void (*hal_spi_master_transfer_callback_t)(hal_spi_master_handle_t handle, 205 hal_spi_status_t status, 206 void *callbackParam); 207 208 /*! @brief spi slave callback for finished transmit */ 209 typedef void (*hal_spi_slave_transfer_callback_t)(hal_spi_slave_handle_t handle, 210 hal_spi_status_t status, 211 void *callbackParam); 212 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U)) || \ 213 (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U)) 214 typedef struct _dma_mux_configure_t 215 { 216 union 217 { 218 struct 219 { 220 uint8_t dma_mux_instance; 221 uint32_t rx_request; 222 uint32_t tx_request; 223 } dma_dmamux_configure; 224 }; 225 } dma_mux_configure_t; 226 typedef struct _dma_channel_mux_configure_t 227 { 228 union 229 { 230 struct 231 { 232 uint32_t dma_rx_channel_mux; 233 uint32_t dma_tx_channel_mux; 234 } dma_dmamux_configure; 235 }; 236 } dma_channel_mux_configure_t; 237 238 typedef struct _hal_spi_dma_config_t 239 { 240 uint8_t spi_instance; 241 uint8_t dma_instance; 242 uint8_t rx_channel; 243 uint8_t tx_channel; 244 void *dma_mux_configure; 245 void *dma_channel_mux_configure; 246 } hal_spi_dma_config_t; 247 #endif /* HAL_SPI_SLAVET_DMA_ENABLE */ 248 249 #if defined(__cplusplus) 250 extern "C" { 251 #endif 252 253 /******************************************************************************* 254 * APIs 255 ******************************************************************************/ 256 /*! 257 * @name Initialization and de-initialization 258 * @{ 259 */ 260 261 /*! 262 * @brief Initializes the spi with master configuration. 263 * 264 * This function configures the spi master with user-defined settings. The user can configure the configuration 265 * structure. The parameter handle is a pointer to point to a memory space of size #HAL_SPI_MASTER_HANDLE_SIZE 266 * allocated by the caller. 267 * 268 * Example below shows how to use this API to configure the SPI master. 269 * @code 270 * HAL_SPI_MASTER_HANDLE_DEFINE(masterHandle); 271 * hal_spi_master_config_t userConfig; 272 * userConfig.polarity = kHAL_SpiClockPolarityActiveHigh; 273 * userConfig.phase = kHAL_SpiClockPhaseFirstEdge; 274 * userConfig.direction = kHAL_SpiMsbFirst; 275 * userConfig.baudRate_Bps = 500000U; 276 * userConfig.enableMaster = true; 277 * userConfig.srcClock_Hz = 48000000; 278 * userConfig.instance = 0; 279 * HAL_SpiMasterInit((hal_spi_master_handle_t)masterHandle, &userConfig); 280 * @endcode 281 * 282 * @param handle Pointer to point to a memory space of size #HAL_SPI_MASTER_HANDLE_SIZE allocated by the caller. 283 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 284 * You can define the handle in the following two ways: 285 * #HAL_SPI_MASTER_HANDLE_DEFINE(handle); 286 * or 287 * uint32_t handle[((HAL_SPI_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 288 * @param config pointer to master configuration structure 289 * @retval kStatus_HAL_SpiError An error occurred. 290 * @retval kStatus_HAL_SpiSuccess spi master initialization succeed 291 * 292 */ 293 hal_spi_status_t HAL_SpiMasterInit(hal_spi_master_handle_t handle, const hal_spi_master_config_t *config); 294 295 /*! 296 * @brief Initializes the spi with slave configuration. 297 * 298 * This function configures the spi slave with user-defined settings. The user can configure the configuration 299 * structure. The parameter handle is a pointer to point to a memory space of size #HAL_SPI_SLAVE_HANDLE_SIZE 300 * allocated by the caller. 301 * After calling this API, the slave is ready to transfer. 302 * 303 * Example below shows how to use this API to configure the SPI slave. 304 * @code 305 * HAL_SPI_MASTER_HANDLE_DEFINE(slaveHandle); 306 * hal_spi_slave_config_t userConfig; 307 * userConfig.polarity = kHAL_SpiClockPolarityActiveHigh; 308 * userConfig.phase = kHAL_SpiClockPhaseFirstEdge; 309 * userConfig.direction = kHAL_SpiMsbFirst; 310 * userConfig.instance = 0; 311 * userConfig.enableSlave = true; 312 * HAL_SpiSlaveInit((hal_spi_slave_handle_t)slaveHandle, &userConfig); 313 * @endcode 314 * 315 * @param handle Pointer to point to a memory space of size #HAL_SPI_SLAVE_HANDLE_SIZE allocated by the caller. 316 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 317 * You can define the handle in the following two ways: 318 * #HAL_SPI_MASTER_HANDLE_DEFINE(handle); 319 * or 320 * uint32_t handle[((HAL_SPI_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 321 * @param config pointer to slave configuration structure 322 * @retval kStatus_HAL_SpiError An error occurred. 323 * @retval kStatus_HAL_SpiSuccess spi slave initialization succeed 324 */ 325 hal_spi_status_t HAL_SpiSlaveInit(hal_spi_slave_handle_t handle, const hal_spi_slave_config_t *config); 326 327 /*! 328 * @brief De-initializes the spi master. 329 * 330 * De-initializes the spi master. 331 * The spi master can't work unless calling the HAL_SpiMasterInit to initialize module. 332 * 333 * @param handle spi master handle pointer, this should be a static variable. 334 * @retval kStatus_HAL_SpiSuccess spi master de-initialization succeed 335 */ 336 hal_spi_status_t HAL_SpiMasterDeinit(hal_spi_master_handle_t handle); 337 338 /*! 339 * @brief De-initializes the spi slave. 340 * 341 * De-initializes the spi slave. 342 * The spi slave can't work unless calling the HAL_SpiSlaveInit to initialize module. 343 * 344 * @param handle spi slave handle pointer, this should be a static variable. 345 * @retval kStatus_HAL_SpiSuccess spi slave de-initialization succeed 346 */ 347 hal_spi_status_t HAL_SpiSlaveDeinit(hal_spi_slave_handle_t handle); 348 349 /*! @} */ 350 351 /*! 352 * @name Transactional 353 * @{ 354 */ 355 356 /*! 357 * @brief Installs a callback and callback parameter. 358 * 359 * This function is used to install the callback and callback parameter for spi master module. 360 * When any status of the spi master changed, the driver will notify the upper layer by the installed callback 361 * function. And the status is also passed as status parameter when the callback is called. 362 * 363 * @param handle spi master handle pointer, this should be a static variable. 364 * @param callback Callback function. 365 * @param callbackParam The parameter of the callback function. 366 * @retval kStatus_HAL_SpiSuccess spi master handle created 367 */ 368 hal_spi_status_t HAL_SpiMasterTransferInstallCallback(hal_spi_master_handle_t handle, 369 hal_spi_master_transfer_callback_t callback, 370 void *callbackParam); 371 372 /*! 373 * @brief Transfers a block of data using a polling method. 374 * 375 * @param handle spi master handle pointer, this should be a static variable. 376 * @param xfer pointer to hal_spi_transfer_t structure 377 * @retval kStatus_HAL_SpiError An error occurred. 378 * @retval kStatus_HAL_SpiSuccess Successfully sent all data. 379 */ 380 hal_spi_status_t HAL_SpiMasterTransferBlocking(hal_spi_master_handle_t handle, hal_spi_transfer_t *xfer); 381 382 /*! 383 * @brief Performs a non-blocking spi interrupt transfer. 384 * 385 * @note If spi transfer data frame size is 16 bits, the transfer size cannot be an odd number. 386 * 387 * @param handle spi master handle pointer, this should be a static variable. 388 * @param xfer pointer to hal_spi_transfer_t structure 389 * @retval kStatus_HAL_SpiError An error occurred. 390 * @retval kStatus_HAL_SpiBusy spi is not idle, is running another transfer. 391 * @retval kStatus_HAL_SpiSuccess Successfully start the data transmission. 392 */ 393 hal_spi_status_t HAL_SpiMasterTransferNonBlocking(hal_spi_master_handle_t handle, hal_spi_transfer_t *xfer); 394 395 /*! 396 * @brief Gets the bytes of the spi interrupt transferred. 397 * 398 * @param handle spi master handle pointer, this should be a static variable. 399 * @param spiCount Transferred bytes of spi master. 400 * @retval kStatus_HAL_SpiError An error occurred. 401 * @retval kStatus_HAL_SpiSuccess Succeed get the transfer count. 402 */ 403 hal_spi_status_t HAL_SpiMasterTransferGetCount(hal_spi_master_handle_t handle, size_t *spiCount); 404 405 /*! 406 * @brief Aborts an spi transfer using interrupt. 407 * 408 * @param handle spi master handle pointer, this should be a static variable. 409 * @retval kStatus_HAL_SpiSuccess Succeed abort the transfer. 410 */ 411 hal_spi_status_t HAL_SpiMasterTransferAbort(hal_spi_master_handle_t handle); 412 413 /*! 414 * @brief Installs a callback and callback parameter. 415 * 416 * This function is used to install the callback and callback parameter for spi slave module. 417 * When any status of the spi slave changed, the driver will notify the upper layer by the installed callback 418 * function. And the status is also passed as status parameter when the callback is called. 419 * 420 * @param handle spi slave handle pointer, this should be a static variable. 421 * @param callback Callback function. 422 * @param callbackParam The parameter of the callback function. 423 * @retval kStatus_HAL_SpiSuccess spi slave handle created 424 */ 425 hal_spi_status_t HAL_SpiSlaveTransferInstallCallback(hal_spi_slave_handle_t handle, 426 hal_spi_slave_transfer_callback_t callback, 427 void *callbackParam); 428 429 /*! 430 * @brief Performs a non-blocking spi slave interrupt transfer. 431 * 432 * @note If spi transfer data frame size is 16 bits, the transfer size cannot be an odd number. 433 * 434 * @param handle spi slave handle pointer, this should be a static variable. 435 * @param xfer pointer to hal_spi_xfer_config_t structure 436 * @retval kStatus_HAL_SpiSuccess Successfully start a transfer. 437 * @retval kStatus_HAL_SpiError An error occurred. 438 * @retval kStatus_HAL_SpiBusy spi is not idle, is running another transfer. 439 */ 440 hal_spi_status_t HAL_SpiSlaveTransferNonBlocking(hal_spi_slave_handle_t handle, hal_spi_transfer_t *xfer); 441 442 /*! 443 * @brief Gets the bytes of the spi interrupt transferred. 444 * 445 * @param handle spi slave handle pointer, this should be a static variable. 446 * @param spiCount Transferred bytes of spi slave. 447 * @retval kStatus_HAL_SpiSuccess Succeed get the transfer count. 448 * @retval kStatus_HAL_SpiError An error occurred. 449 */ 450 hal_spi_status_t HAL_SpiSlaveTransferGetCount(hal_spi_slave_handle_t handle, size_t *spiCount); 451 452 /*! 453 * @brief Aborts an spi slave transfer using interrupt. 454 * 455 * @param handle spi slave handle pointer, this should be a static variable. 456 * @retval kStatus_HAL_SpiSuccess Succeed abort the transfer. 457 */ 458 hal_spi_status_t HAL_SpiSlaveTransferAbort(hal_spi_slave_handle_t handle); 459 460 #if (defined(HAL_SPI_SLAVE_DMA_ENABLE) && (HAL_SPI_SLAVE_DMA_ENABLE > 0U)) 461 /*! 462 * @brief Initializes the spi with slave configuration. 463 * 464 * This function configures the spi slave with user-defined settings. The user can configure the configuration 465 * structure. The parameter handle is a pointer to point to a memory space of size #HAL_SPI_SLAVE_HANDLE_SIZE 466 * allocated by the caller. 467 * After calling this API, the slave is ready to transfer. 468 * 469 * Example below shows how to use this API to configure the SPI slave. 470 * @code 471 * HAL_SPI_MASTER_HANDLE_DEFINE(slaveHandle); 472 * hal_spi_slave_config_t userConfig; 473 * userConfig.polarity = kHAL_SpiClockPolarityActiveHigh; 474 * userConfig.phase = kHAL_SpiClockPhaseFirstEdge; 475 * userConfig.direction = kHAL_SpiMsbFirst; 476 * userConfig.instance = 0; 477 * userConfig.enableSlave = true; 478 * HAL_SpiSlaveInit((hal_spi_slave_handle_t)slaveHandle, &userConfig); 479 * Configure spi_slave dma settings 480 * hal_spi_slave_dma_config_t dmaConfig; 481 * dmaConfig.spi_slave_instance = 0; 482 * dmaConfig.dma_instance = 0; 483 * dmaConfig.rx_channel = 0; 484 * dmaConfig.tx_channel = 1; 485 * dma_mux_configure_t dma_mux; 486 * dma_mux.dma_dmamux_configure.dma_mux_instance = 0; 487 * dma_mux.dma_dmamux_configure.rx_request = kDmaRequestMuxLPSPI1Rx; 488 * dma_mux.dma_dmamux_configure.tx_request = kDmaRequestMuxLPSPI1Tx; 489 * dmaConfig.dma_mux_configure = &dma_mux; 490 * 491 * Init spi_slave dma 492 * HAL_UartDMAInit((hal_spi_slave_handle_t *)g_spi_slaveHandle, (hal_spi_slave_dma_handle_t *)g_spi_slaveDmaHandle, 493 * &dmaConfig); 494 * @endcode 495 * @endcode 496 * 497 * @param handle Pointer to point to a memory space of size #HAL_SPI_SLAVE_HANDLE_SIZE allocated by the caller. 498 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 499 * You can define the handle in the following two ways: 500 * #HAL_SPI_SLAVE_HANDLE_DEFINE(handle); 501 * or 502 * uint32_t handle[((HAL_SPI_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 503 * @param config pointer to spi slave configuration structure 504 * @retval kStatus_HAL_SpiError An error occurred. 505 * @retval kStatus_HAL_SpiSuccess spi slave initialization succeed 506 */ 507 508 hal_spi_status_t HAL_SpiSlaveDMAInit(hal_spi_slave_handle_t handle, 509 hal_spi_slave_dma_handle_t dmaHandle, 510 hal_spi_dma_config_t *dmaConfig); 511 512 /*! 513 * @brief Deinitializes a SPI DMA instance. 514 * 515 * This function will abort spi slave dma receive/send transfer and deinitialize SPI. 516 * 517 * @param handle SPI handle pointer. 518 * @retval kStatus_HAL_UartDmaSuccess SPI DMA de-initialization succeed 519 */ 520 hal_spi_status_t HAL_SpiSlaveDMADeinit(hal_spi_slave_handle_t handle); 521 #endif 522 #if (defined(HAL_SPI_MASTER_DMA_ENABLE) && (HAL_SPI_MASTER_DMA_ENABLE > 0U)) 523 /*! 524 * @brief Initializes the spi with master configuration. 525 * 526 * This function configures the spi master with user-defined settings. The user can configure the configuration 527 * structure. The parameter handle is a pointer to point to a memory space of size #HAL_SPI_MASTER_HANDLE_SIZE 528 * allocated by the caller. 529 * After calling this API, the master is ready to transfer. 530 * 531 * Example below shows how to use this API to configure the SPI master. 532 * @code 533 * HAL_SPI_MASTER_HANDLE_DEFINE(masterHandle); 534 * hal_spi_master_config_t userConfig; 535 * userConfig.polarity = kHAL_SpiClockPolarityActiveHigh; 536 * userConfig.phase = kHAL_SpiClockPhaseFirstEdge; 537 * userConfig.direction = kHAL_SpiMsbFirst; 538 * userConfig.instance = 0; 539 * userConfig.enableMastere = true; 540 * HAL_SpiMastereInit((hal_spi_master_handle_t)masterHandle, &userConfig); 541 * Configure spi_master dma settings 542 * hal_spi_master_dma_config_t dmaConfig; 543 * dmaConfig.spi_master_instance = 0; 544 * dmaConfig.dma_instance = 0; 545 * dmaConfig.rx_channel = 0; 546 * dmaConfig.tx_channel = 1; 547 * dma_mux_configure_t dma_mux; 548 * dma_mux.dma_dmamux_configure.dma_mux_instance = 0; 549 * dma_mux.dma_dmamux_configure.rx_request = kDmaRequestMuxLPSPI1Rx; 550 * dma_mux.dma_dmamux_configure.tx_request = kDmaRequestMuxLPSPI1Tx; 551 * dmaConfig.dma_mux_configure = &dma_mux; 552 * 553 * Init spi_master dma 554 * HAL_SpiMasterDMAInit((hal_spi_master_handle_t *)g_spi_masterHandle, (hal_spi_master_dma_handle_t 555 * *)g_spi_masterDmaHandle, &dmaConfig); 556 * @endcode 557 * @endcode 558 * 559 * @param handle Pointer to point to a memory space of size #HAL_SPI_MASTER_HANDLE_SIZE allocated by the caller. 560 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 561 * You can define the handle in the following two ways: 562 * #HAL_SPI_MASTER_HANDLE_DEFINE(handle); 563 * or 564 * uint32_t handle[((HAL_SPI_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 565 * @param config pointer to master configuration structure 566 * @retval kStatus_HAL_SpiError An error occurred. 567 * @retval kStatus_HAL_SpiSuccess spi master initialization succeed 568 */ 569 570 hal_spi_status_t HAL_SpiMasterDMAInit(hal_spi_master_handle_t handle, 571 hal_spi_master_dma_handle_t dmaHandle, 572 hal_spi_dma_config_t *dmaConfig); 573 574 /*! 575 * @brief Deinitializes a SPI DMA instance. 576 * 577 * This function will abort spi_master dma receive/send transfer and deinitialize SPI. 578 * 579 * @param handle SPI handle pointer. 580 * @retval kStatus_HAL_UartDmaSuccess SPI DMA de-initialization succeed 581 */ 582 hal_spi_status_t HAL_SpiMasterDMADeinit(hal_spi_master_handle_t handle); 583 #endif 584 585 /*! @} */ 586 587 #if defined(__cplusplus) 588 } 589 #endif 590 591 /*! @} */ 592 593 #endif /* __HAL_SPI_ADAPTER_H__ */ 594