Skip to content

[DM/Input] Add ADC joystick, keyboard, and touchscreen drivers - #11679

Open
GuEe-GUI wants to merge 2 commits into
RT-Thread:masterfrom
GuEe-GUI:input
Open

[DM/Input] Add ADC joystick, keyboard, and touchscreen drivers#11679
GuEe-GUI wants to merge 2 commits into
RT-Thread:masterfrom
GuEe-GUI:input

Conversation

@GuEe-GUI

@GuEe-GUI GuEe-GUI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

[
Add polling input drivers for ADC-connected joysticks and resistor- ladder keys. Parse Linux-compatible device-tree bindings, acquire ADC channels through the IIO framework, and report absolute-axis and key events.

Add an SPI touchscreen driver for ADS7843, ADS7845, ADS7846, ADS7873, TSC2046, and XPT2046-compatible controllers. Support pen interrupts, coordinate and pressure reporting, sample filtering, regulator control, power management, and common touchscreen properties.

Add an I2C touchscreen driver for Goodix GT9xx controllers with multi-touch reporting, GPIO-based reset and address selection, interrupt handling with polling fallback, regulator control, panel configuration, and alternate-address recovery.

Adapt the drivers to the RT-Thread device model and input framework, following the corresponding Linux input drivers and device-tree bindings.

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用clang-format 源码格式化工具确保格式符合RT-Thread代码规范 This PR has been formatted with clang-format and complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

Add polling input drivers for ADC-connected joysticks and resistor-
ladder keys. Parse Linux-compatible device-tree bindings, acquire ADC
channels through the IIO framework, and report absolute-axis and key
events.

Add an SPI touchscreen driver for ADS7843, ADS7845, ADS7846, ADS7873,
TSC2046, and XPT2046-compatible controllers. Support pen interrupts,
coordinate and pressure reporting, sample filtering, regulator control,
power management, and common touchscreen properties.

Add an I2C touchscreen driver for Goodix GT9xx controllers with
multi-touch reporting, GPIO-based reset and address selection, interrupt
handling with polling fallback, regulator control, panel configuration,
and alternate-address recovery.

Adapt the drivers to the RT-Thread device model and input framework,
following the corresponding Linux input drivers and device-tree
bindings.

Signed-off-by: GuEe-GUI <2991707448@qq.com>
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: components

Reviewers: @Maihuanyi

Changed Files (Click to expand)
  • components/drivers/input/joystick/Kconfig
  • components/drivers/input/joystick/SConscript
  • components/drivers/input/joystick/js-adc.c
  • components/drivers/input/keyboard/Kconfig
  • components/drivers/input/keyboard/SConscript
  • components/drivers/input/keyboard/keys-adc.c
  • components/drivers/input/touchscreen/Kconfig
  • components/drivers/input/touchscreen/SConscript
  • components/drivers/input/touchscreen/ts-ads7846.c
  • components/drivers/input/touchscreen/ts-goodix.c

📊 Current Review Status (Last Updated: 2026-08-07 00:16 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:input
  • 设置PR number为 \ Set the PR number to:11679
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 input 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the input branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gd32105r-start

  • CODE: .text -104 B (-0.1%, 69,260 B / 262,144 B, total: 26% used)

hc32f334

  • FLASH: .text -104 B (-0.1%, 99,460 B / 131,072 B, total: 76% used)

infineon-psoc6

  • flash: .text -104 B (-0.1%, 116,104 B / 262,144 B, total: 44% used)

k230

  • SRAM: .eh_frame -48 B, .text -32 B (-0.0%, 1,122,651 B / 268,300,288 B, total: 0% used)

loongson-ls1cdev

  • Code: .text -136 B (-0.0%, 362,632 B)

nuvoton-m487

  • CODE: .text -116 B (-0.0%, 355,696 B / 524,288 B, total: 68% used)

qemu-virt64-aarch64

  • Code: .eh_frame +72 B, .text +576 B (+0.1%, 1,057,132 B)
  • Data: .data +8 B (+0.0%, 517,384 B)

raspberry-pico-rp2040

  • FLASH: .rodata -24 B, .text -112 B (-0.1%, 114,064 B / 2,097,152 B, total: 5% used)

simulator

  • Code: .eh_frame +32 B, .eh_frame_hdr +8 B, .rela.dyn -96 B, .text +171 B (+0.0%, 2,634,218 B)
  • Data: .data -128 B (-0.0%, 1,583,108 B)

stm32f407-rt-spark

  • CODE: .text -104 B (-0.1%, 85,728 B / 1,048,576 B, total: 8% used)

stm32l475-atk-pandora-llvm

  • ROM: .text -124 B (-0.1%, 83,384 B / 524,288 B, total: 16% used)

x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds several new Device Model (DM) input drivers to RT-Thread, targeting Linux-compatible device-tree bindings and integrating with RT-Thread’s input/touch frameworks.

Changes:

  • Add a Goodix GT9xx-series I2C capacitive touchscreen driver with multi-touch reporting.
  • Add an ADS784x/XPT2046/TSC2046 SPI resistive touchscreen driver with filtering, pen IRQ handling, and optional PM hooks.
  • Add polling input drivers for ADC ladder keys and ADC joysticks, plus corresponding Kconfig/SConscript integration.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
components/drivers/input/touchscreen/ts-goodix.c New Goodix GT9xx I2C touchscreen driver implementation
components/drivers/input/touchscreen/ts-ads7846.c New ADS784x/XPT2046/TSC2046 SPI touchscreen driver implementation
components/drivers/input/touchscreen/SConscript Build integration for new touchscreen drivers
components/drivers/input/touchscreen/Kconfig Kconfig options for new touchscreen drivers
components/drivers/input/keyboard/SConscript Build integration for ADC keyboard driver
components/drivers/input/keyboard/keys-adc.c New ADC ladder-button (resistor ladder) keyboard driver
components/drivers/input/keyboard/Kconfig Kconfig option for ADC keyboard driver
components/drivers/input/joystick/SConscript Build integration for ADC joystick driver
components/drivers/input/joystick/Kconfig Kconfig option for ADC joystick driver
components/drivers/input/joystick/js-adc.c New ADC joystick driver
Suppressed comments (4)

components/drivers/input/touchscreen/ts-ads7846.c:403

  • [bug/缺陷]: Wrong success/failure handling for rt_spi_transfer_message()

English: rt_spi_transfer_message() returns RT_NULL on success and a non-NULL pointer on failure (dev_spi.h). The current code converts that to 0/1 and returns 1 on failure, which can be misinterpreted as a valid sample. Return a negative error on failure.
中文:rt_spi_transfer_message() 成功返回 RT_NULL,失败返回非空指针(见 dev_spi.h)。当前代码将其转换为 0/1,失败时返回 1,可能被误认为是有效采样值。应在失败时返回负错误码。

        status = rt_spi_transfer_message(ts->spi, &req.msg[0]) != RT_NULL;

components/drivers/input/touchscreen/ts-ads7846.c:442

  • [bug/缺陷]: Wrong success/failure handling for rt_spi_transfer_message() (main sample transfer)

English: Same issue as above: the transfer result is converted to 0/1 instead of 0/negative errno. On failure, return -RT_EIO so callers don’t treat it as a small ADC value.
中文:同上问题:SPI 传输结果被转换成 0/1,而不是 0/负错误码。失败时应返回 -RT_EIO,避免被当作较小的 ADC 采样值。

    status = rt_spi_transfer_message(ts->spi, &req.msg[0]) != RT_NULL;

components/drivers/input/touchscreen/ts-ads7846.c:469

  • [bug/缺陷]: Wrong success/failure handling for rt_spi_transfer_message() in ads7845_read12_ser()

English: ads7845_read12_ser() returns 1 on SPI failure due to != RT_NULL. Return a negative error instead.
中文:ads7845_read12_ser() 由于使用 != RT_NULL,在 SPI 失败时会返回 1。建议改为返回负错误码。

    status = rt_spi_transfer_message(ts->spi, &req.msg[0]) != RT_NULL;

components/drivers/input/touchscreen/Kconfig:16

  • [bug/缺陷]: Missing Kconfig dependencies for Goodix touchscreen driver

English: ts-goodix.c uses OFW/PIN helpers and regulator types/APIs. Add depends on RT_USING_OFW, RT_USING_PIN, and RT_USING_REGULATOR to avoid build break when those components are off.
中文:ts-goodix.c 使用了 OFW/PIN 辅助接口以及 regulator 相关类型/接口。建议增加 depends on RT_USING_OFWRT_USING_PINRT_USING_REGULATOR,避免在这些组件未开启时编译失败。

config RT_INPUT_TOUCHSCREEN_GOODIX
    bool "Goodix GT9xx capacitive touch screen support"
    depends on RT_INPUT_TOUCHSCREEN
    depends on RT_USING_I2C
    default n

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

int *touch_num_out)
{
rt_uint16_t addr = GOODIX_READ_COOR_ADDR;
rt_size_t header_size = 1 + ts->contact_size + 1;

packet->last_cmd_idx = 0;

while (true)
Comment on lines +305 to +319
rt_inline void ads7846_disable(struct ads7846 *ts)
{
ads7846_stop(ts);
rt_regulator_disable(ts->supply);
}

rt_inline void ads7846_enable(struct ads7846 *ts)
{
if (rt_regulator_enable(ts->supply))
{
LOG_E("%s: Failed to enable supply", rt_dm_dev_get_name(&ts->spi->parent));
}

ads7846_restart(ts);
}
Comment on lines +1068 to +1071
if ((err = rt_regulator_enable(ts->supply)))
{
goto _free_regulator;
}
Comment on lines +6 to +10
config RT_INPUT_TOUCHSCREEN_ADS7846
bool "TI ADS7843/45/46/73 XPT/TSC2046 touch screen support"
depends on RT_INPUT_TOUCHSCREEN
depends on RT_USING_SPI
default n
Comment on lines +5 to +9
config RT_INPUT_JOYSTICK_ADC
bool "Simple joystick connected over ADC"
depends on RT_INPUT_JOYSTICK
depends on RT_USING_ADC
default n
Comment on lines +137 to +138
LOG_E("%s: Key with invalid or missing %s",
rt_ofw_node_full_name(key_np), "voltage");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants