92 lines
2.5 KiB
C++
92 lines
2.5 KiB
C++
#include "spiCore.h"
|
|
#include <cstdio>
|
|
|
|
SPI_HandleTypeDef* spiHandle = nullptr;
|
|
DMA_HandleTypeDef* hdma_tx = nullptr;
|
|
DMA_HandleTypeDef* hdma_rx = nullptr;
|
|
|
|
msp_func_t msp_init_func = nullptr;
|
|
void* msp_init_args = nullptr;
|
|
|
|
msp_func_t msp_deinit_func = nullptr;
|
|
void* msp_deinit_args = nullptr;
|
|
|
|
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;
|
|
}
|
|
|
|
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
|
|
*/
|
|
extern "C" 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
|
|
*/
|
|
extern "C" 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");
|
|
}
|
|
}
|