furi_hal_sd.c 844 B

12345678910111213141516171819202122232425
  1. #include "furi_hal_sd.h"
  2. #include <stm32wbxx_ll_gpio.h>
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. void hal_sd_detect_init(void) {
  6. // low speed input with pullup
  7. LL_GPIO_SetPinMode(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_MODE_INPUT);
  8. LL_GPIO_SetPinSpeed(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_SPEED_FREQ_LOW);
  9. LL_GPIO_SetPinPull(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_PULL_UP);
  10. }
  11. void hal_sd_detect_set_low(void) {
  12. // low speed input with pullup
  13. LL_GPIO_SetPinMode(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_MODE_OUTPUT);
  14. LL_GPIO_SetPinOutputType(SD_CD_GPIO_Port, SD_CD_Pin, LL_GPIO_OUTPUT_OPENDRAIN);
  15. LL_GPIO_ResetOutputPin(SD_CD_GPIO_Port, SD_CD_Pin);
  16. }
  17. bool hal_sd_detect(void) {
  18. bool result = !(LL_GPIO_IsInputPinSet(SD_CD_GPIO_Port, SD_CD_Pin));
  19. return result;
  20. }
  21. FuriHalSpiBusHandle* furi_hal_sd_spi_handle = NULL;