Pin driver api.
Example
#include <rtthread.h>
#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)
{
rt_kprintf("turn on beep!\n");
}
void beep_off(void *args)
{
rt_kprintf("turn off beep!\n");
}
static void pin_beep_sample(void)
{
}
#define PIN_LOW
Definition: dev_pin.h:116
#define PIN_MODE_INPUT_PULLUP
Definition: dev_pin.h:121
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
Definition: dev_pin.h:119
#define PIN_HIGH
Definition: dev_pin.h:117
#define PIN_IRQ_ENABLE
Definition: dev_pin.h:165
#define PIN_IRQ_MODE_FALLING
Definition: dev_pin.h:159
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(...)
Definition: finsh.h:142
◆ 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 |
input mode with pull-down
◆ PIN_MODE_OUTPUT_OD
#define PIN_MODE_OUTPUT_OD 0x04 |
output mode with open-drain
◆ 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 |
rising and falling edge trigger
◆ 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
#define PIN_IRQ_PIN_NONE 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
- Parameters
-
name | the name of pin device |
ops | the operations of pin device |
user_data | the user data of pin device |
- Returns
- int error code
◆ rt_pin_mode()
void rt_pin_mode |
( |
rt_base_t |
pin, |
|
|
rt_uint8_t |
mode |
|
) |
| |
set pin mode
- Parameters
-
pin | the pin number |
mode | the pin mode |
◆ rt_pin_write()
void rt_pin_write |
( |
rt_base_t |
pin, |
|
|
rt_ssize_t |
value |
|
) |
| |
write pin value
- Parameters
-
pin | the pin number |
value | the pin value |
◆ rt_pin_read()
rt_ssize_t rt_pin_read |
( |
rt_base_t |
pin | ) |
|
read pin value
- Parameters
-
- Returns
- rt_ssize_t the pin value
◆ rt_pin_get()
rt_base_t rt_pin_get |
( |
const char * |
name | ) |
|
get pin number by name
- Parameters
-
- Returns
- 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(*)(void *args) |
hdr, |
|
|
void * |
args |
|
) |
| |
bind the pin interrupt callback function
- Parameters
-
pin | the pin number |
mode | the irq mode |
hdr | the irq callback function |
args | the argument of the callback function |
- Returns
- 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
- Parameters
-
- Returns
- 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
- Parameters
-
pin | the pin number |
enabled | PIN_IRQ_ENABLE or PIN_IRQ_DISABLE |
- Returns
- 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
- Parameters
-
pin | the pin number |
debounce | time |
- Returns
- rt_err_t error code