api-hal-gpio.h 1.1 KB

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