一个芯片的gpio一般都会有如下一些结构体,用来描述该gpio所具备的所有功能, 以及如何配置一个gpio:
1. gpio_config_t --- 一个gpio的配置,这个结构体通常用来表示一个gpio的具体配置
/* Configuration parameters for one GPIO pin.*/
typedef struct
{
gpio_mode_t mode; /* Defines mode (SOFTWARE or Alternate). */
gpio_direction_t direction; /* Define pin direction (in SOFTWARE mode only). */
gpio_trig_t trig; /* Interrupt trigger (in SOFTWARE mode only) */
gpio_debounce_t debounce; /* Debounce logic control for pin (in SOFTWARE mode only) */
} gpio_config_t;
2. gpio_mode_t, --- gpio 的工作模式:
/* Defines pin assignment(Software mode or Alternate mode) */
typedef enum
{
GPIO_MODE_LEAVE_UNCHANGED, /* Parameter will be ignored by the function. */
GPIO_MODE_SOFTWARE, /* Pin connected to GPIO (SW controlled) */
GPIO_MODE_ALT_FUNCTION_A, /* Pin connected to alternate function 1 (HW periph 1) */
GPIO_MODE_ALT_FUNCTION_B, /* Pin connected to alternate function 2 (HW periph 2) */
GPIO_MODE_ALT_FUNCTION_C /* Pin connected to alternate function 3 (HW periph 3) */
} gpio_mode_t;
3. gpio_direction_t --- 该gpio的输入输出方向
/* Defines GPIO pin direction */
typedef enum
{
GPIO_DIR_LEAVE_UNCHANGED, /* Parameter will be ignored by the function. */
GPIO_DIR_INPUT, /* GPIO set as input */
GPIO_DIR_OUTPUT /* GPIO set as output */
} gpio_direction_t;
4. gpio_trig_t --- 该gpio的中断触发方式:
/* Interrupt trigger mode */
typedef enum
{
GPIO_TRIG_LEAVE_UNCHANGED, /* Parameter will be ignored by the function */
GPIO_TRIG_DISABLE, /* Triggers no IT */
GPIO_TRIG_RISING_EDGE, /* Triggers an IT on a rising edge */
GPIO_TRIG_FALLING_EDGE, /* Triggers an IT on a falling edge */
GPIO_TRIG_BOTH_EDGES /* Triggers an IT on a rising and a falling edge */
// GPIO_TRIG_HIGH_LEVEL, /* Triggers an IT on a high level */
// GPIO_TRIG_LOW_LEVEL /* Triggers an IT on a low level */
} gpio_trig_t;
5. gpio_debounce_t ---去偶功能使用情况