flipperzero-firmware/firmware/targets/f4/api-hal/api-hal-sd.c
SG fef16a8e7a
SD card v7 BSP (#361)
* Outdated apps: add api-light-usage

* Gpio: update SD card CS pin settings

* API-power: added fns to disable/enable external 3v3 dc-dc

* API-gpio: separated SD card detect routines

* Resources: removed sd cs pin

* SD card: low level init now resets card power supply

* App SD-filesystem: use new card detect fns

* SD card: fix low level init headers

* SD card: more realilable low level init, power reset, exit from command read cycle conditionally

* App SD-filesystem: led notifiers, init cycling

* SD card: backport to F4

* SD card: handle eject in init sequence

* SD card: api to set level on detect gpio

* SPI: api to set state on bus pins

* SD card: set low state on bus pins while power reset

Co-authored-by: coreglitch <mail@s3f.ru>
2021-03-09 14:53:33 +03:00

40 lines
897 B
C

#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
const GpioPin* sd_cs_record = &sd_cs_gpio;
// TODO: SPI manager
api_hal_spi_lock(sd_fast_spi.spi);
// configure pin as input
gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
delay(1);
// 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);
gpio_write(sd_cs_record, 1);
delay(1);
// TODO: SPI manager
api_hal_spi_unlock(sd_fast_spi.spi);
return result;
}