2021-02-18 12:49:32 +00:00
|
|
|
#include <api-hal-gpio.h>
|
|
|
|
#include <api-hal-spi.h>
|
|
|
|
#include <api-hal-resources.h>
|
|
|
|
#include <api-hal-delay.h>
|
2020-11-06 10:52:50 +00:00
|
|
|
|
|
|
|
// init GPIO
|
2020-11-19 12:25:32 +00:00
|
|
|
void hal_gpio_init(
|
|
|
|
const GpioPin* gpio,
|
|
|
|
const GpioMode mode,
|
|
|
|
const GpioPull pull,
|
|
|
|
const GpioSpeed speed) {
|
2020-11-06 10:52:50 +00:00
|
|
|
// TODO: Alternate Functions
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
|
|
|
|
GPIO_InitStruct.Pin = gpio->pin;
|
|
|
|
GPIO_InitStruct.Mode = mode;
|
|
|
|
GPIO_InitStruct.Pull = pull;
|
|
|
|
GPIO_InitStruct.Speed = speed;
|
|
|
|
|
|
|
|
HAL_GPIO_Init(gpio->port, &GPIO_InitStruct);
|
|
|
|
}
|
2020-11-11 06:17:53 +00:00
|
|
|
|
|
|
|
bool hal_gpio_read_sd_detect(void) {
|
|
|
|
bool result = false;
|
2021-01-11 14:52:35 +00:00
|
|
|
|
2020-11-11 06:17:53 +00:00
|
|
|
// TODO open record
|
2020-11-19 12:25:32 +00:00
|
|
|
const GpioPin* sd_cs_record = &sd_cs_gpio;
|
2020-11-11 06:17:53 +00:00
|
|
|
|
2021-01-11 14:52:35 +00:00
|
|
|
// TODO: SPI manager
|
2021-01-12 17:33:36 +00:00
|
|
|
api_hal_spi_lock(sd_fast_spi.spi);
|
2021-01-11 14:52:35 +00:00
|
|
|
|
2020-11-11 06:17:53 +00:00
|
|
|
// configure pin as input
|
|
|
|
gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
|
2021-01-11 14:52:35 +00:00
|
|
|
delay(1);
|
2020-11-11 06:17:53 +00:00
|
|
|
|
|
|
|
// if gpio_read == 0 return true else return false
|
|
|
|
result = !gpio_read(sd_cs_record);
|
|
|
|
|
|
|
|
// configure pin back
|
|
|
|
gpio_init_ex(sd_cs_record, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
|
2021-01-11 14:52:35 +00:00
|
|
|
gpio_write(sd_cs_record, 1);
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// TODO: SPI manager
|
2021-01-12 17:33:36 +00:00
|
|
|
api_hal_spi_unlock(sd_fast_spi.spi);
|
2020-11-11 06:17:53 +00:00
|
|
|
|
|
|
|
return result;
|
2020-12-01 18:47:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void enable_cc1101_irq() {
|
|
|
|
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
|
|
|
|
}
|