项目场景:
移植时发现原厂驱动未提供Kconfig文件,自己添加一个。
代码实现:
# SPDX-License-Identifier: GPL-2.0-only
#
# Touchscreen driver configuration
#
menu "Touchscreen Drivers"
config TOUCHSCREEN_SUPPORT
bool "Touchscreen Support"
help
Enable this option to add support for touchscreen devices.
If you don't have a touchscreen, you can safely say N here.
if TOUCHSCREEN_SUPPORT
config TOUCHSCREEN_GENERIC_DRIVER
tristate "Generic Touchscreen Driver"
depends on I2C || SPI || USB
default n
help
This is a generic touchscreen driver that supports a wide range of
touchscreen devices. You can enable this if your touchscreen device
is supported by this generic driver. If unsure, say N.
config TOUCHSCREEN_CUSTOM_DRIVER
tristate "Custom Touchscreen Driver for XYZ Device"
depends on I2C
default n
help
This driver provides support for the XYZ touchscreen device connected
via the I2C bus. If you have the XYZ touchscreen, enable this option.
If unsure, say N.
config TOUCHSCREEN_USB
tristate "USB Touchscreen Driver"
depends on USB
help
Enable this option if you have a touchscreen connected over USB.
config TOUCHSCREEN_DEBUG
bool "Enable Touchscreen Debugging"
default n
help
Enable debug logging for touchscreen drivers. Useful for diagnosing
issues during development. If unsure, say N.
endif # TOUCHSCREEN_SUPPORT
endmenu
语句详解:
menu 和 endmenu:定义一个触摸屏驱动相关的菜单。在内核配置工具(如 make menuconfig 或 make xconfig)中,所有配置项会显示在 "Touchscreen Drivers" 菜单下。
config TOUCHSCREEN_SUPPORT:顶层选项,用于控制是否启用触摸屏支持。如果这个选项未启用,所有相关的触摸屏配置都将被跳过。
tristate 类型:tristate 表示该配置项可以有三个值:y: 内置到内核。m: 编译为模块。n: 不启用。
依赖(depends on):表示某些选项的启用依赖于其他内核配置。例如,TOUCHSCREEN_GENERIC_DRIVER 依赖于 I2C、SPI 或 USB 子系统。
default n:
配置的默认值为 n(未启用)。用户需要主动选择启用。
帮助信息(help):
为每个配置提供简要说明,帮助开发人员或用户理解该选项的功能及其适用场景。
调试选项:
TOUCHSCREEN_DEBUG 提供一个布尔选项,用于启用触摸屏驱动的调试日志,方便开发人员在调试过程中使用。
具体使用:
- 将以上内容保存为 Kconfig 文件(例如放置在 drivers/input/touchscreen/Kconfig 路径下)。
- 在上层的 Kconfig 文件中(如 drivers/input/Kconfig),需要通过 source "drivers/input/touchscreen/Kconfig" 引入该文件。
- 配置内核时(运行 make menuconfig 或类似工具),触摸屏驱动相关的选项将出现在配置菜单中。