api-hal-gpio.h 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(GpioPin* gpio, GpioMode mode, GpioPull pull, GpioSpeed speed);
  37. // write value to GPIO, false = LOW, true = HIGH
  38. void hal_gpio_write(GpioPin* gpio, bool state);
  39. // read value from GPIO, false = LOW, true = HIGH
  40. bool hal_gpio_read(const GpioPin* gpio);