api-hal-gpio.c 1.3 KB

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