api-hal-gpio.c 972 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "api-hal-gpio.h"
  2. #include "api-hal-resources.h"
  3. // init GPIO
  4. void hal_gpio_init(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed) {
  5. // TODO: Alternate Functions
  6. GPIO_InitTypeDef GPIO_InitStruct = {0};
  7. GPIO_InitStruct.Pin = gpio->pin;
  8. GPIO_InitStruct.Mode = mode;
  9. GPIO_InitStruct.Pull = pull;
  10. GPIO_InitStruct.Speed = speed;
  11. HAL_GPIO_Init(gpio->port, &GPIO_InitStruct);
  12. }
  13. bool hal_gpio_read_sd_detect(void) {
  14. bool result = false;
  15. // create pin
  16. GpioPin sd_cs_pin = sd_cs_gpio;
  17. // TODO open record
  18. GpioPin* sd_cs_record = &sd_cs_pin;
  19. // configure pin as input
  20. gpio_init_ex(sd_cs_record, GpioModeInput, GpioPullUp, GpioSpeedVeryHigh);
  21. delay(50);
  22. // if gpio_read == 0 return true else return false
  23. result = !gpio_read(sd_cs_record);
  24. // configure pin back
  25. gpio_init_ex(sd_cs_record, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh);
  26. delay(50);
  27. return result;
  28. }