Notes
main
main
  • Introduction
  • linuxKernel
    • tips
    • make_help
    • old linux
      • compile_linux0.11
      • TestEnvironment
      • load_setup
      • get_hard_data
    • list
    • plist
    • fifo
    • idr
    • xarray
    • rbtree
    • maple_tree
    • syscall
    • bitmap
    • page
    • page_flags
    • page_size
    • page mapcount
    • page refcount
    • folio
    • slub
      • proc_slabinfo
      • slub_theory
      • kmalloc_kfree
      • kmem_cache
      • slab_alloc
      • slab_free
      • proc_meminfo_SReclaimable_SReclaimable
    • vmalloc
    • brk
    • mmap
    • mremap
    • mprotect
    • madvise
    • read
    • write
    • shmem
    • huge_page
    • page_fault
    • rmap
    • lru
    • multi-gen-LRU
    • page_reclaim
    • page_cache
    • page_table
    • rcu
    • kvm
    • aarch64_boot
    • tracing_system
    • cache_coherence_and_memory_consistency
    • cpu_speculates
    • mmap_lock
    • per-vma_lock
    • cgroup
    • symbol
    • campact
    • page_ext
    • mempool
    • kernelstack
    • filesystem
    • io_stack
    • workingset
    • ioremap
    • sched_period
  • linuxDebug
    • openocd_openjtag
    • i2c_tools
    • objdump
    • addr2line
    • gdb_useage
    • debug_linux_kernel_via_gdb
    • debug_linux_module_via_gdb
    • early_boot
    • sequentially_execute
    • dynamic_debug
    • research_linuxKernel_by_patch
    • tracefs
    • ebpf
    • bpftrace
    • perf
    • flame_graph
    • crash
    • ASAN_HWASAN_MTE_check_mem_bug
    • page_owner
    • vmtouch
    • fio
    • benchmark
  • linuxSystem
    • common
      • system_version
      • procfs
      • proc_sys_vm
      • cmd_ps
      • makefile
      • file_descriptor
      • psi
      • ulimit
      • top
      • delay_accounting
    • ubuntu
      • custom_kernel
      • get_cmd_src
      • record_ssh_info
      • log
      • run_custom_script
      • repo
      • cockpit
      • nfs
      • tftp
      • misc
    • fedora
      • system_upgrade
      • custom_kernel
      • lvextend
      • yt-dlp
      • jellyfin
  • linuxDriver
    • i2c_peripherals_driver
    • spi_peripherals_driver
    • gpio_subsystem
    • IRQ_driver
    • blockIO_unblockIO_async
    • linux_own_driver
    • misc_device
    • input_device
    • timer
    • atomic_spinlock_semaphore_mutex
    • lcd
    • touch_screen
    • debugfs
    • v4l2
    • mmap
  • hardware
    • paging_mmu_pt
    • iommu
  • process_thread_scheduler
    • scheduler01
    • scheduler02
    • scheduler03
    • scheduler04
    • scheduler05
    • scheduler06
  • memory_management
    • mm1
    • mm2
    • mm3
    • mm4
    • mm5
  • input_output_filesystem
    • io_fs_01
    • io_fs_02
    • io_fs_03
    • io_fs_04
  • lock_and_lockup_detector
    • general_lock
    • hung_task
    • softLockup_hardLockup
    • crash_experiment
  • MIT_6.S081
    • 6.S081_Operating_System_Engineering
    • Schedule.md
    • Class
      • Overview
      • Administrivia
    • Labs
      • Tools
      • Guidance
      • startup
      • syscall
      • page_table
      • Calling_Convention
      • traps
    • xv6
      • xv6
    • References.md
  • qemu
    • qemu_buildroot
    • qemu_busybox.md
    • Serial.md
    • demo_mini2440
      • 0_compilation_error_summary
      • 1_compilation_steps
      • 2_operation_mode
      • 3_transplant_tools_libraries
      • 4_tools_use
      • reference_website
  • tools
    • getKernelSourceCodeList
    • nat
    • shell
    • translating
    • YouCompleteMe
    • cscope
    • global
    • vscode
    • vim
    • binary
    • markdown
    • draw
    • git
    • tig
    • tmux
    • mail_client
    • download_patchset_from_LKML
    • minicom
    • clash
  • other
    • interview
    • interview_c_base
    • know_dontknow
    • Stop-Ask-Questions-The-Stupid-Ways
    • How-To-Ask-Questions-The-Smart-Way
    • docker
    • buildroot
    • rv32_to_rv64
Powered by GitBook
On this page
  • 1. 手动分配与设置 struct input_dev * 变量
  • 2. 注册 input device
  • 3. 向linux系统上报事件
  • 4. 注销与释放 input device
  • 5. 应用层测试

Was this helpful?

  1. linuxDriver

touch_screen

linux kernel touch screen driver编写,需要用到i2c子系统、中断子系统、input子系统,这三个子系统前面文档已经介绍过如何操作,此处只介绍input子系统的多点触摸协议,需要五步:

  • 手动分配与设置 struct input_dev * 变量

  • 注册 input device

  • 向linux系统上报事件

  • 注销与释放 input device

  • 应用层测试

1. 手动分配与设置 struct input_dev * 变量

struct input_dev *inputDev;

inputDev = input_allocate_device(); // 分配
inputDev->name = "xxx_inputDev";    // 设置input device名字
__set_bit(EV_ABS, inputdev->evbit); // 设置事件类型
input_set_abs_params(inputdev, ABS_MT_POSITION_X, 0, 480, 0, 0);//设置x轴事件码, x轴范围0~480
input_set_abs_params(inputdev, ABS_MT_POSITION_Y, 0, 272, 0, 0);//设置y轴事件码, y轴范围0~272
input_mt_init_slots(inputdev, MAX_SUPPORT_POINTS, 0); // 初始化触摸点个数 MAX_SUPPORT_POINTS

2. 注册 input device

input_register_device(inputDev); // 注册

3. 向linux系统上报事件

一般在中断处理函数或下半部函数中上报事件

/*
 * 向linux系统上报触摸事件
 *
 * 事件类型: EV_ABS
 * 事件码  : ABS_MT_SLOT、ABS_MT_TRACKING_ID、ABS_MT_POSITION_X、ABS_MT_POSITION_Y
 * 事件值  : slot、touch、x、y, 从触摸屏IC读取得到
 *
 * 事件值解释
 * slot :代表第几个触摸点
 * touch:代表手指按下/松开 = 1/0
 * x    :代表触摸点x轴坐标
 * y    :代表触摸点y轴坐标
 */
input_mt_slot(inputdev, slot);                               // ABS_MT_SLOT
input_mt_report_slot_state(inputdev, MT_TOOL_FINGER, touch); // ABS_MT_TRACKING_ID
input_report_abs(inputdev, ABS_MT_POSITION_X, x);
input_report_abs(inputdev, ABS_MT_POSITION_Y, y);

// 向linux系统上报同步事件
input_sync(inputDev);

4. 注销与释放 input device

input_unregister_device(inputDev); // 注销
input_free_device(inputDev);       // 释放

5. 应用层测试

通过hexdump测试

$ hexdump /dev/input/eventx
[编号]   [秒]      [微秒]      [事件类型] [事件码]  [事件值]
0000000 002a 0000 362f 000c    0003     0039    0000 0000
0000010 002a 0000 362f 000c    0003     0035    0025 0000
0000020 002a 0000 362f 000c    0003     0036    0023 0000
0000030 002a 0000 362f 000c    0000     0000    0000 0000

# (x,y) 即(0x25, 0x23)
# 第一行:触摸事件,事件类型EV_ABS=0x3,事件码ABS_MT_SLOT=0x39,事件值0
# 第二行:触摸事件,事件类型EV_ABS=0x3,事件码ABS_MT_POSITION_X=0x35,事件值x坐标 0x25
# 第三行:触摸事件,事件类型EV_ABS=0x3,事件码ABS_MT_POSITION_Y=0x36,事件值y坐标 0x23
# 第四行:同步事件

通过tslib测试

$ vi /etc/profile # 加入以下内容
export TSLIB_TSDEVICE=/dev/input/eventX
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_CONFFILE=/etc/ts.conf
export TSLIB_PLUGINDIR=/usr/lib/ts
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fbx

$ ts_print_mt # 打印坐标(x, y)
$ ts_test_mt  # 图形化显示坐标位置,画图功能

注意:驱动需要上传手指按下/松开状态,tslib画图功能才能正常使用,否则只能使用图形化显示坐标位置功能

PreviouslcdNextdebugfs

Last updated 4 years ago

Was this helpful?