1 /* 2 * Copyright (C) 2017-2020 Alibaba Group Holding Limited 3 */ 4 5 /****************************************************************************** 6 * @file drv/gpio_pin.h 7 * @brief Header File for GPIO PIN Driver 8 * @version v1.0 9 * @date 2020-06-28 10 * @note Only one of gpio or gpio_pin interface can be selected 11 ******************************************************************************/ 12 13 #ifndef _DRV_GPIO_PIN_H_ 14 #define _DRV_GPIO_PIN_H_ 15 16 #include <stdint.h> 17 #include <stdbool.h> 18 #include <drv/common.h> 19 #include <drv/gpio.h> 20 #include <soc.h> 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * \struct csi_gpio_pin_t 28 * \brief GPIO PIN control block 29 */ 30 31 typedef struct csi_gpio_pin csi_gpio_pin_t; 32 struct csi_gpio_pin { 33 csi_gpio_t *gpio; 34 uint32_t pin_idx; 35 void (*callback)(csi_gpio_pin_t *pin, void *arg); 36 void *arg; 37 }; 38 39 /** 40 \brief Initialize GPIO pin handle 41 \param[in] pin GPIO pin handle 42 \param[in] pin_name GPIO pin name 43 \return Error code 44 */ 45 csi_error_t csi_gpio_pin_init(csi_gpio_pin_t *pin, pin_name_t pin_name); 46 47 /** 48 \brief De-initialize GPIO pin 49 \param[in] pin GPIO pin handle 50 \return None 51 */ 52 void csi_gpio_pin_uninit(csi_gpio_pin_t *pin); 53 54 /** 55 \brief Attach the interrupt callback to the GPIO pin 56 \param[in] pin GPIO pin handle 57 \param[in] callback Callback function 58 \param[in] arg User param passed to callback 59 \return Error code 60 */ 61 csi_error_t csi_gpio_pin_attach_callback(csi_gpio_pin_t *pin, void *callback, void *arg); 62 63 /** 64 \brief Config pin direction 65 \param[in] pin GPIO pin handle 66 \param[in] dir \ref csi_gpio_dir_t 67 \return Error code 68 */ 69 csi_error_t csi_gpio_pin_dir(csi_gpio_pin_t *pin, csi_gpio_dir_t dir); 70 71 /** 72 \brief Config pin mode 73 \param[in] pin GPIO pin handle 74 \param[in] mode \ref csi_gpio_mode_t 75 \return Error code 76 */ 77 csi_error_t csi_gpio_pin_mode(csi_gpio_pin_t *pin, csi_gpio_mode_t mode); 78 79 /** 80 \brief Config pin irq params 81 \param[in] pin GPIO pin handle 82 \param[in] mode Interrupt trigger mode \ref csi_gpio_irq_mode_t 83 \return Error code 84 */ 85 csi_error_t csi_gpio_pin_irq_mode(csi_gpio_pin_t *pin, csi_gpio_irq_mode_t mode); 86 87 /** 88 \brief Enable or disable gpio pin interrupt 89 \param[in] pin GPIO pin handle 90 \param[in] enable 0:disable 1:enable 91 \return Error code 92 */ 93 csi_error_t csi_gpio_pin_irq_enable(csi_gpio_pin_t *pin, bool enable); 94 95 /** 96 \brief Set debonce of pin when pin configed as input 97 \param[in] pin GPIO pin handle 98 \param[in] enbale 0: disable 1:enable 99 \return Error code 100 */ 101 csi_error_t csi_gpio_pin_debonce(csi_gpio_pin_t *pin, bool enable); 102 103 /** 104 \brief Set one or zero to specified pin 105 \param[in] pin GPIO pin handle 106 \param[in] value Value to be set \ref csi_gpio_pin_state_t 107 \return None 108 */ 109 void csi_gpio_pin_write(csi_gpio_pin_t *pin, csi_gpio_pin_state_t value); 110 111 /** 112 \brief Toggle output pin value,ex.if previous value is 1, then output 0 113 \param[in] pin GPIO pin handle 114 \return None 115 */ 116 void csi_gpio_pin_toggle(csi_gpio_pin_t *pin); 117 118 /** 119 \brief Get the value of specified GPIO pin 120 \param[in] pin GPIO port handle 121 \return gpio pin state, \ref csi_gpio_pin_state_t 122 */ 123 csi_gpio_pin_state_t csi_gpio_pin_read(csi_gpio_pin_t *pin); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* _GPIO_PIN_H_*/ 130