2014年3月10日星期一

HID protocol -based industrial design custom keyboard interface

Abstract : The next big trend in intelligent transformation equipment , embedded computer applications to a large number of industrial control systems , custom industrial keyboards are becoming more and more widespread application . This paper presents a protocol based on a custom USB HID keyboard design , simple design and practical function , free driver automatically identified. Good solution to the on-demand keyboard device design requirements , to facilitate the system PC software programming, close to engineering practice, the application prospect.

With the promotion of intelligent industrial equipment , more industrial equipment using embedded control computer as its core . Embedded computer system as a platform for product development , the need for control unit hardware and user application software design . In the application software design aspects , the inevitable need to use human interface devices to complete operator control of computer systems , industrial keyboard as the most common type of input device , into our line of sight .

Industrial Keyboard difference between standard keyboard, which is designed to meet all the key requirements of a particular product design , common interfaces have PS / 2 and USB. USB devices with hot-swappable and frame acquisition rate advantages, is gradually replacing the original PS / 2 devices into the mainstream of the market. This paper describes the design of custom industrial keyboard a USB interface , intelligent CNC equipment to solve the problem of the keyboard customization .

1 USB BID Introduction

Plug and play USB interface is a serial bus communications port , is widely used in various types of computer systems. HID class devices belonging to human-computer interaction device is a USB device in a larger class , used to control the operation of a computer , such as a USB mouse , USB keyboard and other equipment. Operating system comes with a HID class drivers, eliminating the need to write drivers , so some simple USB device , like a HID device enumeration facilitate the design also facilitates the use .

All HID USB device via control pipe (default pipe is endpoint 0 ) and interrupt pipes to communicate with the host. Control pipe is mainly used for : receiving referrals USB host control and related class data ; transfer data at USB host queries ; receive USB host data . Broken pipe is mainly used for : USB Host USB device to receive asynchronous data transmission ; USB host sends real-time requirements of the data to the USB device .

Let the computer equipment identified as a HID keyboard device , the main work to be done is to modify the HID device descriptor. HID device descriptor includes five USB standard descriptors ( device descriptor, configuration descriptor, interface descriptor, endpoint descriptor string descriptor ) and three class-specific descriptor HID devices (HID descriptors, report descriptor , physical descriptor ) . You can modify the descriptor HID device enumeration for the mouse , keyboard and other HID devices.

2 System Design

Custom USB keyboard from the industrial point of view the system constitutes a major part of the design into a keyboard and a USB interface design in two parts. System block diagram shown in Figure 1.

Which part of the keyboard scanning keyboard customized according to the specific hardware and software design requirements , allow sufficient I / O, roughly the same design . USB interface part , the current microprocessor USB communication program more, mainly in the following three kinds : 1 ) SCM + PDIUSBD12 chip structure ; 2 ) using Cypress 's USB2.0 protocol integrated microprocessor CY7C68013A chip ; 3 ) selection STM32 family of processors based on ARM Cortex-M3 core. Three kinds of options have their advantages , SCM + PDIUSBD12 chip structure , simple design, low cost ; using CY7C68013A chip , highly integrated, built to facilitate protocol development ; selection STM32 family of processors , a simple circuit , high performance, scalability, there resource -rich firmware , and facilitate the development .

As a new generation of 32-bit STM32 processor family , the performance improvement is evident, the price is reasonable , cost is very high , there is a very broad application prospects . So here build USB keyboard hardware platform STM32F103C8T6 industrial processing chip .

3 Hardware Design

STM32F103C8T6 is a medium -capacity STM32 product , which is based on the ARM Cortex-M3 core with 64K on-chip flash memory , LOFP-48 package , USB interface and a wealth of other peripheral interfaces. Use STM32F103C8T6 USB communication interface design , the circuit is simple, stable performance, the circuit diagram shown in Figure 2 .

Figure J1 USB interface directly with the STM32 processor PA11, PA12 connected , J3, J4 keyboard scan interface of leads 16 IO, can scan up to 8 × 8 matrix keyboard that is 64 keys. The remaining circuit processor minimum system circuit .

4 Software Design

ST companies to provide us with a detailed The USB-FS-Device library firmware library , clear firmware library program structure is divided into two parts and the upper ground floor .

1 ) the underlying structure includes five files : usb_core.c (USB bus data processing core files ), usb_init.c, usb_int.c ( for Endpoint Data Input interrupt processing ), usb_mem.c ( for buffer operation ) , usb_regs.c ( for register operations ) .

2 ) superstructure total of five documents : hw_config.c ( for USB hardware configuration ), usb_pwr.c ( for USB connection , disconnection operation ), usb_istr.c ( directly handle USB interrupt ), usb_prop.c ( for upper-layer protocol processing, such as HID protocol , a mass storage device protocol ), usb_desc.c ( descriptor associated definitions and specific processing equipment ) .

Based on STM32 USB firmware library main design flow shown in Figure 3 .

Device initialization work done are: initialize the system clock , GPIO and related equipment ; configuration used by the USB interrupt ; configure and enable USB clock ; initialize the global pointer .

After entering the main circle, scan button changes the button to change through SendReport () function key status is sent to the USB host. In fact here is to write data IN endpoint buffer , hosts IN token packet comes , SIE is responsible to return it to the host.

5 System Testing and Application

After the software design is complete, the program is downloaded to the STM32 processor , USB connection to the computer processor power , after the completion of device initialization , turn on the computer device manager can see the keyboard device add a HID Keyboard Device ( Figure 4 ) , then the device has been used as a standard HID keyboard device is identified computer.

The next work to be carried out according to the keyboard customization requirements, access to documents HID uses tables to determine the ranks of the value of the corresponding key on the keyboard IPC code , modify the function SendReport (), to complete the custom keyboard programming . Function SendReport () returns an array of 8 bytes reported temporary Buf [8] in . By defining and HID report descriptor table uses the document , known Buf [0] is the left Ctrl key is D0 , D1 is the left Shift key , D2 is the left Alt key , D3 is left GUI ( ie Window button ), D4 is the right Ctrl , D5 is the right Shift, D6 is the right Alt, D7 is the right GUI key. Buf [1] reserved , a value of 0 . Buf [2]-Buf [7] is the key , can have up to six .


6 Conclusions

In the field of industrial control applications , industrial keyboard customization uncommon. Through the USB HID devices studied, custom USB Industrial keyboard design , the circuit is simple , low cost , no driver automatically identify , with a high practical value and broad application prospects .