api-hal-gpio.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include "main.h"
  3. #include "stdbool.h"
  4. // hw-api
  5. typedef char GPIO_TypeDef;
  6. typedef enum {
  7. GpioModeInput,
  8. GpioModeOutputPushPull,
  9. GpioModeOutputOpenDrain,
  10. GpioModeAltFunctionPushPull,
  11. GpioModeAltFunctionOpenDrain,
  12. GpioModeAnalog,
  13. GpioModeInterruptRise,
  14. GpioModeInterruptFall,
  15. GpioModeInterruptRiseFall,
  16. GpioModeEventRise,
  17. GpioModeEventFall,
  18. GpioModeEventRiseFall,
  19. } GpioMode;
  20. typedef enum {
  21. GpioSpeedLow,
  22. GpioSpeedMedium,
  23. GpioSpeedHigh,
  24. GpioSpeedVeryHigh,
  25. } GpioSpeed;
  26. typedef enum {
  27. GpioPullNo,
  28. GpioPullUp,
  29. GpioPullDown,
  30. } GpioPull;
  31. typedef struct {
  32. GPIO_TypeDef* port;
  33. uint16_t pin;
  34. } GpioPin;
  35. // init GPIO
  36. void hal_gpio_init(
  37. const GpioPin* gpio,
  38. const GpioMode mode,
  39. const GpioPull pull,
  40. const GpioSpeed speed);
  41. // write value to GPIO, false = LOW, true = HIGH
  42. void hal_gpio_write(const GpioPin* gpio, const bool state);
  43. // read value from GPIO, false = LOW, true = HIGH
  44. bool hal_gpio_read(const GpioPin* gpio);
  45. void enable_cc1101_irq();