Application Note. 8-bit Microcontrollers. AVR271: USB Keyboard Demonstration



Similar documents
Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

Application Note. 8-bit Microcontrollers. AVR293: USB Composite Device

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AT89C5131A Starter Kit... Software User Guide

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

8-bit. Application Note. Microcontrollers. AVR273: USB Mass Storage Implementation. Features. 1. Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

AVR ONE!... Quick-start Guide. EVK Windows 32104B AVR ONE! 02/10

AT91SAM ARM-based Flash MCU. Application Note

Application Note. USB Microcontrollers. USB PC Drivers Based on Generic HID Class. 1. Introduction

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

AVR2004: LC-Balun for AT86RF230. Application Note. Features. 1 Introduction

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC. 8-bit Microcontrollers. Application Note. Features.

USER GUIDE. ZigBit USB Stick User Guide. Introduction

General Porting Considerations. Memory EEPROM XRAM

AT91 ARM Thumb Microcontrollers. AT91SAM CAN Bootloader. AT91SAM CAN Bootloader User Notes. 1. Description. 2. Key Features

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

USER GUIDE EDBG. Description

AT88CK490 Evaluation Kit

Application Note. USB Mass Storage Device Implementation. USB Microcontrollers. References. Abbreviations. Supported Controllers

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

8-bit RISC Microcontroller. Application Note. AVR155: Accessing an I 2 C LCD Display using the AVR 2-wire Serial Interface

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

AVR106: C functions for reading and writing to Flash memory. 8-bit Microcontrollers. Application Note. Features. Introduction

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

8-bit Microcontroller. Application Note. AVR222: 8-point Moving Average Filter

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

APPLICATION NOTE. Secure Personalization with Transport Key Authentication. ATSHA204A, ATECC108A, and ATECC508A. Introduction.

AVR1003: Using the XMEGA Clock System. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

AT91 ARM Thumb Microcontrollers. Application Note. Interfacing a PC Card to an AT91RM9200-DK. Introduction. Hardware Interface

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

AVR32110: Using the AVR32 Timer/Counter. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

AVR125: ADC of tinyavr in Single Ended Mode. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

256K (32K x 8) Battery-Voltage Parallel EEPROMs AT28BV256

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

AT86RF230 (2450 MHz band) Radio Transceiver... User Guide

Atmel AT32UC3A3256 microcontroller 64MBit SDRAM Analog input (to ADC) Temperature sensor RC filter

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

8-bit Microcontroller. Application Note. AVR286: LIN Firmware Base for LIN/UART Controller. LIN Features. 1. Atmel LIN/UART Controller

Application Note. Migrating from RS-232 to USB Bridge Specification USB Microcontrollers. Doc Control. References. Abbreviations

Introducing a platform to facilitate reliable and highly productive embedded developments

MODFLEX MINI GATEWAY ETHERNET USER S GUIDE

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

AT91 ARM Thumb Microcontrollers. Application Note. AT91 USB CDC Driver Implementation. 1. Introduction. 2. Related Documents

APPLICATION NOTE. Authentication Counting. Atmel CryptoAuthentication. Features. Introduction

AVR106: C Functions for Reading and Writing to Flash Memory. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

AVR223: Digital Filters with AVR. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

8-bit Microcontroller. Application Note. AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory

8-bit Microcontroller. Application Note. AVR461: Quick Start Guide for the Embedded Internet Toolkit. Introduction. System Requirements

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

USB 2.0 Full-Speed Host/Function Processor AT43USB370. Summary. Features. Overview

AVR32100: Using the AVR32 USART. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4905: ASF - USB Device HID Generic. 8-/32-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

AVR034: Mixing C and Assembly Code with IAR Embedded Workbench for AVR. 8-bit Microcontroller. Application Note. Features.

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

Software Prerequisites Linux Ubuntu LTS. Estimated completion time: 15min. The goal of this hands-on is to:

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. Introduction

AVR32737: AVR32 AP7 Linux Getting Started. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

64K (8K x 8) Parallel EEPROM with Page Write and Software Data Protection AT28C64B

Transcription:

AVR271: USB Keyboard Demonstration Features Supported by Windows 98 or later, Linux and MAC OS No driver installation Display a simple text message Does not support keyboard LEDs management 1. Introduction The PS/2 interface is disappearing from the new generation PCs being replaced by the USB interface, which has become the standard interface between the PCs and peripherals. This change must be followed by keyboard designers, who must integrate the USB interface to connect the keyboard to the PC. The aim of this document is to describe how to start and implement a USB keyboard application using the STK525 starter kit and FLIP in-system programming software. A familiarity with USB Software Library for AT90USBxxx Microcontrollers (Doc 7675, Included in the CD-ROM & Atmel website) and the HID specification (http://www.usb.org/developers/hidpage) is assumed. 8-bit Microcontrollers Application Note Figure 1-1. PC to Keyboard Interface

2. Hardware Requirements The USB keyboard application requires the following hardware: 1. AVR USB evaluation board (STK525, AT90USBKey, STK526...or your own board) 2. AVR USB microcontroller 3. USB cable (Standard A to Mini B) 4. PC running on Windows (98SE, ME, 2000, XP, Vista), Linux or MAC OS with USB 1.1 or 2.0 host 3. In system programming and Device Firmware Upgrade To program the device you can use the following methods: The JTAG interface using the JTAGICE MKII The SPI interface using the AVRISP MKII The USB interface thanks to the factory DFU bootloader and FLIP software The parallel programming using the STK500 or the STK600 Please refer to the hardware user guide of the board you are using (if you are using Atmel starter kit) to see how to program the device using these different methods. Please refer to FLIP (1) help content to see how to install the USB driver and program the device through the USB interface. Note: 1. Flip is a software provided by atmel to allow the user to program the AVR USB devices through the USB interface (No external hardware required) thanks to the factory DFU bootloader. 4. Quick start Once your device is programmed with usb_keyboard.a90 file, you can start the keyboard demonstration. Check that your device is enumerated as keyboard (see Figure 4-1), then you can use the kit to send characters to the PC. 2 AVR271

AVR271 Figure 4-1. Keyboard enumeration The figure below shows the STK525 used by the demo (you may use another kit: AT90USBKey, STK526, depending on the AVR USB product you are working with): 3

Figure 4-2. STK525 kit Joystick The purpose of the keyboard demonstration is to send a character string to the PC. Follow the instructions below to start the demo: 1. Open the Notepad application or any text editor. 2. Set your keyboard to QWERTY configuration (Otherwise, you ll see the wrong characters on your text editor). 3. Connect the STK525. 4. Push the joystick button. 4 AVR271

AVR271 Figure 4-3. Keyboard Demo 5

5. Application overview The USB Keyboard application is a simple data exchange between the PC and the keyboard. The PC asks the keyboard if there is new data available each P time (polling interval time), the keyboard will send the data if it is available, otherwise, it will send a NAK (No Acknowledge) to tell the PC that there is no data available. The data exchanges between the PC and the keyboard are called reports. The report which contains the keys pressed is the report IN (Keyboard to PC). The report which contains the LEDs status (NUM LOCK, CAPS LOCK, SCROLL LOCK...) is the report OUT (PC to Keyboard). The figure below shows the structure of these reports: Figure 5-1. USB Report Structure Note: This demonstration manages the report IN only. 6 AVR271

AVR271 Figure 5-2. Application Overview 6. Firmware As explained in the USB Software Library for AT90USBxxx Microcontrollers (Doc 7675), all USB firmware packages are based on the same architecture (please refer to this document for more details). 7

Figure 6-1. USB Keyboard Firmware Architecture Start up Enumeration management main.c scheduler.c config.h conf_scheduler.h Keyboard application management Keyboard application usb_task.h usb_task.c keyboard_task.c keyboard_task.h API usb_standard_ request.c usb_standard_request.h usb_specific_ request.c usb_specific_request.h usb_descriptors.c usb_descriptors.h conf_usb.h Drivers usb_drv.c usb_drv.h stk_525.c stk_525.h Hardware USB hardware interface Should not be modified by user Could be modified by user Added by user This section is dedicated to the keyboard module only. The customization of the files described hereafter allow the user to build his own keyboard Application. 8 AVR271

AVR271 6.1 keyboard_task.c This file contains the functions to initialize the hardware which will be used as a keyboard, collect the report data and put it in the endpoint FIFO to be ready to be sent to the PC. Figure 6-2. Keyboard Application 6.1.1 keyboard_task_init This function performs the initialization of the keyboard parameters and hardware resources (joystick...). 6.1.2 kbd_test_hit This function checks if there is a key pressed and sets the key_hit variable to true. 6.1.3 keyboard_task This function checks if any key is pressed (key_hit == true). If it is the case, the report IN is filled out with the related values and loaded in the USB endpoint FIFO to be transmited to the host. 6.2 stk_52x.c This file contains all the routines to manage the STK52x board resources (Joystick, potentiometer, Temperature sensor, LEDs...).The user should not modify this file when using the STK52x board. Otherwise he has to build his own hadware management file. 6.3 How to manage the CAPS, NUMLOCK... LEDs The keyboard LEDs (CAPS, NUMLOCK...) are managed by the host when the corresponding key is pressed. When receiving the keycode of CAPS or NUMLOCK... the host sends a Set_Report request (Out Report) to turn on/off the related LED of the keyboard. This request is send through the endpoint 0 (control transfer) and has to be managed as a Set_Configuration request, as shown below: First the host will send the set_report as showing below: 9

bmrequesttype 00100001 brequest SET_REPORT (0x09) wvalue Report Type (0x02) and Report ID 0x00) windex wlength Data Interface (0x00) Report Length (0x0004) Report (1 byte) This request is specific to the HID class, this is why it is not managed by the usb_standard_request.c file but with the usb_specific_request.c. In this file the request is decoded following the value of the bmrequest and the brequest using the usb_user_read_request() function. The report type (0x02) corresponds to an Out Report. To handle this request the usb_user_read_request() will call the hid_set_report() function. This function will acknowledge the setup request and than allow the user to get the one byte data (you can check the size using the wlength parameter) to know which LED has to be turned on/off (please refer to the HID specification for further information regarding the LEDs usage values). void hid_set_report (void) { U16 wlength; U8 CAPS_LED = 0; U8 REPORT_ID; LSB(wInterface)=Usb_read_byte(); MSB(wInterface)=Usb_read_byte(); LSB(wLength) = Usb_read_byte(); MSB(wLength) = Usb_read_byte(); Usb_ack_receive_setup(); //!< read wlength while(!is_usb_receive_out()); REPORT_ID = Usb_read_byte(); CAPS_LED = Usb_read_byte();// get the value of the CAPS LED status sent by the host Usb_ack_receive_out(); Usb_send_control_in(); while(!is_usb_in_ready()); //Send a report to clear the CAPS request Usb_select_endpoint(EP_KBD_IN); Usb_write_byte(0);// Byte0: Modifier Usb_write_byte(0); // Byte1: Reserved Usb_write_byte(0); // Byte2: Keycode 0 Usb_write_byte(0); // Byte2: Keycode 1 Usb_write_byte(0); // Byte2: Keycode 2 Usb_write_byte(0); // Byte2: Keycode 3 Usb_write_byte(0); // Byte2: Keycode 4 Usb_write_byte(0); // Byte2: Keycode 5 10 AVR271

AVR271 Usb_ack_in_ready(); //Turn ON/OFF the LED0 following the host reuqest if(caps_led == 0) Led3_off(); else Led3_on(); } 6.4 How to modify my device from non-bootable to bootable device Please note that HID device may be bootable or non-bootable. By default, the HID demo provided by Atmel are non-bootable device. If your application need to be bootable, you have to modify the sub-class parameter (usb_descriptors.h): // USB Interface descriptor Keyboard #define INTERFACE_NB_KEYBOARD 0 #define ALTERNATE_KEYBOARD 0 #define NB_ENDPOINT_KEYBOARD 1 #define INTERFACE_CLASS_KEYBOARD 0x03 // HID Class #define INTERFACE_SUB_CLASS_KEYBOARD 0x00 // Non-bootable #define INTERFACE_PROTOCOL_KEYBOARD 0x01 //Keyboard #define INTERFACE_INDEX_KEYBOARD 0 Set the INTERFACE_SUB_CLASS_KEYBOARD to 1 to convert the keyboard to a bootable device. 7. PC Software The USB keyboard application doesn t require any PC software. Limitations The demonstration does not manage the OUT report.you have to add the required code to handle this feature (refer to the section 6.3 for further details) 8. Related Documents AVR USB Datasheet (the related to the part number you are using) USB Software Library for AT90USBxxx Microcontrollers (Doc 7675) USB HID class specification 11

Headquarters International Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600 Atmel Asia Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369 Atmel Europe Le Krebs 8, Rue Jean-Pierre Timbaud BP 309 78054 Saint-Quentin-en- Yvelines Cedex France Tel: (33) 1-30-60-70-00 Fax: (33) 1-30-60-71-11 Atmel Japan 9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581 Product Contact Web Site www.atmel.com Technical Support avr@atmel.com Sales Contact www.atmel.com/contacts Literature Requests www.atmel.com/literature Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMEL S TERMS AND CONDI- TIONS OF SALE LOCATED ON ATMEL S WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDEN- TAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel s products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life. 2008 Atmel Corporation. All rights reserved. Atmel, logo and combinations thereof, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.