User manual

LPCXpresso Experiment Kit - User’s Guide
Page 126
Copyright 2013 © Embedded Artists AB
7.18 Extra: Work with USB Device
In this experiment you will learn how to work with an USB device interface. This experiment requires
an LPCXpresso board with USB device interface. The LPCXpresso Experiment Kit pcb has been
designed for the LPCXpresso LPC1769 board, but it is also possible to use the LPC1347 and
LPC11U14 boards.
7.18.1 Lab 17a: USB Device HID
The experiment will configure the LPC1769 as a USB Device with the HID (Human Interface Device)
class. The HID driver is always present in Windows and does not require any additional device drivers.
When using the USB Device interface a USB B to USB A cable is needed (not included in the kit).
Connect it to the J9 connector on the experiment board and to the PC.
This experiment is based on the code examples that are delivered with the LPCXpresso IDE. The code
is structured very differently (none of the code from the previous exercises is used). You have to create
a new workspace in LPCXpresso and then import the projects from Lab17a.zip.
Run the USBHID project on the LPCXpresso and let the PC discover it. Run the HIDClient.exe
program (found in the USBHID folder of Lab17a.zip) and select LPC17xx USB HID from the list.
Figure 69 HID Client Screenshot
Press the buttons on the experiment board and note what happens in the PC application. Click the
different output checkboxes or change the value in the text field.
The reading/writing of values are done in these two functions in main.c:
/*
* Get HID Input Report -> InReport
*/
void GetInReport (void) {
InReport = 0x00;
if ((LPC_GPIO0->FIOPIN & (1<<4)) == 0) InReport |= 0x01; //up pressed means 0
if ((LPC_GPIO0->FIOPIN & (1<<2)) == 0) InReport |= 0x02; //left pressed means 0
if ((LPC_GPIO1->FIOPIN & (1UL<<31)) == 0)InReport |= 0x04; //select pressed means 0
if ((LPC_GPIO0->FIOPIN & (1<<3)) == 0) InReport |= 0x08; //right pressed means 0
if ((LPC_GPIO2->FIOPIN & (1<<7)) == 0) InReport |= 0x10; //down pressed means 0
}
/*
* Set HID Output Report <- OutReport
*/
void SetOutReport (void) {
static unsigned long led_mask[] = { 1<<6, 1<<17, 1<<15, 1<<16,
1<<3, 1<<13, 1<<28, 1<<27 };
int i;
for (i = 0; i < LED_NUM; i++) {
if (OutReport & (1<<i)) {