api-hal-gpio.c 1.2 KB

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