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