api-hal-gpio.c 1.1 KB

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