api-hal-sd.c 871 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <api-hal-sd.h>
  2. #include <api-hal-spi.h>
  3. #include <api-hal-resources.h>
  4. #include <api-hal-delay.h>
  5. #include <furi.h>
  6. void hal_sd_detect_init(void) {
  7. // nothing to do
  8. }
  9. void hal_sd_detect_set_low(void) {
  10. // nothing to do
  11. }
  12. bool hal_sd_detect(void) {
  13. bool result = false;
  14. // TODO open record
  15. const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSdCard);
  16. // configure pin as input
  17. gpio_init_ex(device->chip_select, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
  18. delay(1);
  19. // if gpio_read == 0 return true else return false
  20. result = !gpio_read(device->chip_select);
  21. // configure pin back
  22. gpio_init_ex(device->chip_select, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
  23. gpio_write(device->chip_select, 1);
  24. delay(1);
  25. api_hal_spi_device_return(device);
  26. return result;
  27. }