Keyboard Host example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Keyboard Host example

Keyboard Host example

Description

This example implements a HID class host mode device that enumerates a HID class device with keyboard report descriptors and displays key press characters on a terminal.
NOTE: many keyboards enumerate as a HUB device which is not supported by this example.

Compiler build configurations

The software that makes up this example is designed to run on many different development boards. Therefore the compiler must be configured to build an image that is targeted to the development board you are using. This section explains how to set these build configurations for each of the supported compilers.

 

LPCXpresso IDE

Configure projects

  right click on the BSP project in the project explorer window
  click Build Configurations->Set Active->(see configuration in table below)
  repeat these steps with the CDL, nxpUSBlib, and Example_KeyboardHost

Configure MCU
  right click on the Example_KeyboardHost project in the project explorer window
  click Properties->C/C++ Build->MCU settings->(see configuration in table below)

Configure the indexer
   click Window->Preferences->C/C++->Indexer->Use active build configuration

 

BSP

CDL

nxpUSBlib

Example_KeyboardDevice

MCU

LPC1850  / Hitex

LPC18xx_HITEX

LPC18xx

LPC18xx_Host

LPC18xx

LPC1850

LPC4330  / Xplorer

LPC4330_Xplorer

LPC18xx

LPC18xx_Host

LPC18xx

LPC4330

LPC4350  / Element14

LPC1435_ELEMENT14

LPC18xx

LPC18xx_Host

LPC18xx

LPC4350

LPC1768  / MCB1700

LPC1768_MCB1700

LPC17xx

LPC17xx_Host

LPC17xx

LPC1768

LPC1768  / LPCXpresso

LPC17xx_LPCXpressoRevB

LPC17xx

LPC17xx_Host

LPC17xx

LPC1768


NOTE:
The LPC18xx CDL is used with boards that hold LPC43xx parts. This is done because the LPC43xx CDL is currently experimental. The LPC18xx USB library is used because both parts share the same controller.

Keil uVision 4 IDE

Configure a Batch Build

 

  click on Project->Batch Build...
  expand the BSP project to display a list of project targets
  select the project target by checking the appropriate checkbox (see target list in table below)
  repeat these steps with the CDL, nxpUSBlib_Host, and Example_KeyboardDevice

BSP

CDL

nxpUSBlib_Host

Example_KeyboardDevice

LPC1850  / Hitex

HITEX1800

LPC18xx

LPC18xx_Host

HITEX1800

LPC1768  / MCB1700

MCB1700

LPC17xx

LPC17xx_Host

MCB1700

 

Board connections and configurations

LPC18xx_HITEX (LPC1850 Hitex Evaluation Board)  older A2 design

schematic ./BSP/schematics/HITEX_SCM_LPC1850EVA-A2-2.pdf

Connect the JTAG to the 20 pin receptacle marked X4 JTAG
Connect a keyboard into the type A receptacle marked X10
Connect a 9-pin serial cable into the receptacle marked UART X1. Connect the other end of this cable into a PC running a terminal program.
To power the board:
  Connect the type-B end of a powered USB cable into the receptacle marked X13
  or
  Supply 5v to the DC connector labeled X14

 

LPC18xx_HITEX (LPC1850 Hitex Evaluation Board)  newer A3 design

schematic ./BSP/schematics/HITEX_Final_LPC1850EVA-A3.pdf

 

LPC1768_MCB1700 (Keil MCB1700 development board)

schematic: ./BSP/schematics/mcb1700-schematics.pdf

JumperSetting
  E/U1-2
UMODE1-2
D-Host
D+Host
VBUS1-2
VDDIO1-2
VDDREG1-2
ISPremoved

Connect the JTAG debugger to the 20 pin JTAG or 10 pin Cortex Debug connector
Connect a 9 pin serial cable between COM0 on the board and a PC running a terminal program. Baud rate = 9600
Plug a keyboard into the type A receptacle marked HOST
To power the board:
  Connect the type-B end of a powered USB cable to the type-B receptacle labeled 'Device'
  or
  Supply 5v to the -VIN+ pins between the JTAG and COM0 receptacles
Once the board is powered the following LEDs should be illuminated:
    Power
    100MHz
    USC

 

LPC17xx_LPCXpressoRevB (LPCXpresso LPC17xx on the LPCXpresso Rev B base board)

schematic: ./BSP/schematics/LPCXpressoLPC1769revB.pdf

 

Plug the LPCXpresso LPC1769 board into the connector labeled J4 on a
  LPCXpresso base board
Connect the JTAG to the mini USB receptacle labeled J3 on the LPCXpresso LPC1769
  board
Configure the base board according to the users guide from Embedded Artists
Install jumpers 1-2, 3-4, 5-6 on the jumper block marked J61 on the base board
Plug a keyboard into the type A receptacle marked J60 on the base board
Connect the mini type-B end of a USB cable to the USB-to-serial receptacle on
  the base board labeled X3 and the type-A end to the USB receptacle on a PC.
Once the USB cable is connected to the board the following LEDs should be
  illuminated:
    LED25  (vbus)
    LED26  (3.3v rail)
      

 

PC configuration

Use a PC running Windows XP, Vista or 7 to display runtime diagnostics that can be viewed with a terminal emulation program like Teraterm or Hyperterm. The baud rate in these programs should be set to 9600.

 

Build and debug the example


LPCXpresso IDE

In the project explorer window of the IDE right click on the Example_KeyboardHost project and select Debug As->C/C++ MCU Application
In the main window of the IDE click Run->Resume to start running the application

 

Keil uVision 4 IDE

In the Batch Build window, select the project targets as described in Compiler Build Configurations and then click Build
In the main window of the IDE click Debug->Start/Stop Debug Session click Debug->Run

 

How this example runs and what to look for

When the example is first run the terminal window will display:
Keyboard Host Demo running.

 

When the keyboard is plugged in the terminal window will display:
Device Attached.
Keyboard Enumerated.

 

When a key is pressed on the keyboard an upper case character corresponding
to that key will be displayed in the terminal window.

 

When the keyboard is unplugged the ternimal window will display:
Device Unattached.

No ratings
Version history
Last update:
‎04-25-2016 02:19 PM
Updated by: