LPC 1752 USB problem

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

LPC 1752 USB problem

592 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by hong2004123 on Fri Mar 29 04:42:38 MST 2013
We are using LPC1752 to write the HID mouse program. however, I did not know how to write the USB output program which send the information and data to the PC.
Anyone can help me.
0 Kudos
Reply
1 Reply

567 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Tue Apr 02 04:40:19 MST 2013

Quote:
We are using LPC1752 to write the HID mouse program. however, I did not know how to write the USB output program which send the information and data to the PC.


In the LPCXpresso examples folder (C:\nxp\LPCXpresso_5.1.2_2065\lpcxpresso\Examples\NXP\LPC1000\LPC17xx)
you'll see a couple of HID examples, which can be ported to LPC1752 easily.

The first one is RDB1768cmsis2_usb_hidmouse example in RDB1768cmsis2.zip
This one seems to come from LPCUSB
In HandleFrame() routine of this example, USBHwEPWrite() passes an input report to the interrupt IN endpoint to send it to host. HandleFrame() is called at SOF interrupt, and this routine counts 100 using _iFrame variable. Therefore, the input report is sent every 100ms interval.
RDB1768cmsis2_usb_hidmouse\src\main_mouse.c

static void HandleFrame(U16 wFrame)
{
    static int iCount;

    _iFrame++;
    if ((_iFrame > 100)) {
        iCount++;
        USBHwEPWrite(INTR_IN_EP, (void *)&MouseInputReport, REPORT_SIZE);
        _iFrame = 0;
    }
}


The second one is USBHID in NXP_LPCXpresso1769_MCB1700_2011-02-11.zip, which comes from KEIL examples.
This one is a generic HID example, but you change it into a HID mouse by replacing the report descriptor. In this example, the first report is set to the endpoint at the callback of Set_Configuration request, using USB_WriteEP(). And then, the second and later reports are put in the endpoint1 ISR. In this implementation, the input report is sent at the interval specified by the bInterval field of the endpoint descriptor.
USBHID\src\usbuser.c

#if USB_CONFIGURE_EVENT
void USB_Configure_Event (void) {

  if (USB_Configuration) {                   /* Check if USB is configured */
    GetInReport();
    USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));
  }
}
#endif

void USB_EndPoint1 (uint32_t event) {

  switch (event) {
    case USB_EVT_IN:
      GetInReport();
      USB_WriteEP(HID_EP_IN, &InReport, sizeof(InReport));
      break;
  }    
}


Both methods will work, but I recommend you neither for mouse implementation.
Practical implementation in commercial mouse is,
- send the input report just when the mouse detects movement or button click by user.

Your firmware polls movement and button click (or release) at the interval, equal to or greater than bInterval of the endpoint descriptor. When this polling detects movement or click, your firmware fills the IN endpoint with the input report using USBHwEPWrite() or USB_WriteEP()

If you would strictly follow the USB HID spec, the report interval is determined by the host by Set_Idle request. Windows set 0 (indefinite) interval by Set_Idle - ie. the report is sent just when any change occurs, like above practical implementation. MacOSX sets it to 36ms, but most of commercial implementation ignores it, and they work in the same way on Windows.

Tsuneo
0 Kudos
Reply