FL-443 Move sd card to second spi (#271)

* sd card spi 2 fix, add spi mgr
This commit is contained in:
DrZlo13
2020-12-19 17:52:17 +10:00
committed by GitHub
parent 73ecc7cde6
commit 8b6e7fd4ae
10 changed files with 127 additions and 42 deletions

View File

@@ -0,0 +1,32 @@
#include "api-hal-spi.h"
osMutexId_t spi_mutex_r;
osMutexId_t spi_mutex_d;
extern SPI_HandleTypeDef SPI_R;
extern SPI_HandleTypeDef SPI_D;
void api_hal_spi_init() {
spi_mutex_r = osMutexNew(NULL);
spi_mutex_d = osMutexNew(NULL);
}
void api_hal_spi_lock(SPI_HandleTypeDef* spi) {
if(spi == &SPI_D) {
osMutexAcquire(spi_mutex_d, osWaitForever);
} else if(spi == &SPI_R) {
osMutexAcquire(spi_mutex_r, osWaitForever);
} else {
Error_Handler();
}
}
void api_hal_spi_unlock(SPI_HandleTypeDef* spi) {
if(spi == &SPI_D) {
osMutexRelease(spi_mutex_d);
} else if(spi == &SPI_R) {
osMutexRelease(spi_mutex_r);
} else {
Error_Handler();
}
}