RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ Pin 的协作图:

结构体

struct  rt_device_pin
 
struct  rt_device_pin_mode
 
struct  rt_device_pin_value
 
struct  rt_pin_irq_hdr
 
struct  rt_pin_ops
 

宏定义

#define PIN_NONE   (-1)
 
#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   PIN_NONE
 

函数

int rt_device_pin_register (const char *name, const struct rt_pin_ops *ops, void *user_data)
 
void rt_pin_mode (rt_base_t pin, rt_uint8_t mode)
 
void rt_pin_write (rt_base_t pin, rt_ssize_t value)
 
rt_ssize_t rt_pin_read (rt_base_t pin)
 
rt_base_t rt_pin_get (const char *name)
 
rt_err_t rt_pin_attach_irq (rt_base_t pin, rt_uint8_t mode, void(*hdr)(void *args), void *args)
 
rt_err_t rt_pin_detach_irq (rt_base_t pin)
 
rt_err_t rt_pin_irq_enable (rt_base_t pin, rt_uint8_t enabled)
 
rt_err_t rt_pin_debounce (rt_base_t pin, rt_uint32_t debounce)
 

详细描述

Pin driver api

Example

#include <rtthread.h>
#include <rtdevice.h>
#ifndef BEEP_PIN_NUM
#define BEEP_PIN_NUM 35 // PB0
#endif
#ifndef KEY0_PIN_NUM
#define KEY0_PIN_NUM 55 // PD8
#endif
#ifndef KEY1_PIN_NUM
#define KEY1_PIN_NUM 56 // PD9
#endif
void beep_on(void *args)
{
rt_kprintf("turn on beep!\n");
rt_pin_write(BEEP_PIN_NUM, PIN_HIGH);
}
void beep_off(void *args)
{
rt_kprintf("turn off beep!\n");
rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
}
static void pin_beep_sample(void)
{
rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
rt_pin_attach_irq(KEY1_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_off, RT_NULL);
}
MSH_CMD_EXPORT(pin_beep_sample, pin beep sample);
#define rt_kprintf(...)
#define PIN_LOW
#define PIN_MODE_INPUT_PULLUP
void rt_pin_write(rt_base_t pin, rt_ssize_t value)
write pin value
void rt_pin_mode(rt_base_t pin, rt_uint8_t mode)
set pin mode
rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint8_t enabled)
enable or disable the pin interrupt
#define PIN_MODE_OUTPUT
#define PIN_HIGH
#define PIN_IRQ_ENABLE
#define PIN_IRQ_MODE_FALLING
rt_err_t rt_pin_attach_irq(rt_base_t pin, rt_uint8_t mode, void(*hdr)(void *args), void *args)
bind the pin interrupt callback function
#define MSH_CMD_EXPORT(...)
#define RT_NULL

宏定义说明

◆ PIN_NONE

#define PIN_NONE   (-1)

在文件 dev_pin.h114 行定义.

◆ PIN_LOW

#define PIN_LOW   0x00

low level

在文件 dev_pin.h116 行定义.

◆ PIN_HIGH

#define PIN_HIGH   0x01

high level

在文件 dev_pin.h117 行定义.

◆ PIN_MODE_OUTPUT

#define PIN_MODE_OUTPUT   0x00

output mode

在文件 dev_pin.h119 行定义.

◆ PIN_MODE_INPUT

#define PIN_MODE_INPUT   0x01

input mode

在文件 dev_pin.h120 行定义.

◆ PIN_MODE_INPUT_PULLUP

#define PIN_MODE_INPUT_PULLUP   0x02

input mode with pull-up

在文件 dev_pin.h121 行定义.

◆ PIN_MODE_INPUT_PULLDOWN

#define PIN_MODE_INPUT_PULLDOWN   0x03

input mode with pull-down

在文件 dev_pin.h122 行定义.

◆ PIN_MODE_OUTPUT_OD

#define PIN_MODE_OUTPUT_OD   0x04

output mode with open-drain

在文件 dev_pin.h123 行定义.

◆ PIN_IRQ_MODE_RISING

#define PIN_IRQ_MODE_RISING   0x00

rising edge trigger

在文件 dev_pin.h158 行定义.

◆ PIN_IRQ_MODE_FALLING

#define PIN_IRQ_MODE_FALLING   0x01

falling edge trigger

在文件 dev_pin.h159 行定义.

◆ PIN_IRQ_MODE_RISING_FALLING

#define PIN_IRQ_MODE_RISING_FALLING   0x02

rising and falling edge trigger

在文件 dev_pin.h160 行定义.

◆ PIN_IRQ_MODE_HIGH_LEVEL

#define PIN_IRQ_MODE_HIGH_LEVEL   0x03

high level trigger

在文件 dev_pin.h161 行定义.

◆ PIN_IRQ_MODE_LOW_LEVEL

#define PIN_IRQ_MODE_LOW_LEVEL   0x04

low level trigger

在文件 dev_pin.h162 行定义.

◆ PIN_IRQ_DISABLE

#define PIN_IRQ_DISABLE   0x00

disable irq

在文件 dev_pin.h164 行定义.

◆ PIN_IRQ_ENABLE

#define PIN_IRQ_ENABLE   0x01

enable irq

在文件 dev_pin.h165 行定义.

◆ PIN_IRQ_PIN_NONE

#define PIN_IRQ_PIN_NONE   PIN_NONE

no pin irq

在文件 dev_pin.h167 行定义.

函数说明

◆ rt_device_pin_register()

int rt_device_pin_register ( const char * name,
const struct rt_pin_ops * ops,
void * user_data )

register a pin device

参数
namethe name of pin device
opsthe operations of pin device
user_datathe user data of pin device
返回
int error code

◆ rt_pin_mode()

void rt_pin_mode ( rt_base_t pin,
rt_uint8_t mode )

set pin mode

参数
pinthe pin number
modethe pin mode

◆ rt_pin_write()

void rt_pin_write ( rt_base_t pin,
rt_ssize_t value )

write pin value

参数
pinthe pin number
valuethe pin value

◆ rt_pin_read()

rt_ssize_t rt_pin_read ( rt_base_t pin)

read pin value

参数
pinthe pin number
返回
rt_ssize_t the pin value

◆ rt_pin_get()

rt_base_t rt_pin_get ( const char * name)

get pin number by name

参数
namethe pin name
返回
rt_base_t the pin number

◆ rt_pin_attach_irq()

rt_err_t rt_pin_attach_irq ( rt_base_t pin,
rt_uint8_t mode,
void(* hdr )(void *args),
void * args )

bind the pin interrupt callback function

参数
pinthe pin number
modethe irq mode
hdrthe irq callback function
argsthe argument of the callback function
返回
rt_err_t error code

◆ rt_pin_detach_irq()

rt_err_t rt_pin_detach_irq ( rt_base_t pin)

detach the pin interrupt callback function

参数
pinthe pin number
返回
rt_err_t error code

◆ rt_pin_irq_enable()

rt_err_t rt_pin_irq_enable ( rt_base_t pin,
rt_uint8_t enabled )

enable or disable the pin interrupt

参数
pinthe pin number
enabledPIN_IRQ_ENABLE or PIN_IRQ_DISABLE
返回
rt_err_t error code

◆ rt_pin_debounce()

rt_err_t rt_pin_debounce ( rt_base_t pin,
rt_uint32_t debounce )

set the pin's debounce time

参数
pinthe pin number
debouncetime
返回
rt_err_t error code