pinmux.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2015 Intel Corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * Public APIs for Pinmux drivers
  9. */
  10. #ifndef ZEPHYR_INCLUDE_DRIVERS_PINMUX_H_
  11. #define ZEPHYR_INCLUDE_DRIVERS_PINMUX_H_
  12. /**
  13. * @brief Pinmux Interface
  14. * @defgroup pinmux_interface Pinmux Interface
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. #include <zephyr/types.h>
  19. #include <device.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. #define PINMUX_FUNC_A 0
  24. #define PINMUX_FUNC_B 1
  25. #define PINMUX_FUNC_C 2
  26. #define PINMUX_FUNC_D 3
  27. #define PINMUX_FUNC_E 4
  28. #define PINMUX_FUNC_F 5
  29. #define PINMUX_FUNC_G 6
  30. #define PINMUX_FUNC_H 7
  31. #define PINMUX_FUNC_I 8
  32. #define PINMUX_FUNC_J 9
  33. #define PINMUX_FUNC_K 10
  34. #define PINMUX_FUNC_L 11
  35. #define PINMUX_FUNC_M 12
  36. #define PINMUX_FUNC_N 13
  37. #define PINMUX_FUNC_O 14
  38. #define PINMUX_FUNC_P 15
  39. #define PINMUX_PULLUP_ENABLE (0x1)
  40. #define PINMUX_PULLUP_DISABLE (0x0)
  41. #define PINMUX_INPUT_ENABLED (0x1)
  42. #define PINMUX_OUTPUT_ENABLED (0x0)
  43. /**
  44. * @typedef pmux_set
  45. * @brief Callback API upon setting a PIN's function
  46. * See pinmux_pin_set() for argument description
  47. */
  48. typedef int (*pmux_set)(const struct device *dev, uint32_t pin, uint32_t func);
  49. /**
  50. * @typedef pmux_get
  51. * @brief Callback API upon getting a PIN's function
  52. * See pinmux_pin_get() for argument description
  53. */
  54. typedef int (*pmux_get)(const struct device *dev, uint32_t pin,
  55. uint32_t *func);
  56. /**
  57. * @typedef pmux_pullup
  58. * @brief Callback API upon setting a PIN's pullup
  59. * See pinmix_pin_pullup() for argument description
  60. */
  61. typedef int (*pmux_pullup)(const struct device *dev, uint32_t pin,
  62. uint8_t func);
  63. /**
  64. * @typedef pmux_input
  65. * @brief Callback API upon setting a PIN's input function
  66. * See pinmux_input() for argument description
  67. */
  68. typedef int (*pmux_input)(const struct device *dev, uint32_t pin,
  69. uint8_t func);
  70. __subsystem struct pinmux_driver_api {
  71. pmux_set set;
  72. pmux_get get;
  73. pmux_pullup pullup;
  74. pmux_input input;
  75. };
  76. static inline int pinmux_pin_set(const struct device *dev, uint32_t pin,
  77. uint32_t func)
  78. {
  79. const struct pinmux_driver_api *api =
  80. (const struct pinmux_driver_api *)dev->api;
  81. return api->set(dev, pin, func);
  82. }
  83. static inline int pinmux_pin_get(const struct device *dev, uint32_t pin,
  84. uint32_t *func)
  85. {
  86. const struct pinmux_driver_api *api =
  87. (const struct pinmux_driver_api *)dev->api;
  88. return api->get(dev, pin, func);
  89. }
  90. static inline int pinmux_pin_pullup(const struct device *dev, uint32_t pin,
  91. uint8_t func)
  92. {
  93. const struct pinmux_driver_api *api =
  94. (const struct pinmux_driver_api *)dev->api;
  95. return api->pullup(dev, pin, func);
  96. }
  97. static inline int pinmux_pin_input_enable(const struct device *dev,
  98. uint32_t pin,
  99. uint8_t func)
  100. {
  101. const struct pinmux_driver_api *api =
  102. (const struct pinmux_driver_api *)dev->api;
  103. return api->input(dev, pin, func);
  104. }
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108. /**
  109. *
  110. * @}
  111. */
  112. #endif /* ZEPHYR_INCLUDE_DRIVERS_PINMUX_H_ */