1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-01-28 flybreak first version
*/
#include "drv_gpio.h"
static void pico_pin_mode(struct rt_device *dev, rt_base_t pin, rt_base_t mode)
{
RT_ASSERT((0 <= pin) && (pin < N_GPIOS));
gpio_init(pin);
switch (mode)
{
case PIN_MODE_OUTPUT:
gpio_set_dir(pin, GPIO_OUT);
break;
case PIN_MODE_INPUT:
gpio_set_dir(pin, GPIO_IN);
break;
case PIN_MODE_INPUT_PULLUP:
gpio_pull_up(pin);
break;
case PIN_MODE_INPUT_PULLDOWN:
gpio_pull_down(pin);
break;
case PIN_MODE_OUTPUT_OD:
gpio_disable_pulls(pin);
break;
}
}
static void pico_pin_write(struct rt_device *dev, rt_base_t pin, rt_base_t value)
{
RT_ASSERT((0 <= pin) && (pin < N_GPIOS));
gpio_put(pin, value);
}
static int pico_pin_read(struct rt_device *device, rt_base_t pin)
{
RT_ASSERT((0 <= pin) && (pin < N_GPIOS));
return (gpio_get(pin)? PIN_HIGH : PIN_LOW);
}
static const struct rt_pin_ops ops =
{
pico_pin_mode,
pico_pin_write,
pico_pin_read,
RT_NULL,
RT_NULL,
RT_NULL,
RT_NULL,
};
int rt_hw_gpio_init(void)
{
rt_device_pin_register("gpio", &ops, RT_NULL);
return 0;
}
INIT_DEVICE_EXPORT(rt_hw_gpio_init);
|