| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Using Keyboard with Embedded Host Author: Amardeep Gupta Microchi
Top Searches for this datasheetAN1212 Using Keyboard with Embedded Host Author: Amardeep Gupta Microchip Technology Inc. Ctrl, Shift, keys make 8-bit modifier byte standard keyboard report. Byte this report constant. This byte reserved Original Equipment Manufacturer (OEM). Table describes keyboard output report byte). Microcontroller applications easily support embedded host functionality with introduction Microchip's microcontrollers with peripheral. Traditionally, personal computers have been used hosts network. Microchip's product line replace personal computer system implementing embedded host. Many embedded applications require control inputs from external devices, such keyboards, mice, joysticks, Point-of-Sale (POS) barcode scanners magnetic code readers having Keyboard Emulation mode. This application note demonstrates develop keyboard application that Explorer demo board with PICtailPlus daughter board using Microchip microcontroller embedded host. TABLE KEYBOARD OUTPUT REPORT Description Lock Caps Lock Scroll Lock Compose KANA Constant Keyboard Overview preferred method interface peripherals with computers. conventional keyboard been replaced with standard keyboard interface with computer (host). standard keyboard sends 8-byte input report host. Table describes keyboard input report bytes). standard keyboard three LEDs display Lock, Caps Lock Scroll Lock status. LEDs absolute output items; state each must included output reports OFF, ON). keyboard demo application, Lock Caps Lock LEDs have been implemented. Keyboard with Embedded Host This application demo illustrates Human Interface Device (HID) host capability. low-speed full-speed keyboard connected host Explorer board through PICtailPlus daughter board. demo schedules transfers interprets reports received from keyboard. codes decoded their respective ASCII values displayed display Explorer demo board. Since purpose this application demonstrate capabilities host, codes have been implemented. This demo helps user understand host capabilities. Users incorporate necessary changes required their application. alphabetic, numeric special characters have been implemented, well Esc, Shift, Caps Lock, Arrow Spacebar keys. Note: Refer "Device Class Definition Human Interface Devices (HID)" keyboard implementation details (see "References" section). TABLE Byte KEYBOARD INPUT REPORTS Description Modifier Keys Reserved Code Code Code Code Code Code some keyboards that have custom implementation that does match standard keyboard implementation, look-up table required order code returned desired usage Keys, such 2008 Microchip Technology Inc. DS01212A-page AN1212 Application Architecture keyboard application actually multi-layer stack (see Figure with different components Microchip's embedded host support package contributing different layers. Table lists source files used this application which layer those files implement. FIGURE DEFAULT DIRECTORY STRUCTURE KEYBOARD HOST SUPPORT Local Hard Drive (C:) Microchip Solutions FIGURE APPLICATION ARCHITECTURE Microchip Common Common Microchip Source Files Application Layer (Keypad, Joystick.) Include Header Files Common Microchip Header Files Interface Layer Parser/Client Layer Documentation Client Driver Directories Source Files Embedded Host Layer Getting Started with Host Stack This section describes various steps involved getting started with host stack. keyboard application available part Microchip's complete embedded host support package (see Appendix "Software Discussed this Application Note" more details). Help Help Files Host-HID-Keyboard Project Files Tools USBConfig Tool INSTALLING HOST STACK install required project files host Download installation file from Microchip site: http://microchip.com/usb executable installer file. default, project stack files will installed directory structure displayed Figure EMBEDDED HOST LAYER embedded host layer provides basic embedded host support. interface this layer provided automatically client driver. more information about this layer, refer Microchip's AN1140, "USB Embedded Host Stack" AN1141, "USB Embedded Host Stack Programmers Guide". necessary familiar with this layer's operation configuration order with keyboard application. DS01212A-page 2008 Microchip Technology Inc. AN1212 CLIENT DRIVER/HID PARSER next layer provides client driver Human Interface (Class) parser. client needed interfacing devices, like mice, keyboards, joystick controls, etc. Refer Microchip Application Note AN1144, "USB Human Interface Device Class Embedded Host" more information about client driver. Note: Memory allocation descriptor related information dynamic. Report descriptor data structures consume less than bytes interface. application should reserve least Kbyte heap while using host stack. INTERFACE LAYER interface layer provided integrate user application with client/HID parser. This layer provides interface functions application interact with client/HID parser. client interface functions used exchange reports with devices attached bus. parser interface functions used interpret report descriptor decode input report received from device. Refer AN1144, "USB Human Interface Device Class Embedded Host" more information parser. Note: detailed information about embedded host interface APIs, refer Embedded Host Library documentation provided Help directory. TABLE Layer FILES USED KEYBOARD APPLICATION File Name usb_host.c usb_host.h Description Provides embedded host support devices. Does provide class support. Header file with definitions required embedded hosts. Defines interface embedded host driver. Other support header files. Embedded Host Layer usb.h, usb_ch9.h, usb_common.h, usb_hal.h, usb_hal_pic24.h usb_host_hid.c usb_host_hid.h Client Driver/Parser Provides class support embedded host. Header file with definitions embedded hosts supporting class. Defines interfaces client driver. Provides report descriptor parser data structures. Header file with interface functions report descriptor parser definitions supporting data structures. Provides Interface functions access client/parser. usb_host_hid_parser.c usb_host_hid_parser.h usb_host_hid_appl_interface.c Interface usb_host_hid_appl_interface.h Header file containing interface definitions used access client/parser. uart2.c uart2.h usb_config.c usb_config.h HardwareProfile.h lcd_demo.c lcd_demo.h keyboard_demo.c Provides interface UART2 provide RS-232 input output application. Header file UART2 functions. Configures stack application; generated configuration tool. Configures stack application; generated configuration tool. Contains system level constants libraries reference. Provides support functions driver display routines. Header file containing interface definitions LCD. Main application code. Application 2008 Microchip Technology Inc. DS01212A-page AN1212 Application Functionality keyboard application demo intended demonstrate features Microchip host. application interface keyboard with Explorer demo board using PICtail Plus daughter board. user might have modify settings depending number interfaces keyboard supports. main features keyboard demo are: Parsed Data Collection Handler Receive Input Reports Transmit Output Reports Display Function interface function, USBHostHID_ApiGetReport(), used request input report from device. input report received from device stored Appl_raw_report_buffer structure. contains information keys pressed that duration. report then passed USBHostHID_ApiImportData() interface function. Then, data extracted application buffers populated. application then processes data based pressed. shadow buffers, Appl_ShadowBuffer1 Appl_ShadowBuffer2, used keep track keys pressed previous reports. Data from current buffer copied into shadow buffers after processing current report buffer data current report buffer report buffers cleared. Table lists input report buffers declared application. Parsed Data Collection Handler device must have least report descriptor. Report descriptors composed pieces information. Each piece information called item. client driver incorporates parser. class client driver contains parser used analyze items found report descriptor. parser extracts information from descriptor linear fashion. parser collects state each item known walks through descriptor stores structure form table. Refer Microchip's AN1144, "USB Human Interface Device (HID) Class Embedded Host" more information about client driver. client driver generates event, EVENT_HID_RPT_DESC_PARSED, after report descriptor been parsed without error. application must provide callback function collect parsed information stored data structures. configuration tool provision enter function's name. this keyboard application demo, USB_HID_DataCollectionHandler() function collects parsed information stores structure, HID_DATA_DETAILS. Table lists structures provided. Transmit Output Reports Common keyboards have LEDs display Caps Lock, Lock Scroll Lock status. status sent host application output report device. number LEDs supported keyboard format report described report descriptor. described previous section, application should collect report format details after report descriptor been parsed. Depending combinations pressed, application decide status indicator store output report buffer. rate sending output reports fixed; they aperiodic transfers. user application decide transmit report whenever change status occurs. Table lists output report buffer declared application. Note: detailed information about embedded host interface APIs, refer Embedded Host Library documentation provided Help directory. Receive Input Reports host application receives 8-byte input report from device. Timer3 used trigger send request input report. Timer3 triggers request depending polling rate defined configuration descriptor. polling rate input report stored structure, USB_HID_DEVICE_RPT_INFO, accessed using interface function, DS01212A-page 2008 Microchip Technology Inc. AN1212 Display Function Upon power-up, following banner displays display: keyboard ready use. When first press received, application clears banner starts displaying keys they pressed. input report received from device consists usage keys pressed within that period. alphabetic special characters converted their respective ASCII values. characters displayed Explorer board. Table displays action taken codes received from device. Device Detached Upon connecting keyboard, device enumerated without errors, following banner displays display: Explorer16 Board HIDHost Demo TABLE HID_DATA_DETAILS OBJECTS Object Description This structure stores details modifier keys (Ctrl, Shift, GUI). This structure stores input details other keys. This structure stores indicator output report details. Appl_ModifierKeysDetails Appl_NormalKeysDetails Appl_LED_Indicator TABLE INPUT REPORT BUFFER Buffer Description This buffer stores report details pointer input report data received from device. This buffer stores pressed instance data rest keys keyboard. This buffer stores pressed instance data modifier keys (Ctrl, Shift, GUI) current report received from device. Appl_raw_report_buffer Appl_BufferNormalKeys Appl_BufferModifierKeys TABLE TRANSMIT OUTPUT REPORT BUFFER Buffer Description This buffer stores indicator status Caps Lock, Lock Scroll Lock LEDs. Appl_led_report_buffer 2008 Microchip Technology Inc. DS01212A-page AN1212 TABLE Characters Shift ACTION CODES RECEIVED FROM DEVICE Pressed Action letters special characters displayed LCD. Caps Lock letters displayed lower case; otherwise, they displayed upper case. Special characters displayed instead numbers. Caps Lock off, letters displayed upper case; otherwise, they displayed lower case. Numbers displayed. display cleared. Advances cursor space. Character left cursor deleted. Letters displayed upper case. Output report with Caps Lock status high sent. Letters displayed lower case. Output report with Caps Lock status sent. Output report with Lock status high sent. Enables numeric keys keypad. Output report with Caps Lock status sent. Enables Arrow keys keypad. Moves cursor display. Space Back Space Caps Lock Lock Arrow Keys DS01212A-page 2008 Microchip Technology Inc. AN1212 CONFIGURATION TOOL keyboard application already been configured using graphic configuration tool, USBConfig.exe, located installation directory, \USB Tools\USBConfig Tool. configuration files (usb_config.c usb_config.h) were generated stored .\USB Host Keyboard project directory. following configuration options have been selected: Main (Figure Device Type: Embedded Host Ping-Pong Mode: Endpoints Host (Figure Transfer Types: Interrupt only, with NAKs allowed (control transfers also enabled with dialog text appearing grey) Attach Debounce Interval: Name Application Event Handler: USB_ApplicationEventHandler Note Attach Debounce Interval increased from specification allow slower devices. conserve program data memory, transfer events used. number allowed NAKs depends Idle rate device attached. (Figure Entry Support Class selected Client Driver: Class: (0x03) SubClass: Boot (0x01) Protocol: Keyboard (0x01) Initial Configuration: Initialization Flags: HNP: Allowed Entry Support Class selected Client Driver: Class: (0x03) SubClass: None (0x00) Protocol: None (0x00) Initial Configuration: Initialization Flags: HNP: Allowed Note: This demo application supports only standard keyboard interfaces. user keyboard supports multimedia functions, then entries need changed support interfaces. (see Figure Client used Host mode selected. Input reports varied lengths. While configuring, host application needs inform client maximum data field size bits. illustrated Example this input report, user must enter "Maximum Data Field Size". Under "Application Interface", "Default Interface" selected. "Parsed Data Collection Handler" provided application. Note: host application aware input/output report format, then parsed data collection handler ignored field disabled deselecting check box. EXAMPLE DATA FIELDS 4-BYTE INPUT REPORT 2008 Microchip Technology Inc. DS01212A-page AN1212 FIGURE CONFIGURATION TOOL, MAIN FIGURE CONFIGURATION TOOL, HOST DS01212A-page 2008 Microchip Technology Inc. AN1212 FIGURE CONFIGURATION TOOL, FIGURE CONFIGURATION TOOL, 2008 Microchip Technology Inc. DS01212A-page AN1212 CONCLUSION Standard input devices, like keyboards, mice joysticks, intended used with easily interfaced with embedded system. Using Microchip's embedded host capability with client driver, embedded applications connect user interface devices embedded system. REFERENCES more information components Microchip embedded host support package, following documents available Microchip site (www.microchip.com/usb): Microchip's AN1140, "USB Embedded Host Stack" (DS01140) Microchip's AN1141, "USB Embedded Host Stack Programmer's Guide" (DS01141) Microchip's AN1144, "USB Human Interface Device Class Embedded Host" more information embedded host functionality, general: Implementers Forum, "Universal Serial Revision Specification", Implementers Forum, "Device Class Definition Human Interface Devices (HID)", Implementers Forum, "Requirements Recommendations Products with Embedded Hosts and/or Multiple Receptacles", DS01212A-page 2008 Microchip Technology Inc. AN1212 APPENDIX SOFTWARE DISCUSSED THIS APPLICATION NOTE keyboard application available download part Microchip's Embedded Host Library. This software library contains source code support files required layers application. Interested users download Embedded Host Library from Microchip corporate site, www.microchip.com/usb. 2008 Microchip Technology Inc. DS01212A-page AN1212 NOTES: DS01212A-page 2008 Microchip Technology Inc. Note following details code protection feature Microchip devices: Microchip products meet specification contained their particular Microchip Data Sheet. Microchip believes that family products most secure families kind market today, when used intended manner under normal conditions. There dishonest possibly illegal methods used breach code protection feature. these methods, knowledge, require using Microchip products manner outside operating specifications contained Microchip's Data Sheets. Most likely, person doing engaged theft intellectual property. Microchip willing work with customer concerned about integrity their code. Neither Microchip other semiconductor manufacturer guarantee security their code. Code protection does mean that guaranteeing product "unbreakable." Code protection constantly evolving. Microchip committed continuously improving code protection features products. Attempts break Microchip's code protection feature violation Digital Millennium Copyright Act. such acts allow unauthorized access your software other copyrighted work, have right relief under that Act. Information contained this publication regarding device applications like provided only your convenience superseded updates. your responsibility ensure that your application meets with your specifications. MICROCHIP MAKES REPRESENTATIONS WARRANTIES KIND WHETHER EXPRESS IMPLIED, WRITTEN ORAL, STATUTORY OTHERWISE, RELATED INFORMATION, INCLUDING LIMITED CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY FITNESS PURPOSE. Microchip disclaims liability arising from this information use. Microchip devices life support and/or safety applications entirely buyer's risk, buyer agrees defend, indemnify hold harmless Microchip from damages, claims, suits, expenses resulting from such use. licenses conveyed, implicitly otherwise, under Microchip intellectual property rights. Trademarks Microchip name logo, Microchip logo, Accuron, dsPIC, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART, rfPIC SmartShunt registered trademarks Microchip Technology Incorporated U.S.A. other countries. FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor Embedded Control Solutions Company registered trademarks Microchip Technology Incorporated U.S.A. Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, UNI/O, WiperLock ZENA trademarks Microchip Technology Incorporated U.S.A. other countries. SQTP service mark Microchip Technology Incorporated U.S.A. other trademarks mentioned herein property their respective companies. 2008, Microchip Technology Incorporated, Printed U.S.A., Rights Reserved. Printed recycled paper. Microchip received ISO/TS-16949:2002 certification worldwide headquarters, design wafer fabrication facilities Chandler Tempe, Arizona; Gresham, Oregon design centers California India. Company's quality system processes procedures PIC® MCUs dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory analog products. addition, Microchip's quality system design manufacture development systems 9001:2000 certified. 2008 Microchip Technology Inc. DS01212A-page Worldwide Sales Service AMERICAS Corporate Office 2355 West Chandler Blvd. Chandler, 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://support.microchip.com Address: www.microchip.com Atlanta Duluth, Tel: 678-957-9614 Fax: 678-957-1455 Boston Westborough, Tel: 774-760-0087 Fax: 774-760-0088 Chicago Itasca, Tel: 630-285-0071 Fax: 630-285-0075 Dallas Addison, Tel: 972-818-7423 Fax: 972-818-2924 Detroit Farmington Hills, Tel: 248-538-2250 Fax: 248-538-2260 Kokomo Kokomo, Tel: 765-864-8360 Fax: 765-864-8387 Angeles Mission Viejo, Tel: 949-462-9523 Fax: 949-462-9608 Santa Clara Santa Clara, Tel: 408-961-6444 Fax: 408-961-6445 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509 ASIA/PACIFIC Asia Pacific Office Suites 3707-14, 37th Floor Tower Gateway Harbour City, Kowloon Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 Australia Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China Beijing Tel: 86-10-8528-2100 Fax: 86-10-8528-2104 China Chengdu Tel: 86-28-8665-5511 Fax: 86-28-8665-7889 China Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 China Nanjing Tel: 86-25-8473-2460 Fax: 86-25-8473-2470 China Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 China Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 China Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 China Shenzhen Tel: 86-755-8203-2660 Fax: 86-755-8203-1760 China Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 China Xiamen Tel: 86-592-2388138 Fax: 86-592-2388130 China Xian Tel: 86-29-8833-7252 Fax: 86-29-8833-7256 China Zhuhai Tel: 86-756-3210040 Fax: 86-756-3210049 ASIA/PACIFIC India Bangalore Tel: 91-80-4182-8400 Fax: 91-80-4182-8422 India Delhi Tel: 91-11-4160-8631 Fax: 91-11-4160-8632 India Pune Tel: 91-20-2566-1512 Fax: 91-20-2566-1513 Japan Yokohama Tel: 81-45-471- 6166 Fax: 81-45-471-6122 Korea Daegu Tel: 82-53-744-4301 Fax: 82-53-744-4302 Korea Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 82-2-558-5934 Malaysia Kuala Lumpur Tel: 60-3-6201-9857 Fax: 60-3-6201-9859 Malaysia Penang Tel: 60-4-227-8870 Fax: 60-4-227-4068 Philippines Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan Hsin Tel: 886-3-572-9526 Fax: 886-3-572-6459 Taiwan Kaohsiung Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan Taipei Tel: 886-2-2500-6610 Fax: 886-2-2508-0102 Thailand Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 EUROPE Austria Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 Denmark Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 France Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Italy Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Netherlands Drunen Tel: 31-416-690399 Fax: 31-416-690340 Spain Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 Wokingham Tel: 44-118-921-5869 Fax: 44-118-921-5820 01/02/08 DS01212A-page 2008 Microchip Technology Inc. Other recent searchesSTM32-SK - STM32-SK STM32-SK Datasheet KEIL - KEIL KEIL Datasheet STR91X-SK - STR91X-SK STR91X-SK Datasheet STK611-721-E - STK611-721-E STK611-721-E Datasheet SL1540S7 - SL1540S7 SL1540S7 Datasheet MAX3140 - MAX3140 MAX3140 Datasheet MAX3140 - MAX3140 MAX3140 Datasheet MAX3100 - MAX3100 MAX3100 Datasheet MAX3089 - MAX3089 MAX3089 Datasheet EPB5042 - EPB5042 EPB5042 Datasheet BGA715L7 - BGA715L7 BGA715L7 Datasheet AP1501A - AP1501A AP1501A Datasheet TO263-5L - TO263-5L TO263-5L Datasheet TO220-5L - TO220-5L TO220-5L Datasheet
Privacy Policy | Disclaimer |