2022-06-04 17:04:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021-2022, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-06-03 supperthomas first version
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-09-14 15:49:05 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rtdevice.h>
|
|
|
|
#include "driver/gpio.h"
|
2022-06-04 17:04:19 +08:00
|
|
|
|
2022-09-14 15:49:05 +08:00
|
|
|
#ifdef RT_USING_PIN
|
2022-06-04 17:04:19 +08:00
|
|
|
|
2023-04-07 11:42:05 +08:00
|
|
|
static void mcu_pin_write(rt_device_t dev, rt_base_t pin, rt_uint8_t value)
|
2022-06-04 17:04:19 +08:00
|
|
|
{
|
|
|
|
gpio_set_level(pin, value);
|
|
|
|
/*TODO:set gpio out put mode */
|
|
|
|
}
|
|
|
|
|
2023-04-07 11:42:05 +08:00
|
|
|
static rt_int8_t mcu_pin_read(rt_device_t dev, rt_base_t pin)
|
2022-06-04 17:04:19 +08:00
|
|
|
{
|
2023-04-07 11:42:05 +08:00
|
|
|
rt_int8_t value;
|
2022-06-04 17:04:19 +08:00
|
|
|
value = gpio_get_level(pin);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2023-04-07 11:42:05 +08:00
|
|
|
static void mcu_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode)
|
2022-06-04 17:04:19 +08:00
|
|
|
{
|
|
|
|
gpio_config_t io_conf;
|
|
|
|
io_conf.intr_type = GPIO_INTR_DISABLE;
|
|
|
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
|
|
|
io_conf.pin_bit_mask = (1ULL << pin);
|
|
|
|
io_conf.pull_down_en = 0;
|
|
|
|
io_conf.pull_up_en = 0;
|
|
|
|
gpio_config(&io_conf);
|
|
|
|
if (mode == PIN_MODE_OUTPUT)
|
|
|
|
{
|
|
|
|
gpio_set_direction(pin, GPIO_MODE_OUTPUT);
|
|
|
|
}
|
|
|
|
/*TODO:set gpio out put mode */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-04-07 11:42:05 +08:00
|
|
|
static rt_err_t mcu_pin_attach_irq(struct rt_device *device, rt_base_t pin,
|
|
|
|
rt_uint8_t irq_mode, void (*hdr)(void *args), void *args)
|
2022-06-04 17:04:19 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
/*TODO: start irq handle */
|
2023-04-07 11:42:05 +08:00
|
|
|
return -RT_ENOSYS;
|
2022-06-04 17:04:19 +08:00
|
|
|
}
|
|
|
|
|
2023-10-23 20:29:15 +08:00
|
|
|
static rt_err_t mcu_pin_detach_irq(struct rt_device *device, rt_base_t pin)
|
2022-06-04 17:04:19 +08:00
|
|
|
{
|
|
|
|
/*TODO:disable gpio irq handle */
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static rt_err_t mcu_pin_irq_enable(struct rt_device *device, rt_base_t pin,
|
2023-04-07 11:42:05 +08:00
|
|
|
rt_uint8_t enabled)
|
2022-06-04 17:04:19 +08:00
|
|
|
{
|
|
|
|
/*TODO:start irq handle */
|
|
|
|
return RT_EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
const static struct rt_pin_ops _mcu_pin_ops =
|
|
|
|
{
|
|
|
|
mcu_pin_mode,
|
|
|
|
mcu_pin_write,
|
|
|
|
mcu_pin_read,
|
|
|
|
mcu_pin_attach_irq,
|
2023-04-07 11:42:05 +08:00
|
|
|
mcu_pin_detach_irq,
|
2022-06-04 17:04:19 +08:00
|
|
|
mcu_pin_irq_enable,
|
2022-12-13 06:12:20 +08:00
|
|
|
RT_NULL,
|
2022-06-04 17:04:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int rt_hw_pin_init(void)
|
|
|
|
{
|
|
|
|
/*TODO: INIT THE GPIO CLOCK AND OTHER */
|
|
|
|
return rt_device_pin_register("pin", &_mcu_pin_ops, RT_NULL);
|
|
|
|
}
|
|
|
|
INIT_BOARD_EXPORT(rt_hw_pin_init);
|
|
|
|
|
|
|
|
#endif /* RT_USING_PIN */
|