board_gpio_profile.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #ifndef BOARD_GPIO_PROFILE_H
  3. #define BOARD_GPIO_PROFILE_H
  4. #include <stddef.h>
  5. #include <stdint.h>
  6. #include "driver/gpio.h"
  7. /*
  8. * Capabilities are deliberately explicit. A GPIO is usable only when the
  9. * selected board profile lists it and grants the requested capabilities.
  10. */
  11. enum GpioPinCapability : uint8_t
  12. {
  13. GPIO_PIN_CAP_INPUT = 1U << 0,
  14. GPIO_PIN_CAP_OUTPUT = 1U << 1,
  15. GPIO_PIN_CAP_PULL_UP = 1U << 2,
  16. GPIO_PIN_CAP_PULL_DOWN = 1U << 3,
  17. GPIO_PIN_CAP_INTERRUPT = 1U << 4,
  18. GPIO_PIN_CAP_PWM = 1U << 5
  19. };
  20. struct GpioBoardPin
  21. {
  22. gpio_num_t gpio;
  23. uint8_t capabilities;
  24. const char *description;
  25. };
  26. struct GpioBoardProfile
  27. {
  28. const char *name;
  29. const GpioBoardPin *userPins;
  30. size_t userPinCount;
  31. const gpio_num_t *reservedPins;
  32. size_t reservedPinCount;
  33. gpio_num_t builtInFlashLedPin;
  34. uint8_t maxUserChannels;
  35. };
  36. static const uint8_t GPIO_MAX_USER_CHANNELS = 4U;
  37. /* Returns the profile selected at compile time for the complete board. */
  38. const GpioBoardProfile *gpioGetBoardProfile(void);
  39. /* Profile integrity and pin lookup helpers. */
  40. bool gpioBoardProfileIsValid(void);
  41. const GpioBoardPin *gpioBoardFindUserPin(gpio_num_t gpio);
  42. bool gpioBoardPinSupports(gpio_num_t gpio, uint8_t requiredCapabilities);
  43. bool gpioBoardIsReservedPin(gpio_num_t gpio);
  44. bool gpioBoardIsBuiltInFlashLed(gpio_num_t gpio);
  45. #endif // BOARD_GPIO_PROFILE_H