mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-03-27 01:10:20 +08:00
[bsp][raspberry-pico]add gpio drivers
This commit is contained in:
67
bsp/raspberry-pico/drivers/drv_gpio.c
Normal file
67
bsp/raspberry-pico/drivers/drv_gpio.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2019, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-07-29 zdzn 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);
|
||||
21
bsp/raspberry-pico/drivers/drv_gpio.h
Normal file
21
bsp/raspberry-pico/drivers/drv_gpio.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2019, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2019-07-29 zdzn first version
|
||||
*/
|
||||
|
||||
#ifndef __DRV_GPIO_H__
|
||||
#define __DRV_GPIO_H__
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "board.h"
|
||||
|
||||
int rt_hw_gpio_init(void);
|
||||
|
||||
#endif /* __DRV_GPIO_H__ */
|
||||
Reference in New Issue
Block a user