drv_gpio.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-08-20 zx.chen header file for gpio driver
  9. */
  10. #ifndef _CSI_GPIO_H_
  11. #define _CSI_GPIO_H_
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include <drv_common.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /// definition for gpio pin handle.
  19. typedef void *gpio_pin_handle_t;
  20. /****** GPIO specific error codes *****/
  21. typedef enum
  22. {
  23. GPIO_ERROR_MODE = (DRV_ERROR_SPECIFIC + 1), ///< Specified Mode not supported
  24. GPIO_ERROR_DIRECTION, ///< Specified direction not supported
  25. GPIO_ERROR_IRQ_MODE, ///< Specified irq mode not supported
  26. } gpio_error_e;
  27. /*----- GPIO Control Codes: Mode -----*/
  28. typedef enum
  29. {
  30. GPIO_MODE_PULLNONE = 0, ///< pull none for input
  31. GPIO_MODE_PULLUP, ///< pull up for input
  32. GPIO_MODE_PULLDOWN, ///< pull down for input
  33. GPIO_MODE_OPEN_DRAIN, ///< open drain mode for output
  34. GPIO_MODE_PUSH_PULL, ///< push-pull mode for output
  35. } gpio_mode_e;
  36. /*----- GPIO Control Codes: Mode Parameters: Data Bits -----*/
  37. typedef enum
  38. {
  39. GPIO_DIRECTION_INPUT = 0, ///< gpio as input
  40. GPIO_DIRECTION_OUTPUT, ///< gpio as output
  41. } gpio_direction_e;
  42. /*----- GPIO Control Codes: Mode Parameters: Parity -----*/
  43. typedef enum
  44. {
  45. GPIO_IRQ_MODE_RISING_EDGE = 0, ///< interrupt mode for rising edge
  46. GPIO_IRQ_MODE_FALLING_EDGE, ///< interrupt mode for falling edge
  47. GPIO_IRQ_MODE_DOUBLE_EDGE, ///< interrupt mode for double edge
  48. GPIO_IRQ_MODE_LOW_LEVEL, ///< interrupt mode for low level
  49. GPIO_IRQ_MODE_HIGH_LEVEL, ///< interrupt mode for high level
  50. } gpio_irq_mode_e;
  51. typedef void (*gpio_event_cb_t)(int32_t idx); ///< gpio Event call back.
  52. /**
  53. \brief Initialize GPIO handle.
  54. \param[in] gpio_pin gpio pin idx.
  55. \param[in] cb_event event callback function \ref gpio_event_cb_t
  56. \return gpio_pin_handle
  57. */
  58. gpio_pin_handle_t csi_gpio_pin_initialize(int32_t gpio_pin, gpio_event_cb_t cb_event);
  59. /**
  60. \brief De-initialize GPIO pin handle.stops operation and releases the software resources used by the handle.
  61. \param[in] handle gpio pin handle to operate.
  62. \return error code
  63. */
  64. int32_t csi_gpio_pin_uninitialize(gpio_pin_handle_t handle);
  65. /**
  66. \brief control gpio power.
  67. \param[in] handle gpio handle to operate.
  68. \param[in] state power state.\ref csi_power_stat_e.
  69. \return error code
  70. */
  71. int32_t csi_gpio_power_control(gpio_pin_handle_t handle, csi_power_stat_e state);
  72. /**
  73. \brief config pin mode
  74. \param[in] pin gpio pin handle to operate.
  75. \param[in] mode \ref gpio_mode_e
  76. \return error code
  77. */
  78. int32_t csi_gpio_pin_config_mode(gpio_pin_handle_t handle,
  79. gpio_mode_e mode);
  80. /**
  81. \brief config pin direction
  82. \param[in] pin gpio pin handle to operate.
  83. \param[in] dir \ref gpio_direction_e
  84. \return error code
  85. */
  86. int32_t csi_gpio_pin_config_direction(gpio_pin_handle_t handle,
  87. gpio_direction_e dir);
  88. /**
  89. \brief config pin
  90. \param[in] pin gpio pin handle to operate.
  91. \param[in] mode \ref gpio_mode_e
  92. \param[in] dir \ref gpio_direction_e
  93. \return error code
  94. */
  95. int32_t csi_gpio_pin_config(gpio_pin_handle_t handle,
  96. gpio_mode_e mode,
  97. gpio_direction_e dir);
  98. /**
  99. \brief Set one or zero to the selected GPIO pin.
  100. \param[in] pin gpio pin handle to operate.
  101. \param[in] value value to be set
  102. \return error code
  103. */
  104. int32_t csi_gpio_pin_write(gpio_pin_handle_t handle, bool value);
  105. /**
  106. \brief Get the value of selected GPIO pin.
  107. \param[in] pin gpio pin handle to operate.
  108. \param[out] value buffer to store the pin value
  109. \return error code
  110. */
  111. int32_t csi_gpio_pin_read(gpio_pin_handle_t handle, bool *value);
  112. /**
  113. \brief set GPIO interrupt mode.
  114. \param[in] pin gpio pin handle to operate.
  115. \param[in] mode irq mode to be set
  116. \param[in] enable enable flag
  117. \return error code
  118. */
  119. int32_t csi_gpio_pin_set_irq(gpio_pin_handle_t handle, gpio_irq_mode_e mode, bool enable);
  120. #ifdef __cplusplus
  121. }
  122. #endif
  123. #endif /* _CSI_GPIO_H_ */