api-hal-gpio.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. }
  42. extern COMP_HandleTypeDef hcomp1;
  43. bool get_rfid_in_level() {
  44. #ifdef INVERT_RFID_IN
  45. return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
  46. #else
  47. return (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
  48. #endif
  49. }