Pin driver api
Example
#include <rtdevice.h>
#ifndef BEEP_PIN_NUM
#define BEEP_PIN_NUM 35
#endif
#ifndef KEY0_PIN_NUM
#define KEY0_PIN_NUM 55
#endif
#ifndef KEY1_PIN_NUM
#define KEY1_PIN_NUM 56
#endif
void beep_on(void *args)
{
}
void beep_off(void *args)
{
}
static void pin_beep_sample(void)
{
}
#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_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(...)
◆ PIN_NONE
◆ PIN_LOW
◆ PIN_HIGH
◆ PIN_MODE_OUTPUT
#define PIN_MODE_OUTPUT 0x00 |
◆ PIN_MODE_INPUT
#define PIN_MODE_INPUT 0x01 |
◆ PIN_MODE_INPUT_PULLUP
#define PIN_MODE_INPUT_PULLUP 0x02 |
◆ PIN_MODE_INPUT_PULLDOWN
#define PIN_MODE_INPUT_PULLDOWN 0x03 |
◆ PIN_MODE_OUTPUT_OD
#define PIN_MODE_OUTPUT_OD 0x04 |
◆ PIN_IRQ_MODE_RISING
#define PIN_IRQ_MODE_RISING 0x00 |
◆ PIN_IRQ_MODE_FALLING
#define PIN_IRQ_MODE_FALLING 0x01 |
◆ PIN_IRQ_MODE_RISING_FALLING
#define PIN_IRQ_MODE_RISING_FALLING 0x02 |
◆ PIN_IRQ_MODE_HIGH_LEVEL
#define PIN_IRQ_MODE_HIGH_LEVEL 0x03 |
◆ PIN_IRQ_MODE_LOW_LEVEL
#define PIN_IRQ_MODE_LOW_LEVEL 0x04 |
◆ PIN_IRQ_DISABLE
#define PIN_IRQ_DISABLE 0x00 |
◆ PIN_IRQ_ENABLE
#define PIN_IRQ_ENABLE 0x01 |
◆ PIN_IRQ_PIN_NONE
◆ 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
- 参数
-
name | the name of pin device |
ops | the operations of pin device |
user_data | the user data of pin device |
- 返回
- int error code
◆ rt_pin_mode()
set pin mode
- 参数
-
pin | the pin number |
mode | the pin mode |
◆ rt_pin_write()
write pin value
- 参数
-
pin | the pin number |
value | the pin value |
◆ rt_pin_read()
◆ rt_pin_get()
get pin number by name
- 参数
-
- 返回
- rt_base_t the pin number
◆ rt_pin_attach_irq()
bind the pin interrupt callback function
- 参数
-
pin | the pin number |
mode | the irq mode |
hdr | the irq callback function |
args | the argument of the callback function |
- 返回
- rt_err_t error code
◆ rt_pin_detach_irq()
detach the pin interrupt callback function
- 参数
-
- 返回
- rt_err_t error code
◆ rt_pin_irq_enable()
enable or disable the pin interrupt
- 参数
-
pin | the pin number |
enabled | PIN_IRQ_ENABLE or PIN_IRQ_DISABLE |
- 返回
- rt_err_t error code
◆ rt_pin_debounce()
set the pin's debounce time
- 参数
-
pin | the pin number |
debounce | time |
- 返回
- rt_err_t error code