📄 gpio_input_device_driver.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head> <title></title> <link rel="stylesheet" media="screen" type="text/css" href="./style.css" /> <link rel="stylesheet" media="screen" type="text/css" href="./design.css" /> <link rel="stylesheet" media="print" type="text/css" href="./print.css" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><a href=start.html>start</a></br><div class="toc"><div class="tocheader toctoggle" id="toc__header">Table of Contents</div><div id="toc__inside"><ul class="toc"><li class="level1"><div class="li"><span class="li"><a href="#general_description" class="toc">GENERAL DESCRIPTION</a></span></div></li><li class="level1"><div class="li"><span class="li"><a href="#kernel_configuration_for_gpio_input_device_support" class="toc">Kernel Configuration for GPIO Input Device Support</a></span></div><ul class="toc"><li class="level2"><div class="li"><span class="li"><a href="#configure_gpio_portf_for_bf537" class="toc">Configure GPIO PortF for BF537</a></span></div></li><li class="level2"><div class="li"><span class="li"><a href="#setting_up_input_device_support" class="toc">Setting up Input Device Support</a></span></div><ul class="toc"><li class="level3"><div class="li"><span class="li"><a href="#device_drivers" class="toc">Device Drivers</a></span></div></li><li class="level3"><div class="li"><span class="li"><a href="#blackfin_test_programs" class="toc">Blackfin test programs</a></span></div></li></ul></li></ul></li></ul></div></div><h1><a name="general_description" id="general_description">GENERAL DESCRIPTION</a></h1><div class="level1"><p>This sample device driver utilizes the <strong>Linux Input Device</strong> subsystem.<br/> In Particular <em>evdev</em>, which is a generic input event interface.<br/> It passes the events generated in the kernel straight to the program, with timestamps.<br/> The event codes are the same on all architectures and are hardware<br/> independent.<br/></p><pre class="code"> The devices are in /dev/input: crw-r--r-- 1 root root 13, 64 Apr 1 10:49 event0 crw-r--r-- 1 root root 13, 65 Apr 1 10:50 event1 crw-r--r-- 1 root root 13, 66 Apr 1 10:50 event2 crw-r--r-- 1 root root 13, 67 Apr 1 10:50 event3 ...</pre><p>The Event interface can use blocking and non-blocking reads, also <strong>poll()</strong> and <strong>select()</strong>system calls on the /dev/input/eventX devices, and you’ll always get a whole number of input events on a read. Their layout is:</p><pre class="code">struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value;};</pre><pre class="code">'time' is the timestamp, it returns the time at which the event happened.</pre><p>Type is for example EV_REL for relative moment, REL_KEY for a key-press or release. More types are defined in include/linux/input.h. </p><pre class="code">'code' is event code, for example REL_X or KEY_BACKSPACE, again a complete</pre><p>list is in include/linux/input.h. </p><pre class="code">'value' is the value the event carries. Either a relative change for</pre><p>EV_REL, absolute new value for EV_ABS (joysticks ...), or 0 for EV_KEY for release, 1 for key-press and 2 for auto-repeat.</p><p><em class="u"><strong>For more information please read:</strong></em> </p><ol><li class="level1"><div class="li"> linux-2.6.x/Documentation/input/input.txt</div></li><li class="level1"><div class="li"> linux-2.6.x/Documentation/input/input-programming.txt</div></li></ol></div><!-- SECTION [1-1679] --><h1><a name="kernel_configuration_for_gpio_input_device_support" id="kernel_configuration_for_gpio_input_device_support">Kernel Configuration for GPIO Input Device Support</a></h1><div class="level1"></div><!-- SECTION [1680-1745] --><h2><a name="configure_gpio_portf_for_bf537" id="configure_gpio_portf_for_bf537">Configure GPIO PortF for BF537</a></h2><div class="level2"><p>In kernel option “Blackfin Processor Options” —> “BF537 Specific Configuration” </p><pre class="code">--- PORT F/G Selection Select BF537/6/4 default GPIO PFx PORTx (Select BF537/6/4 default GPIO PFx PORTF) ---></pre><pre class="code">(*) Select BF537/6/4 default GPIO PFx PORTF( ) Select BF537/6/4 default GPIO PFx PORTG</pre></div><!-- SECTION [1746-2105] --><h2><a name="setting_up_input_device_support" id="setting_up_input_device_support">Setting up Input Device Support</a></h2><div class="level2"></div><!-- SECTION [2106-2151] --><h3><a name="device_drivers" id="device_drivers">Device Drivers</a></h3><div class="level3"></div><h4><a name="input_device_support" id="input_device_support">Input device support</a></h4><div class="level4"><pre class="code"> <*> Generic input layer (needed for keyboard, mouse, ...) --- Userland interfaces < > Mouse interface < > Joystick interface (NEW) < > Touchscreen interface (NEW) <*> Event interface < > Event debugging (NEW) --- Input Device Drivers [ ] Keyboards ---> [ ] Mouse ---> [ ] Joysticks (NEW) ---> [ ] Touchscreens (NEW) ---> [*] Miscellaneous devices ---> Hardware I/O ports ---></pre></div><h4><a name="miscellaneous_devices" id="miscellaneous_devices">Miscellaneous devices</a></h4><div class="level4"><pre class="code"> --- Miscellaneous devices <*> User level driver support <*> PF buttons input device < > TWI/I2C Keypad input device (NEW)</pre></div><!-- SECTION [2152-2829] --><h3><a name="blackfin_test_programs" id="blackfin_test_programs">Blackfin test programs</a></h3><div class="level3"><pre class="code">[ ] RTC test program[ ] DPMC test program[ ] PPIFCD test program[ ] AUDIO test program[ ] VIDEO test program[ ] PFLAGS test program[*] PFBUTTONS test program[ ] TWI test program[ ] SPI test program[ ] PPI test program[ ] TWI LCD test program[ ] TWI KEYPAD test program[ ] RTS/CTS test program[ ] Sqlite test program[ ] Pthread lib test[ ] Kernel Panic (test Watchdog)[ ] netperf test tool[ ] SYSVIPC testcase[ ] Still to write[ ] Input event device test[ ] AD9960 device test[ ] file operation test</pre></div><h4><a name="pfbuttons_test_application" id="pfbuttons_test_application">pfbuttons_test application</a></h4><div class="level4"><p> The example program shown below listens on the /dev/input/event0 file descriptor,<br/> trying to read any events. It filters out events that don’t correspond to BUTTONS <br/> and then prints out the various fields in the input_event structure.<br/> Running this while pressing Buttons on the STAMP board produces:<br/></p><pre class="code">root:~> pfbuttons_test########################## PFBUTTONS TEST ###############################open success /dev/input/event0Event. Type: 1, Code: 256, Value: 0Take a look LED_MUTE ... offEvent. Type: 0, Code: 0, Value: 0Event. Type: 17, Code: 7, Value: 0Event. Type: 1, Code: 256, Value: 1Take a look LED_MUTE ... onEvent. Type: 0, Code: 0, Value: 0Event. Type: 17, Code: 7, Value: 1</pre><p>You get one event per key press and another per key release. LEDs are toggled based on Button actions.</p></div><!-- SECTION [2830-] --></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -