sd detect pin feature (#222)

* test sd detect pin
* sd detect support for f2 board
This commit is contained in:
DrZlo13
2020-11-11 09:17:53 +03:00
committed by GitHub
parent 748f7e4fc3
commit 49fdb28871
10 changed files with 46 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
#include "api-hal-gpio.h"
#include "api-hal-resources.h"
// init GPIO
void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) {
@@ -12,3 +13,24 @@ void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed)
HAL_GPIO_Init(gpio->port, &GPIO_InitStruct);
}
bool hal_gpio_read_sd_detect(void) {
bool result = false;
// create pin
GpioPin sd_cs_pin = sd_cs_gpio;
// TODO open record
GpioPin* sd_cs_record = &sd_cs_pin;
// configure pin as input
gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
delay(50);
// 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);
delay(50);
return result;
}