2021-06-04 16:34:38 +02:00
|
|
|
#include "spiInterrupts.h"
|
2021-06-10 19:09:33 +02:00
|
|
|
#include "spiCore.h"
|
2021-06-03 15:12:34 +02:00
|
|
|
|
2021-06-04 15:50:02 +02:00
|
|
|
#include "stm32h7xx_hal.h"
|
|
|
|
#include "stm32h7xx_hal_dma.h"
|
|
|
|
#include "stm32h7xx_hal_spi.h"
|
|
|
|
|
2021-06-03 15:12:34 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2021-06-10 19:09:33 +02:00
|
|
|
user_handler_t spi1UserHandler = &spi::spiIrqHandler;
|
2021-06-05 13:29:43 +02:00
|
|
|
user_args_t spi1UserArgs = nullptr;
|
2021-06-04 15:50:02 +02:00
|
|
|
|
2021-06-10 19:09:33 +02:00
|
|
|
user_handler_t spi2UserHandler = &spi::spiIrqHandler;
|
2021-06-05 13:29:43 +02:00
|
|
|
user_args_t spi2UserArgs = nullptr;
|
2021-06-04 15:50:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function handles DMA Rx interrupt request.
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
2021-06-05 13:29:43 +02:00
|
|
|
void spi::dmaRxIrqHandler(void* dmaHandle) {
|
2021-06-10 21:31:21 +02:00
|
|
|
if(dmaHandle == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-05 13:29:43 +02:00
|
|
|
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dmaHandle);
|
2021-06-04 15:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function handles DMA Rx interrupt request.
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
2021-06-05 13:29:43 +02:00
|
|
|
void spi::dmaTxIrqHandler(void* dmaHandle) {
|
2021-06-10 21:31:21 +02:00
|
|
|
if(dmaHandle == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-05 13:29:43 +02:00
|
|
|
HAL_DMA_IRQHandler((DMA_HandleTypeDef *) dmaHandle);
|
2021-06-04 15:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function handles SPIx interrupt request.
|
|
|
|
* @param None
|
|
|
|
* @retval None
|
|
|
|
*/
|
2021-06-10 19:09:33 +02:00
|
|
|
void spi::spiIrqHandler(void* spiHandle)
|
2021-06-04 15:50:02 +02:00
|
|
|
{
|
2021-06-10 21:31:21 +02:00
|
|
|
if(spiHandle == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//auto currentSpiHandle = spi::getSpiHandle();
|
|
|
|
HAL_SPI_IRQHandler((SPI_HandleTypeDef *) spiHandle);
|
2021-06-04 15:50:02 +02:00
|
|
|
}
|
|
|
|
|
2021-06-05 13:29:43 +02:00
|
|
|
void spi::assignSpiUserHandler(spi::SpiBus spiIdx, user_handler_t userHandler,
|
|
|
|
user_args_t userArgs) {
|
|
|
|
if(spiIdx == spi::SpiBus::SPI_1) {
|
|
|
|
spi1UserHandler = userHandler;
|
|
|
|
spi1UserArgs = userArgs;
|
2021-06-04 16:34:38 +02:00
|
|
|
}
|
|
|
|
else {
|
2021-06-05 13:29:43 +02:00
|
|
|
spi2UserHandler = userHandler;
|
|
|
|
spi2UserArgs = userArgs;
|
2021-06-04 16:34:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-10 19:09:33 +02:00
|
|
|
void spi::getSpiUserHandler(spi::SpiBus spiBus, user_handler_t *userHandler,
|
|
|
|
user_args_t *userArgs) {
|
|
|
|
if(userHandler == nullptr or userArgs == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(spiBus == spi::SpiBus::SPI_1) {
|
|
|
|
*userArgs = spi1UserArgs;
|
|
|
|
*userHandler = spi1UserHandler;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*userArgs = spi2UserArgs;
|
|
|
|
*userHandler = spi2UserHandler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-10 21:31:21 +02:00
|
|
|
void spi::assignSpiUserArgs(spi::SpiBus spiBus, user_args_t userArgs) {
|
2021-06-10 19:09:33 +02:00
|
|
|
if(spiBus == spi::SpiBus::SPI_1) {
|
|
|
|
spi1UserArgs = userArgs;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spi2UserArgs = userArgs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:34:38 +02:00
|
|
|
/* Do not change these function names! They need to be exactly equal to the name of the functions
|
|
|
|
defined in the startup_stm32h743xx.s files! */
|
|
|
|
|
|
|
|
extern "C" void SPI1_IRQHandler() {
|
2021-06-05 13:29:43 +02:00
|
|
|
if(spi1UserHandler != NULL) {
|
|
|
|
spi1UserHandler(spi1UserArgs);
|
2021-06-04 16:34:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Default_Handler();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void SPI2_IRQHandler() {
|
2021-06-05 13:29:43 +02:00
|
|
|
if(spi2UserHandler != nullptr) {
|
|
|
|
spi2UserHandler(spi2UserArgs);
|
2021-06-04 16:34:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Default_Handler();
|
|
|
|
}
|