RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dev_pin.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2024 RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2015-01-20 Bernard the first version
9 * 2017-10-20 ZYH add mode open drain and input pull down
10 */
11
12#ifndef DEV_PIN_H__
13#define DEV_PIN_H__
14
15#include <rtthread.h>
16
73
78#ifdef __cplusplus
79extern "C" {
80#endif
81
82#ifdef RT_USING_DM
83#include <drivers/pic.h>
84
85struct rt_pin_irqchip
86{
87 struct rt_pic parent;
88
89 int irq;
90 rt_base_t pin_range[2];
91};
92
93struct rt_pin_irq_hdr;
94#endif /* RT_USING_DM */
95
100{
102#ifdef RT_USING_DM
103 /* MUST keep the order member after parent */
104 struct rt_pin_irqchip irqchip;
105 /* Fill by DM */
106 rt_base_t pin_start;
107 rt_size_t pin_nr;
108 rt_list_t list;
109 struct rt_pin_irq_hdr *legacy_isr;
110#endif /* RT_USING_DM */
111 const struct rt_pin_ops *ops;
112};
113
114#define PIN_NONE (-1)
115
116#define PIN_LOW 0x00
117#define PIN_HIGH 0x01
118
119#define PIN_MODE_OUTPUT 0x00
120#define PIN_MODE_INPUT 0x01
121#define PIN_MODE_INPUT_PULLUP 0x02
122#define PIN_MODE_INPUT_PULLDOWN 0x03
123#define PIN_MODE_OUTPUT_OD 0x04
124
125#ifdef RT_USING_PINCTRL
126enum
127{
128 PIN_CONFIG_BIAS_BUS_HOLD,
129 PIN_CONFIG_BIAS_DISABLE,
130 PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
131 PIN_CONFIG_BIAS_PULL_DOWN,
132 PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
133 PIN_CONFIG_BIAS_PULL_UP,
134 PIN_CONFIG_DRIVE_OPEN_DRAIN,
135 PIN_CONFIG_DRIVE_OPEN_SOURCE,
136 PIN_CONFIG_DRIVE_PUSH_PULL,
137 PIN_CONFIG_DRIVE_STRENGTH,
138 PIN_CONFIG_DRIVE_STRENGTH_UA,
139 PIN_CONFIG_INPUT_DEBOUNCE,
140 PIN_CONFIG_INPUT_ENABLE,
141 PIN_CONFIG_INPUT_SCHMITT,
142 PIN_CONFIG_INPUT_SCHMITT_ENABLE,
143 PIN_CONFIG_MODE_LOW_POWER,
144 PIN_CONFIG_MODE_PWM,
145 PIN_CONFIG_OUTPUT,
146 PIN_CONFIG_OUTPUT_ENABLE,
147 PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS,
148 PIN_CONFIG_PERSIST_STATE,
149 PIN_CONFIG_POWER_SOURCE,
150 PIN_CONFIG_SKEW_DELAY,
151 PIN_CONFIG_SLEEP_HARDWARE_STATE,
152 PIN_CONFIG_SLEW_RATE,
153 PIN_CONFIG_END = 0x7f,
154 PIN_CONFIG_MAX = 0xff,
155};
156#endif /* RT_USING_PINCTRL */
157
158#define PIN_IRQ_MODE_RISING 0x00
159#define PIN_IRQ_MODE_FALLING 0x01
160#define PIN_IRQ_MODE_RISING_FALLING 0x02
161#define PIN_IRQ_MODE_HIGH_LEVEL 0x03
162#define PIN_IRQ_MODE_LOW_LEVEL 0x04
163
164#define PIN_IRQ_DISABLE 0x00
165#define PIN_IRQ_ENABLE 0x01
166
167#define PIN_IRQ_PIN_NONE PIN_NONE
168
173{
175 rt_uint8_t mode; /* e.g. PIN_MODE_OUTPUT */
176};
177
182{
184 rt_uint8_t value; /* PIN_LOW or PIN_HIGH */
185};
186
191{
193 rt_uint8_t mode; /* e.g. PIN_IRQ_MODE_RISING */
194 void (*hdr)(void *args);
195 void *args;
196};
197
198#ifdef RT_USING_PINCTRL
202struct rt_pin_ctrl_conf_params
203{
204 const char *propname;
205 rt_uint32_t param;
206 rt_uint32_t default_value;
207};
208#endif /* RT_USING_PINCTRL */
209
214{
215 void (*pin_mode)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode);
216 void (*pin_write)(struct rt_device *device, rt_base_t pin, rt_uint8_t value);
217 rt_ssize_t (*pin_read)(struct rt_device *device, rt_base_t pin);
219 rt_uint8_t mode, void (*hdr)(void *args), void *args);
221 rt_err_t (*pin_irq_enable)(struct rt_device *device, rt_base_t pin, rt_uint8_t enabled);
222 rt_base_t (*pin_get)(const char *name);
223 rt_err_t (*pin_debounce)(struct rt_device *device, rt_base_t pin, rt_uint32_t debounce);
224#ifdef RT_USING_DM
225 rt_err_t (*pin_irq_mode)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode);
226 rt_ssize_t (*pin_parse)(struct rt_device *device, struct rt_ofw_cell_args *args, rt_uint32_t *flags);
227#endif
228#ifdef RT_USING_PINCTRL
229 rt_err_t (*pin_ctrl_confs_apply)(struct rt_device *device, void *fw_conf_np);
230#endif /* RT_USING_PINCTRL */
231};
232
240int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data);
241
248
255
262
268rt_base_t rt_pin_get(const char *name);
269
279 void (*hdr)(void *args), void *args);
280
287
295
303
304#ifdef RT_USING_DM
305rt_ssize_t rt_pin_get_named_pin(struct rt_device *dev, const char *propname, int index,
306 rt_uint8_t *out_mode, rt_uint8_t *out_value);
307rt_ssize_t rt_pin_get_named_pin_count(struct rt_device *dev, const char *propname);
308
309#ifdef RT_USING_OFW
310rt_ssize_t rt_ofw_get_named_pin(struct rt_ofw_node *np, const char *propname, int index,
311 rt_uint8_t *out_mode, rt_uint8_t *out_value);
312rt_ssize_t rt_ofw_get_named_pin_count(struct rt_ofw_node *np, const char *propname);
313#endif
314#endif /* RT_USING_DM */
315
316#ifdef RT_USING_PINCTRL
317rt_ssize_t rt_pin_ctrl_confs_lookup(struct rt_device *device, const char *name);
318rt_err_t rt_pin_ctrl_confs_apply(struct rt_device *device, int index);
319rt_err_t rt_pin_ctrl_confs_apply_by_name(struct rt_device *device, const char *name);
320#endif /* RT_USING_PINCTRL */
321
322#ifdef __cplusplus
323}
324#endif
325
327
328#endif
int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data)
register a pin device
rt_err_t rt_pin_detach_irq(rt_base_t pin)
detach the pin interrupt callback function
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
rt_base_t rt_pin_get(const char *name)
get pin number by name
rt_err_t rt_pin_debounce(rt_base_t pin, rt_uint32_t debounce)
set the pin's debounce time
rt_ssize_t rt_pin_read(rt_base_t pin)
read pin value
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
rt_base_t rt_ssize_t
rt_int32_t rt_base_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
rt_ubase_t rt_size_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
pin mode structure
pin value structure
pin device structure
const struct rt_pin_ops * ops
struct rt_device parent
void * user_data
pin irq structure
rt_uint8_t mode
void(* hdr)(void *args)
pin device operations
rt_err_t(* pin_irq_enable)(struct rt_device *device, rt_base_t pin, rt_uint8_t enabled)
rt_ssize_t(* pin_read)(struct rt_device *device, rt_base_t pin)
rt_err_t(* pin_debounce)(struct rt_device *device, rt_base_t pin, rt_uint32_t debounce)
rt_err_t(* pin_detach_irq)(struct rt_device *device, rt_base_t pin)
void(* pin_write)(struct rt_device *device, rt_base_t pin, rt_uint8_t value)
rt_err_t(* pin_attach_irq)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode, void(*hdr)(void *args), void *args)
rt_base_t(* pin_get)(const char *name)
void(* pin_mode)(struct rt_device *device, rt_base_t pin, rt_uint8_t mode)