2021-03-09 11:53:33 +00:00
|
|
|
#include <api-hal-sd.h>
|
|
|
|
#include <api-hal-spi.h>
|
|
|
|
#include <api-hal-resources.h>
|
|
|
|
#include <api-hal-delay.h>
|
|
|
|
#include <furi.h>
|
|
|
|
|
|
|
|
void hal_sd_detect_init(void) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
void hal_sd_detect_set_low(void) {
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hal_sd_detect(void) {
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
// TODO open record
|
2021-03-31 17:52:26 +00:00
|
|
|
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSdCard);
|
2021-03-09 11:53:33 +00:00
|
|
|
|
|
|
|
// configure pin as input
|
2021-03-31 17:52:26 +00:00
|
|
|
gpio_init_ex(device->chip_select, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
|
2021-03-09 11:53:33 +00:00
|
|
|
delay(1);
|
|
|
|
|
|
|
|
// if gpio_read == 0 return true else return false
|
2021-03-31 17:52:26 +00:00
|
|
|
result = !gpio_read(device->chip_select);
|
2021-03-09 11:53:33 +00:00
|
|
|
|
|
|
|
// configure pin back
|
2021-03-31 17:52:26 +00:00
|
|
|
gpio_init_ex(device->chip_select, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
|
|
|
|
gpio_write(device->chip_select, 1);
|
2021-03-09 11:53:33 +00:00
|
|
|
delay(1);
|
|
|
|
|
2021-03-31 17:52:26 +00:00
|
|
|
api_hal_spi_device_return(device);
|
2021-03-09 11:53:33 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|