[dm][input] support input #11031

This commit is contained in:
GUI
2025-12-10 16:58:10 +08:00
committed by GitHub
parent 357c9b7b5a
commit 3ff3fc3948
19 changed files with 2207 additions and 0 deletions
+1
View File
@@ -22,6 +22,7 @@ rsource "graphic/Kconfig"
rsource "hwcrypto/Kconfig"
rsource "wlan/Kconfig"
rsource "led/Kconfig"
rsource "input/Kconfig"
rsource "mailbox/Kconfig"
rsource "phye/Kconfig"
rsource "ata/Kconfig"
File diff suppressed because it is too large Load Diff
+7
View File
@@ -53,7 +53,14 @@ extern "C" {
#ifdef RT_USING_LED
#include "drivers/led.h"
#endif /* RT_USING_LED */
#ifdef RT_USING_INPUT
#include "drivers/input.h"
#ifdef RT_INPUT_UAPI
#include "drivers/input_uapi.h"
#endif
#endif /* RT_USING_INPUT */
#ifdef RT_USING_MBOX
#include "drivers/mailbox.h"
+36
View File
@@ -0,0 +1,36 @@
menuconfig RT_USING_INPUT
bool "Using Input device drivers"
depends on RT_USING_DM
select RT_USING_ADT
select RT_USING_ADT_BITMAP
default n
config RT_INPUT_POWER
bool "Input event power"
depends on RT_USING_INPUT
default y
config RT_INPUT_UAPI
bool "Input event Unix API"
depends on RT_USING_INPUT
depends on RT_USING_KTIME
depends on RT_USING_POSIX_DEVIO
default n
default y if RT_USING_SMART
config RT_INPUT_UAPI_EVENT_MAX
int "Events storage max"
depends on RT_INPUT_UAPI
default 128
config RT_UAPI_FAKE_BLOCK
bool "Events fake when block"
depends on RT_INPUT_UAPI
default y
if RT_USING_INPUT
rsource "joystick/Kconfig"
rsource "keyboard/Kconfig"
rsource "misc/Kconfig"
rsource "touchscreen/Kconfig"
endif
+32
View File
@@ -0,0 +1,32 @@
from building import *
group = []
objs = []
if not GetDepend(['RT_USING_INPUT']):
Return('group')
cwd = GetCurrentDir()
list = os.listdir(cwd)
CPPPATH = [cwd + '/../include']
src = ['input.c']
if GetDepend(['RT_INPUT_POWER']):
src += ['input_power.c']
if GetDepend(['RT_INPUT_TOUCHSCREEN']):
src += ['input_touch.c']
if GetDepend(['RT_INPUT_UAPI']):
src += ['input_uapi.c']
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
objs = objs + group
Return('objs')
File diff suppressed because it is too large Load Diff
+130
View File
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#define DBG_TAG "input.power"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
struct input_event_cap
{
rt_uint16_t code;
rt_int32_t value;
rt_int32_t current;
};
static rt_bool_t power_input_identify(struct rt_input_handler *handler,
struct rt_input_device *idev)
{
struct input_event_cap *cap = handler->priv;
if (rt_bitmap_test_bit(idev->key_map, cap->code))
{
if (cap->value == cap->current)
{
return RT_TRUE;
}
++cap->current;
}
return RT_FALSE;
}
static rt_bool_t power_input_callback(struct rt_input_handler *handler,
struct rt_input_event *ev)
{
if (ev->code == KEY_POWER)
{
if (ev->value == 0)
{
rt_hw_cpu_shutdown();
}
return RT_TRUE;
}
else if (ev->code == KEY_RESTART)
{
if (ev->value == 0)
{
rt_hw_cpu_reset();
}
return RT_TRUE;
}
return RT_FALSE;
}
static rt_bool_t power_test_cap(struct rt_input_handler *handler,
struct rt_input_device *idev)
{
struct input_event_cap *cap = handler->priv;
if (rt_bitmap_test_bit(idev->key_map, cap->code))
{
++cap->value;
}
return RT_FALSE;
}
static void power_handler_install(rt_uint16_t code)
{
rt_uint32_t idev_count;
struct input_event_cap cap;
struct rt_input_handler tmp_handler, *handlers;
cap.code = code;
cap.value = 0;
tmp_handler.idev = RT_NULL;
tmp_handler.identify = &power_test_cap;
tmp_handler.callback = &power_input_callback;
tmp_handler.priv = &cap;
rt_input_add_handler(&tmp_handler); /* Just test */
if (!(idev_count = cap.value))
{
return;
}
handlers = rt_calloc(idev_count, sizeof(*handlers));
if (!handlers)
{
LOG_E("No memory to install power handler");
return;
}
for (int i = 0; i < idev_count; ++i, ++handlers)
{
cap.value = i;
cap.current = 0;
handlers->identify = &power_input_identify;
handlers->callback = &power_input_callback;
handlers->priv = &cap;
rt_input_add_handler(handlers);
handlers->priv = RT_NULL;
}
}
static int input_event_power_init(void)
{
power_handler_install(KEY_POWER);
power_handler_install(KEY_RESTART);
return 0;
}
INIT_ENV_EXPORT(input_event_power_init);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,7 @@
menuconfig RT_INPUT_JOYSTICK
bool "Joystick"
default n
if RT_INPUT_JOYSTICK
osource "$(SOC_DM_INPUT_JOYSTICK_DIR)/Kconfig"
endif
@@ -0,0 +1,15 @@
from building import *
group = []
if not GetDepend(['RT_INPUT_JOYSTICK']):
Return('group')
cwd = GetCurrentDir()
CPPPATH = [cwd + '/../../include']
src = []
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
+13
View File
@@ -0,0 +1,13 @@
menuconfig RT_INPUT_KEYBOARD
bool "Keyboards"
default n
config RT_INPUT_KEYBOARD_GPIO
bool "GPIO"
depends on RT_INPUT_KEYBOARD
depends on RT_USING_OFW
default n
if RT_INPUT_KEYBOARD
osource "$(SOC_DM_INPUT_KEYBOARD_DIR)/Kconfig"
endif
@@ -0,0 +1,18 @@
from building import *
group = []
if not GetDepend(['RT_INPUT_KEYBOARD']):
Return('group')
cwd = GetCurrentDir()
CPPPATH = [cwd + '/../../include']
src = []
if GetDepend(['RT_INPUT_KEYBOARD_GPIO']):
src += ['keys-gpio.c']
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
@@ -0,0 +1,163 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#define DBG_TAG "input.keyboard.gpio"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
struct gpio_key
{
struct rt_input_device parent;
rt_base_t pin;
rt_uint8_t mode;
rt_uint32_t code;
};
static void gpio_key_event(void *data)
{
struct gpio_key *gkey = data;
rt_input_report_key(&gkey->parent, gkey->code, 1);
rt_input_sync(&gkey->parent);
rt_input_report_key(&gkey->parent, gkey->code, 0);
rt_input_sync(&gkey->parent);
}
static rt_err_t ofw_append_gpio_key(struct rt_ofw_node *np)
{
rt_err_t err = RT_EOK;
rt_uint32_t debounce;
const char *propname;
struct gpio_key *gkey = rt_calloc(1, sizeof(*gkey));
if (!gkey)
{
return -RT_ENOMEM;
}
gkey->pin = rt_ofw_get_named_pin(np, RT_NULL, 0, &gkey->mode, RT_NULL);
if (gkey->pin < 0)
{
err = gkey->pin;
goto _fail;
}
if ((propname = rt_ofw_get_prop_fuzzy_name(np, ",code$")) &&
!rt_ofw_prop_read_u32(np, propname, &gkey->code))
{
rt_input_set_capability(&gkey->parent, EV_KEY, gkey->code);
if (!(err = rt_input_device_register(&gkey->parent)))
{
err = rt_pin_attach_irq(gkey->pin, gkey->mode, gpio_key_event, gkey);
if (err)
{
rt_input_device_unregister(&gkey->parent);
goto _fail;
}
rt_pin_irq_enable(gkey->pin, RT_TRUE);
}
}
if (err)
{
goto _fail;
}
if (!rt_ofw_prop_read_u32(np, "debounce-interval", &debounce))
{
rt_pin_debounce(gkey->pin, debounce);
}
rt_ofw_data(np) = gkey;
return RT_EOK;
_fail:
rt_free(gkey);
return err;
}
static rt_err_t gpio_key_probe(struct rt_platform_device *pdev)
{
rt_err_t err = RT_EOK;
struct rt_ofw_node *key_np, *np = pdev->parent.ofw_node;
rt_ofw_foreach_available_child_node(np, key_np)
{
err = ofw_append_gpio_key(key_np);
if (err == -RT_ENOMEM)
{
rt_ofw_node_put(key_np);
return err;
}
else if (err)
{
LOG_E("%s: create KEY fail", rt_ofw_node_full_name(key_np));
continue;
}
}
return err;
}
static rt_err_t gpio_key_remove(struct rt_platform_device *pdev)
{
struct rt_ofw_node *key_np, *np = pdev->parent.ofw_node;
rt_ofw_foreach_available_child_node(np, key_np)
{
struct gpio_key *gkey = rt_ofw_data(key_np);
if (!gkey)
{
continue;
}
rt_ofw_data(key_np) = RT_NULL;
rt_pin_irq_enable(gkey->pin, RT_FALSE);
rt_pin_detach_irq(gkey->pin);
rt_input_device_unregister(&gkey->parent);
rt_free(gkey);
}
return RT_EOK;
}
static const struct rt_ofw_node_id gpio_key_ofw_ids[] =
{
{ .compatible = "gpio-keys" },
{ /* sentinel */ }
};
static struct rt_platform_driver gpio_key_driver =
{
.name = "gpio-keys",
.ids = gpio_key_ofw_ids,
.probe = gpio_key_probe,
.remove = gpio_key_remove,
};
RT_PLATFORM_DRIVER_EXPORT(gpio_key_driver);
+12
View File
@@ -0,0 +1,12 @@
menuconfig RT_INPUT_MISC
bool "Misc"
default n
config RT_INPUT_MISC_BUTTON_E3X0
bool "NI Ettus Research USRP E3xx Button support"
depends on RT_INPUT_MISC
default n
if RT_INPUT_MISC
osource "$(SOC_DM_INPUT_MISC_DIR)/Kconfig"
endif
+18
View File
@@ -0,0 +1,18 @@
from building import *
group = []
if not GetDepend(['RT_INPUT_MISC']):
Return('group')
cwd = GetCurrentDir()
CPPPATH = [cwd + '/../../include']
src = []
if GetDepend(['RT_INPUT_MISC_BUTTON_E3X0']):
src += ['button-e3x0.c']
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
+115
View File
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2022-3-08 GuEe-GUI the first version
*/
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
struct e3x0_button
{
struct rt_input_device parent;
int press_irq, release_irq;
};
static void e3x0_button_press_isr(int irqno, void *param)
{
struct e3x0_button *btn = param;
rt_input_report_key(&btn->parent, KEY_POWER, 1);
rt_input_sync(&btn->parent);
}
static void e3x0_button_release_isr(int irqno, void *param)
{
struct e3x0_button *btn = param;
rt_input_report_key(&btn->parent, KEY_POWER, 0);
rt_input_sync(&btn->parent);
}
static rt_err_t e3x0_button_probe(struct rt_platform_device *pdev)
{
rt_err_t err;
struct rt_device *dev = &pdev->parent;
struct e3x0_button *btn = rt_calloc(1, sizeof(*btn));
if (!btn)
{
return -RT_ENOMEM;
}
if ((btn->press_irq = rt_dm_dev_get_irq_by_name(dev, "press")) < 0)
{
err = btn->press_irq;
goto _fail;
}
if ((btn->release_irq = rt_dm_dev_get_irq_by_name(dev, "release")) < 0)
{
err = btn->release_irq;
goto _fail;
}
rt_input_set_capability(&btn->parent, EV_KEY, KEY_POWER);
if ((err = rt_input_device_register(&btn->parent)))
{
goto _fail;
}
dev->user_data = btn;
rt_hw_interrupt_install(btn->press_irq, e3x0_button_press_isr, btn, "button-e3x0-press");
rt_hw_interrupt_umask(btn->press_irq);
rt_hw_interrupt_install(btn->release_irq, e3x0_button_release_isr, btn, "button-e3x0-release");
rt_hw_interrupt_umask(btn->release_irq);
return RT_EOK;
_fail:
rt_free(btn);
return err;
}
static rt_err_t e3x0_button_remove(struct rt_platform_device *pdev)
{
struct e3x0_button *btn = pdev->parent.user_data;
rt_hw_interrupt_mask(btn->press_irq);
rt_pic_detach_irq(btn->press_irq, btn);
rt_hw_interrupt_mask(btn->release_irq);
rt_pic_detach_irq(btn->release_irq, btn);
rt_input_device_unregister(&btn->parent);
rt_free(btn);
return RT_EOK;
}
static const struct rt_ofw_node_id e3x0_button_ofw_ids[] =
{
{ .compatible = "ettus,e3x0-button" },
{ /* sentinel */ }
};
static struct rt_platform_driver e3x0_button_driver =
{
.name = "e3x0-button",
.ids = e3x0_button_ofw_ids,
.probe = e3x0_button_probe,
.remove = e3x0_button_remove,
};
RT_PLATFORM_DRIVER_EXPORT(e3x0_button_driver);
@@ -0,0 +1,8 @@
menuconfig RT_INPUT_TOUCHSCREEN
bool "Touchscreens"
select RT_USING_TOUCH
default n
if RT_INPUT_TOUCHSCREEN
osource "$(SOC_DM_INPUT_TOUCHSCREEN_DIR)/Kconfig"
endif
@@ -0,0 +1,15 @@
from building import *
group = []
if not GetDepend(['RT_INPUT_TOUCHSCREEN']):
Return('group')
cwd = GetCurrentDir()
CPPPATH = [cwd + '/../../include']
src = []
group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH)
Return('group')