api-hal-gpio.c 845 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <api-hal-gpio.h>
  2. #include <api-hal-version.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. extern COMP_HandleTypeDef hcomp1;
  18. bool get_rfid_in_level() {
  19. bool value = false;
  20. if (api_hal_version_get_hw_version() > 7) {
  21. value = (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
  22. } else {
  23. value = (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
  24. }
  25. #ifdef INVERT_RFID_IN
  26. return !value;
  27. #else
  28. return value;
  29. #endif
  30. }