2021-01-28 22:09:28 +08:00
|
|
|
/*
|
2021-01-28 22:22:57 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2021-01-28 22:09:28 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-01-28 22:22:57 +08:00
|
|
|
* 2021-01-28 flybreak first version
|
2021-01-28 22:09:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "drv_gpio.h"
|
|
|
|
|
2023-05-09 11:35:27 +08:00
|
|
|
static void pico_pin_mode(struct rt_device *dev, rt_base_t pin, rt_uint8_t mode)
|
2021-01-28 22:09:28 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-09 11:35:27 +08:00
|
|
|
static void pico_pin_write(struct rt_device *dev, rt_base_t pin, rt_uint8_t value)
|
2021-01-28 22:09:28 +08:00
|
|
|
{
|
|
|
|
RT_ASSERT((0 <= pin) && (pin < N_GPIOS));
|
|
|
|
gpio_put(pin, value);
|
|
|
|
}
|
|
|
|
|
2023-05-09 11:35:27 +08:00
|
|
|
static rt_int8_t pico_pin_read(struct rt_device *device, rt_base_t pin)
|
2021-01-28 22:09:28 +08:00
|
|
|
{
|
|
|
|
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);
|