RT-Thread API参考手册
3.1.1
嵌入式实时操作系统
|
PIN设备接口 更多...
结构体 | |
struct | rt_device_pin_mode |
引脚模式信息 更多... | |
struct | rt_device_pin_status |
引脚状态信息 更多... | |
struct | rt_pin_irq_hdr |
引脚中断信息 更多... | |
struct | rt_pin_ops |
引脚的操作方法 更多... | |
宏定义 | |
#define | PIN_LOW 0x00 |
低电平 | |
#define | PIN_HIGH 0x01 |
高电平 | |
#define | PIN_MODE_OUTPUT 0x00 |
普通输出模式 | |
#define | PIN_MODE_INPUT 0x01 |
输入模式 | |
#define | PIN_MODE_INPUT_PULLUP 0x02 |
输入上拉模式 | |
#define | PIN_MODE_INPUT_PULLDOWN 0x03 |
输入下拉模式 | |
#define | PIN_MODE_OUTPUT_OD 0x04 |
开漏输出模式 | |
#define | PIN_IRQ_MODE_RISING 0x00 |
上升沿触发模式 | |
#define | PIN_IRQ_MODE_FALLING 0x01 |
下降沿触发模式 | |
#define | PIN_IRQ_MODE_RISING_FALLING 0x02 |
边沿触发(上升沿和下降沿都触发) | |
#define | PIN_IRQ_MODE_HIGH_LEVEL 0x03 |
高电平触发模式 | |
#define | PIN_IRQ_MODE_LOW_LEVEL 0x04 |
低电平触发模式 | |
#define | PIN_IRQ_DISABLE 0x00 |
引脚中断禁止命令 | |
#define | PIN_IRQ_ENABLE 0x01 |
引脚中断使能命令 | |
#define | PIN_IRQ_PIN_NONE -1 |
引脚无中断 | |
函数 | |
int | rt_device_pin_register (const char *name, const struct rt_pin_ops *ops, void *user_data) |
注册PIN设备 更多... | |
void | rt_pin_mode (rt_base_t pin, rt_base_t mode) |
设置引脚模式 更多... | |
void | rt_pin_write (rt_base_t pin, rt_base_t value) |
设置引脚电平 更多... | |
int | rt_pin_read (rt_base_t pin) |
读取引脚电平 更多... | |
rt_err_t | rt_pin_attach_irq (rt_int32_t pin, rt_uint32_t mode, void(*hdr)(void *args), void *args) |
绑定引脚中断回调函数 更多... | |
rt_err_t | rt_pin_detach_irq (rt_int32_t pin) |
脱离引脚中断回调函数 更多... | |
rt_err_t | rt_pin_irq_enable (rt_base_t pin, rt_uint32_t enabled) |
使能 / 屏蔽引脚中断 更多... | |
PIN设备接口
int rt_device_pin_register | ( | const char * | name, |
const struct rt_pin_ops * | ops, | ||
void * | user_data | ||
) |
注册PIN设备
此函数可以注册PIN设备到PIN驱动框架中。
name | PIN设备名称 |
ops | PIN设备操作方法对象指针 |
user_data | 用户数据,一般设为RT_NULL |
设置引脚模式
此函数可以设定指定引脚的工作模式。
pin | 引脚编号 | ||||||||||||
mode | 引脚工作模式,可以取以下 5 种模式之一
|
设置引脚电平
此函数可以设定指定引脚的输出电平。
pin | 引脚编号 |
value | 电平逻辑值,可取 2 种值之一,PIN_LOW 低电平,PIN_HIGH 高电平 |
int rt_pin_read | ( | rt_base_t | pin | ) |
读取引脚电平
该函数可以读取指定引脚的当前电平。
pin | 引脚编号 |
rt_err_t rt_pin_attach_irq | ( | rt_int32_t | pin, |
rt_uint32_t | mode, | ||
void(*)(void *args) | hdr, | ||
void * | args | ||
) |
绑定引脚中断回调函数
此函数可以设定指定引脚的中断触发模式,并可指定中断回调函数。
pin | 引脚编号 | ||||||||||||
mode | 中断触发模式,可取以下 5 种值之一
| ||||||||||||
hdr | 中断回调函数,用户需要自行定义这个函数,其返回值为 void | ||||||||||||
args | 中断回调函数的参数,不需要时设置为 RT_NULL |
rt_err_t rt_pin_detach_irq | ( | rt_int32_t | pin | ) |
脱离引脚中断回调函数
调用此函数可以脱离指定的引脚中断。
pin | 引脚编号 |
rt_err_t rt_pin_irq_enable | ( | rt_base_t | pin, |
rt_uint32_t | enabled | ||
) |
使能 / 屏蔽引脚中断
此函数可以使能/屏蔽指定引脚的中断。
pin | 引脚编号 |
enabled | 状态,可取 2 种值之一:PIN_IRQ_ENABLE 开启,PIN_IRQ_DISABLE 关闭 |