文章目录
GPIO输入输出
RASC图形化配置
输出模式:
输入模式:
配置选项:
配置项 | 取值/描述 |
---|---|
Mode | l "Input mode"(输入模式)l "Output mode(Initial Low)"(输出模式,初始电平为低)l "Output mode(Initial High)"(输出模式,初始电平为高) |
Pull up(上拉电阻) | l "None"(禁止内部上拉)l "input pull-up"(使能内部上拉)当引脚被配置为Output mode时无法设置Pull up参数 |
IRQ(中断) | l "None"(不使用中断)l "IRQ10"(使用中断) |
Output type(输出类型) | l "CMOS"l "n-ch open drain"(开漏)当引脚被配置为Input mode时无法设置本参数 |
Symbolic Name | #define LED (BSP_IO_PORT_04_PIN_00) |
接口函数
[API详解](第5章 GPIO输入输出 | 百问网 (100ask.net))
c
fsp_err_t (* open)(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
fsp_err_t (* close)(ioport_ctrl_t * const p_ctrl);
fsp_err_t (* pinsCfg)(ioport_ctrl_t * const p_ctrl, const ioport_cfg_t * p_cfg);
fsp_err_t (* pinCfg)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, uint32_t cfg);
fsp_err_t (* pinEventInputRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t * p_pin_event);
fsp_err_t (* pinEventOutputWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin,bsp_io_level_t pin_value);
fsp_err_t (* pinRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t * p_pin_value);
fsp_err_t (* pinWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_pin_t pin, bsp_io_level_t level);
fsp_err_t (* portDirectionSet)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port,ioport_size_t direction_values, ioport_size_t mask);
fsp_err_t (* portEventInputRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port, ioport_size_t * p_event_data);
fsp_err_t (* portEventOutputWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port,ioport_size_t event_data,ioport_size_t mask_value);
fsp_err_t (* portRead)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port,ioport_size_t * p_port_value);
fsp_err_t (* portWrite)(ioport_ctrl_t * const p_ctrl, bsp_io_port_t port,ioport_size_t value, ioport_size_t mask);
实例代码:
c
/* in hal_entry() */
bsp_io_level_t level;
while(1)
{
/* 读按键状态 */
g_ioport.p_api->pinRead(&g_ioport_ctrl, BSP_IO_PORT_00_PIN_00, &level);
/* 根据按键状态设置LED */
g_ioport.p_api->pinWrite(&g_ioport_ctrl, BSP_IO_PORT_04_PIN_00, level);
}