USB Library
Linux

 

The SimpleLibUSBDemo program and the associated firmware demonstrate how to use the Libusb device drivers for basic general purpose USB data transfer. To make the PC source code as easy to understand as possible, the demo has deliberately been made simple, and only sends/receives small amounts of data. 

Before you can run the SimpleLibUSBDemo executable, you will need to have the libusb 0.1 driver installed on your computer. The libusb can be downloaded from sourceforge.net. 

The source code for SimpleLibUSBDemo.exe file was created using QT3 Designer. The source code can be found in the “<Install Directory>\ USB Device - Libusb - Generic Driver Demo\Libusb Simple Demo - Linux Application\ Libusb Simple Demo - Linux Application -QT3” directory. 

To launch the application, open the Terminal and navigate to the “<Install Directory>\USB Device - LibUSB - Generic Driver Demo\Linux Application” directory and execute the following commands

  1. chmod a+x SimpleLibusbDemo_Linux (This command gives executable right to the file on this Linux computer
  2. sudo ./SimpleLibusbDemo_Linux.
Enter the Super user password when requested. A window like that shown below should appear: 

 

In order to begin sending/receiving packets to the device, you must first find and “connect” to the device. As configured by default, the application is looking for USB devices with VID = 0x04D8 and PID = 0x0204. The device descriptor in the firmware project meant to be used with this demo uses the same VID/PID. To run the demo program the USB device with the correct precompiled .hex file. If you are connecting the device for the first time, Windows pops up a window asking you to install the driver for the device. When asked for the driver point it to the inf file provided along with the demo. Windows takes while to install the driver for the USB device that is just plugged in. Open the Device manager and ensure that the USB device is listed under the ‘Libusb Demo Devices’. Once the driver is installed hit the “Connect” button, the other pushbuttons should become enabled. If hitting the connect button has no effect, it is likely the USB device is either not connected, or has not been programmed with the correct firmware. 

Hitting the Toggle LED(s) should send a single packet of general purpose generic data to the Custom class USB peripheral device. The data will arrive on the Bulk OUT endpoint. The firmware has been configured to receive this generic data packet, parse the packet looking for the “Toggle LED(s)” command, and should respond appropriately by controlling the LED(s) on the demo board. 

The “Get Pushbutton State” button will send one packet of data over the USB to the peripheral device (to the Bulk OUT endpoint) requesting the current pushbutton state. The firmware will process the received Get Pushbutton State command, and will prepare an appropriate response packet depending upon the pushbutton state. 

The PC then requests a packet of data from the device (which will be taken from the Bulk IN endpoint). Once the PC application receives the response packet, it will update the pushbutton state label. 

Try experimenting with the application by holding down the appropriate pushbutton on the demo board, and then simultaneously clicking on the “Get Pushbutton State” button. Then try to repeat the process, but this time without holding down the pushbutton on the demo board. 

To make for a more fluid and gratifying end user experience, a real USB application would probably want to launch a separate thread to periodically poll the pushbutton state, so as to get updates regularly. This is not done in this simple demo, so as to avoid cluttering the PC application project with source code that is not related to USB communication. 

In order to build the application navigate to the “<Install Directory>\USB Device - LibUSB - Generic Driver Demo\Linux Application\Qt3” directory and execute the command “make”.

MLA - USB Library Help Version : 2.16
http://www.microchip.com/mla