You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
952 B

2 years ago
  1. #pragma once
  2. #include "pin.h"
  3. #include "xs_basic.h"
  4. #include "xs_log.h"
  5. typedef enum {
  6. kxs_gpio_nopull, //
  7. kxs_gpio_pullup, //
  8. kxs_gpio_pulldown, //
  9. kxs_gpio_od, //
  10. } xs_gpio_mode_t;
  11. typedef enum { kxs_gpio_ain, kxs_gpio_input, kxs_gpio_output } xs_gpio_type_t;
  12. typedef enum {
  13. kxs_gpio_no_irq,
  14. kxs_gpio_rising_irq,
  15. kxs_gpio_falling_irq,
  16. kxs_gpio_rising_and_falling_irq,
  17. } xs_gpio_irq_t;
  18. typedef struct {
  19. Pin_t pin;
  20. GPIO_TypeDef *gpio;
  21. uint16_t pinoff;
  22. xs_gpio_mode_t mode;
  23. xs_gpio_type_t gpiotype;
  24. xs_gpio_irq_t irqtype;
  25. bool mirror;
  26. bool inited;
  27. } xs_gpio_t;
  28. void xs_gpio_init_as_input(xs_gpio_t *gpio, Pin_t pin, xs_gpio_mode_t mode, xs_gpio_irq_t irqtype, bool mirror);
  29. void xs_gpio_init_as_output(xs_gpio_t *gpio, Pin_t pin, xs_gpio_mode_t mode, bool mirror, bool initLevel);
  30. bool xs_gpio_read(xs_gpio_t *gpio);
  31. void xs_gpio_write(xs_gpio_t *gpio, bool level);