gpio_exp.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* GDS Example
  2. This example code is in the Public Domain (or CC0 licensed, at your option.)
  3. Unless required by applicable law or agreed to in writing, this
  4. software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  5. CONDITIONS OF ANY KIND, either express or implied.
  6. */
  7. #pragma once
  8. #include <stdint.h>
  9. #include "freertos/FreeRTOS.h"
  10. #include "driver/gpio.h"
  11. struct gpio_exp_s;
  12. typedef struct {
  13. char model[32];
  14. uint8_t intr;
  15. uint8_t count;
  16. uint32_t base;
  17. union gpio_exp_phy_u {
  18. struct {
  19. uint8_t addr, port;
  20. };
  21. struct {
  22. uint8_t cs_pin;
  23. };
  24. } phy;
  25. } gpio_exp_config_t;
  26. typedef void (*gpio_exp_enumerator)(int gpio, int level, struct gpio_exp_s *expander);
  27. typedef BaseType_t (*gpio_exp_isr)(void *arg);
  28. // set <intr> to -1 and <queue> to NULL if there is no interrupt
  29. struct gpio_exp_s* gpio_exp_create(const gpio_exp_config_t *config);
  30. bool gpio_exp_add_isr(gpio_exp_isr isr, void *arg, struct gpio_exp_s *expander);
  31. uint32_t gpio_exp_get_base(struct gpio_exp_s *expander);
  32. struct gpio_exp_s* gpio_exp_get_expander(int gpio);
  33. /* For all functions below when <expander> is provided, GPIO's can be numbered from 0. If <expander>
  34. is NULL, then GPIO must start from base */
  35. esp_err_t gpio_exp_set_direction(int gpio, gpio_mode_t mode, struct gpio_exp_s *expander);
  36. esp_err_t gpio_exp_set_pull_mode(int gpio, gpio_pull_mode_t mode, struct gpio_exp_s *expander);
  37. int gpio_exp_get_level(int gpio, uint32_t age, struct gpio_exp_s *expander);
  38. esp_err_t gpio_exp_set_level(int gpio, int level, bool direct, struct gpio_exp_s *expander);
  39. /* This can be called to enumerate modified GPIO since last read. Note that <enumerator>
  40. can be NULL to initialize all GPIOs */
  41. void gpio_exp_enumerate(gpio_exp_enumerator enumerator, struct gpio_exp_s *expander);
  42. // option to use either built-in or expanded GPIO
  43. esp_err_t gpio_set_direction_u(int gpio, gpio_mode_t mode);
  44. esp_err_t gpio_set_pull_mode_u(int gpio, gpio_pull_mode_t mode);
  45. int gpio_get_level_u(int gpio);
  46. esp_err_t gpio_set_level_u(int gpio, int level);