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



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

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

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

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

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

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

AVR287: USB Host HID and Mass Storage Demonstration. 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

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

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

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

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

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 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

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

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

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

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

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

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

AT91SAM ARM-based Flash MCU. Application Note

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

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

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

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

AT89C5131A Starter Kit... Software User Guide

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. 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

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

General Porting Considerations. Memory EEPROM XRAM

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

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.

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

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

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

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

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

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

AT88CK490 Evaluation Kit

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

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

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

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

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

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

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

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

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

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

USER GUIDE. ZigBit USB Stick User Guide. Introduction

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

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

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

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

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

USER GUIDE EDBG. Description

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

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

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

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

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

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

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

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

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

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

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

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

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

AT89LP Flash Data Memory. Application Note. AT89LP Flash Data Memory API. 1. Introduction. 2. Theory of Operation. 2.1 Flash Memory Operation

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

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

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

MODFLEX MINI GATEWAY ETHERNET USER S GUIDE

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

AT91 ARM Thumb Microcontrollers. Application Note. GNU-Based Software Development on AT91SAM Microcontrollers. 1. Introduction. 2.

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

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

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

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

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

Designing Feature-Rich User Interfaces for Home and Industrial Controllers

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

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

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

4.0. Offline Folder Wizard. User Guide

Using WinUSB in a Visual Studio Project with Freescale USB device controller

New Features and Enhancements

formerly Help Desk Authority Quest Free Network Tools User Manual

Introduction to Version Control in

Getting started with DfuSe USB device firmware upgrade STMicroelectronics extension

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

Dell One Identity Cloud Access Manager How to Configure vworkspace Integration

How To Design An Ism Band Antenna For 915Mhz/2.4Ghz Ism Bands On A Pbbb (Bcm) Board

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

USB Test Environment ATUSBTEST- SS7400. Summary

Transcription:

USB PC Drivers Based on Generic HID Class Supported by Windows 98 SE or later Full Duplex Communication Send Commands Through the EP 0 Dynamic Link Library Supported by any Compiler: VC++, JAVA, VB... Auto-detection of device for VC++ application Point-to-Point Communication USB Microcontrollers Application Note 1. Introduction This application note describes how to integrate the USB HID DLL in your application. The provided examples are based on VC++ and JAVA compilers, however the DLL can be used with any compiler (VB, Delphi, LabView...). Simple code examples that demonstrate different types of implementation are given.

2. DLL functions As specified in the USB HID specification, the Generic HID application uses two reports (IN/OUT) to send and receive data. The length of these reports is assigned in the firmware and automatically detected by the DLL following the firmware setting (please refer to the USB Generic HID Implementation application note to see how to modify these values if needed). Please note that this DLL allows you to communicate with one Generic HID device and only one device at a time. You cannot manage several devices at the same time using this DLL. Figure 2-1. DLL functions NO Find the HID Device findhiddevice(vid, PID) YES Send data to the device writedata(*buff) Get data from the device readdata(*buff) Send commands to the device setfeature(*buff) Get the IN report length getreportlength() Get the OUT report length getoutputreportlength() Get the Feature report length getfeatureputreportlength() Close all handles closedevice(). 2.1 findhiddevice This function (BOOLEAN) allows to find the Generic HID device using the vendor ID (VID)/the product ID (PID) and open a handle if the device is connected. const UINT VendorID: this is the vendor ID const UINT ProductID: this is the product ID Output FALSE: if the device is not found. More information can be found using GetLastError(). GetLastError will return: 2 Application Note

Application Note ERROR_USB_DEVICE_NOT_FOUND if Device is cannot be found. ERROR_USB_DEVICE_NO_CAPABILITIES if device found but capabilities cannot be retrieved. TRUE: if the connection has succeeded and the handle is opened. 2.2 closedevice 2.3 writedata 2.3.1 Output 2.4 readdata 2.4.1 Output 2.5 setfeature Closes the communication with the USB device and all related handles. This function (BOOLEAN) sends data to the device (OUT data). The maximum data length supported by this function must be lower or equal to the value given by the function getoutputreportlength (see Section 2.9 on page 5). If the data length exceeds the maximum length specified in the firmware, the user has to send data in several packets. When data length is lower than the maximum length, this function will complete the remaining bytes with zero (0x00). UCHAR* buffer: pointer of the packet to be sent. FALSE: if data transmission fails. GetLastError() will return ERROR_WRITE_FAULT code TRUE: if the packet was successfully transferred. This function (BOOLEAN) read the data packets sent by the device (IN data). To avoid data loss this function should be called in continuous mode (using a thread or a timer).. UCHAR* buffer: Pointer to the buffer which will contain the received packet. The buffer must have the length of the IN report given by the getreportlength function (see Section 2.10 on page 5). FALSE: if no data is available. TRUE: if data are received and stored in the buffer. This function (BOOLEAN) allows the user to send a command data to control the HID device (i.e.: Start the bootloader, start a new task...). Data will be transmitted over the endpoint 0 as a SetReport request (Refer to the HID Specification for further information). The endpoints IN and OUT will be used for the applicative raw data transfer only. 3

The data length is fixed by the firmware and can be obtained using the function getfeaturereportlength (please refer to the Section 2.11 on page 5). The data length must not exceed the length returned by getfeaturereportlength function. UCHAR* buffer: Pointer to the buffer which contains the received packet. Output FALSE:if data transmission fails. TRUE: if data are well transferred. 2.6 hidregisterdevicenotification Please note that this function can be used only with VC++ project. This function notifies the application if a new plug & play device has been plugged or unplugged. HWND hwnd - Handle to a window. Output FALSE: if the function fails. To get extended error information, call GetLastError. TRUE: if the function succeeds. 2.7 hidunregisterdevicenotification Please note that this function can be used only with VC++ project. This function closes the specified device notification handle. HWND hwnd - Handle to a window. Output FALSE: if the function fails. To get extended error information, call GetLastError. TRUE: if the function succeeds. 2.8 ismydevicenotification Please note that this function can be used only with VC++ project. This function allows to check if the new device (plugged or unplugged) notified by hidregister- DeviceNotification is the used HID device or not. DWORD dwdata, the value given by OnDeviceChange 2 nd parameters Output TRUE: if the device connected/disconnected is the used HID device FALSE: if this is another device 4 Application Note

Application Note 2.9 getoutputreportlength This function allows the user to get the length of the OUT report (data packet sent from the PC to the device). This value is specified in the firmware. 2.10 getreportlength This function allows the user to get the length of the IN report (data packet sent from the device to the PC). This value is specified in the firmware. 2.11 getfeaturereportlength This function allows the user to get the length of the Feature report (Control data packet sent from the PC to the device). This value is specified in the firmware. 3. PC demos 3.1 VC++ demo The VC++ demo allows the user to see how to load the AtUsbHid.dll in a project, and also how to use the plug & play notification. 3.1.1 Load the DLL in Visual C++ Application The file AtUsbHid.h provides the macros which help to load and use the functions present in the Atmel USB HID DLL. When designing an application using the DLL you need to do the following: create a handler for the DLL: HINSTANCE hlib = NULL; Load the DLL using the function hlib =LoadLibrary(AT_USB_HID_DLL); Load each DLL functions using loadfuncpointers(hlib) Once these steps have been performed without error, the DLL and its functions are loaded in your application and can be called using the macro DYNCALL(DllFunction()). When the application is stopped, it is convenient to free the DLL from memory using the function FreeLibrary(hLib). You must ensure that USB device handle has been closed before freeing the DLL from memory. 3.1.2 Using Automatic Device Connection/Disconnection Feature The DLL provides the functions which allow the user to detect the connection/disconnection of the device. To perform this feature you have to do the following actions: Register you application to get device change notification using: DYNCALL(hidRegisterDeviceNotification)((m_hWnd)). Add the function ON_WM_DEVICECHANGE() in your Message Map application. Creates a function called OnDeviceChange(UINT neventtype, DWORD dwdata) which will be called each time a device status changes. In the function OnDeviceChange, call the function DYNCALL(isMyDeviceNotification(dwData)) to know if the status of your device has changed (connected or disconnected). (See code demo code in UsbHidDemoCodeDlg.cpp) 5

When exiting the application, it is convenient to unregister it using the function: DYNCALL(hidUnregisterDeviceNotification(m_hWnd)). 3.1.3 Using readdata As data can be sent continuously by the device. It s interesting to read data using a timer base function. This allows you to poll continuously the readdata function. 3.1.4 User Interface To do so, you have to do the following: Add the function ON_WM_TIMER() in your Message Map application. Create a function OnTimer(UINT nidevent) which will call the function DYNCALL(readData(sbuffer). Now you can set the Timer for a specified interval using SetTimer(n,x,y); to call the readdata function each x ms when your device is connected. Kill the timer using KillTimer(n) when your device is disconnected. Hereunder is a screen shot of the provided demo. Please note that the default PID is related to one specific demo (Atmel demos which have a Generic HID interface do not have the same PID). You may have to modify this PID parameter to match with the device you are using (refer to the firmware or the device manager to get the VID/PID used by your demo) Figure 3-1. VC++ based demo Hereunder is the description of the GUI components: The Vendor ID, Product ID box are used to specify the VID/PID of the device. OK button should be pushed once the VID/PID are correctly set. LED 1...LED4 button are used to switch ON/OFF the LEDs of the board. Firmware Upgrade button allows the user to start the bootloader to upgrade the firmware through the USB interface (Refer to the bootloader datasheet for further details). 6 Application Note

Application Note Exit button closes the application Status field gives the connection state and also when the device is connected gives the lengths of the IN report, OUT report and Feature report (these parameters will be automatically used by the DLL to send/receive data) 3.1.5 DOS demo This demo gives a simple console application example. This demo uses a fixed VID/PID and has to be recompiled to modify these parameters. The device have to be connected and running with the Generic HID firmware before performing this console application. Figure 3-2. DOS Interface Note: This project can be compiled using the MinGw (www.mingw.org). The command line is: mingw32-g++ -O2 -Wall UsbHidSmallDemoCode.cpp -o AtUsbHidMinGw.exe -I. 3.2 JAVA demo The JAVA demo allows the user to see how to integrate the AtUsbHid.dll in a JAVA project. The interface between the AtUsbHid.dll and the JAVA is done through the package AtUsbHidJni.jar. 3.2.1 AtUsbHid.dll integration To integrate the AtUsbHid.dll you have to follow the steps below: Add the following code in the import section of your JAVA file: import com.atmel.atusbhidjni.atusbhidjni Create a new object to use the DLL: AtUsbHidJni usbdevice = new AtUsbHidJni(); 7

3.2.2 User interface Load the DLL: usbdevice.loadlibraryusbhid(); Now, the DLL is ready for use. Please refer to the DLL functions section for further details regarding the DLL functionalities. Before existing the application, it is important to unload the DLL: usbdevice.unloadloadlibraryusbhid(); To compile the project, please add to the class path of the AtUsbHidJni.jar package: JAVAc userhid.java -classpath AtUsbHidJni.jar Note: Please refer to the HTML documentation provided with the DLL package for further information. The GUI source code is available in the JNICodeForHIDDLL folder. Hereunder is the JAVA user interface: Figure 3-3. JAVA User interface The components have the same roles as described for the VC++ interface (refer to section 3.1.4). The Auto-Connect box is used to allow the application to detect automatically the connection/disconnection of the device. 3.2.3 DOS demo This demo gives a simple console application example. The demo uses a fixed VID/PID and has to be recompiled to modify these parameters. The device has to be connected and running with the Generic HID firmware before performing this console application. 8 Application Note

Application Note Figure 3-4. DOS Interface 4. The package architecture When you unzip the DLL package, you ll find several folders. Hereunder is the content of each one: 4.1 AtUsbHid 4.2 ExeDemo This folder contains the AtUsbHid.dll and the AtUsbHid.h files. This folder contains the different executable demo examples. 4.3 JNICodeForHIDDLL This folder contains the source code of the JAVA project. 4.4 UsbHidDemoCode This folder contains the source code of the VC++ project. 4.5 UsbHidSmallDemoCode This folder contains the source code of the VC++ small demo (DOS demo). 9

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 8051@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.