#include "spiCore.h" #include SPI_HandleTypeDef* spiHandle = NULL; DMA_HandleTypeDef* hdma_tx = NULL; DMA_HandleTypeDef* hdma_rx = NULL; msp_func_t msp_init_func = NULL; void* msp_init_args = NULL; msp_func_t msp_deinit_func = NULL; void* msp_deinit_args = NULL; void set_dma_handles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle) { hdma_tx = txHandle; hdma_rx = rxHandle; } void get_dma_handles(DMA_HandleTypeDef** txHandle, DMA_HandleTypeDef** rxHandle) { *txHandle = hdma_tx; *rxHandle = hdma_rx; } void assign_spi_handle(SPI_HandleTypeDef *spiHandle_) { if(spiHandle_ == NULL) { return; } spiHandle = spiHandle_; } SPI_HandleTypeDef* get_spi_handle() { return spiHandle; } /** * @brief This function handles DMA Rx interrupt request. * @param None * @retval None */ void dma_rx_irq_handler(void* dma_handle) { HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle); } /** * @brief This function handles DMA Rx interrupt request. * @param None * @retval None */ void dma_tx_irq_handler(void* dma_handle) { HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dma_handle); } /** * @brief This function handles SPIx interrupt request. * @param None * @retval None */ void spi1_irq_handler(void* spi_handle) { HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spi_handle); } void set_spi_msp_functions(msp_func_t init_func, void* init_args, msp_func_t deinit_func, void* deinit_args) { msp_init_func = init_func; msp_init_args = init_args; msp_deinit_func = deinit_func; msp_deinit_args = deinit_args; } void get_msp_init_function(msp_func_t* init_func, void **args) { if(init_func != NULL && args != NULL) { *init_func = msp_init_func; *args = msp_init_args; } } void get_msp_deinit_function(msp_func_t* deinit_func, void **args) { if(deinit_func != NULL && args != NULL) { *deinit_func = msp_deinit_func; *args = msp_deinit_args; } } /** * @brief SPI MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * - DMA configuration for transmission request by peripheral * - NVIC configuration for DMA interrupt request enable * @param hspi: SPI handle pointer * @retval None */ void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi) { if(msp_init_func != NULL) { msp_init_func(msp_init_args); } else { printf("HAL_SPI_MspInit: Please call set_msp_functions to assign SPI MSP functions\n"); } } /** * @brief SPI MSP De-Initialization * This function frees the hardware resources used in this example: * - Disable the Peripheral's clock * - Revert GPIO, DMA and NVIC configuration to their default state * @param hspi: SPI handle pointer * @retval None */ void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi) { if(msp_deinit_func != NULL) { msp_deinit_func(msp_deinit_args); } else { printf("HAL_SPI_MspDeInit: Please call set_msp_functions to assign SPI MSP functions\n"); } }