// ====================================================================== // JVdG USB Gadget libusb test program // // Copyright 2011 Julien Viard de Galbert // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, // MA 02110-1301, USA. // ====================================================================== #include #include enum { // Generic requests USBTINY_ECHO, // echo test USBTINY_READ, // read byte USBTINY_WRITE, // write byte USBTINY_CLR, // clear bit USBTINY_SET, // set bit // USBTINY_KEY_READ // read key status }; #define USB_TIMEOUT 500 libusb_device_handle * usb_device; int main(int argc, char ** argv) { libusb_init(NULL); printf("USB gadget test program (c) 2010 Julien VdG\n"); usb_device = libusb_open_device_with_vid_pid (NULL, 0x6666, 0x0001); if(NULL == usb_device) { fprintf(stderr, "ERROR: USB device not found !\n"); libusb_exit(NULL); return 2; } { unsigned char res[4]; int st; st = libusb_control_transfer(usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, USBTINY_READ, 0, 0, res, 1, USB_TIMEOUT); printf("Read LEDs: %x (%d)\n",res[0], st); st = libusb_control_transfer(usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, USBTINY_WRITE, 0xf & (res[0]+1), 1, NULL, 0, USB_TIMEOUT); st = libusb_control_transfer(usb_device, LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE, USBTINY_KEY_READ, 0, 0, res, 1, USB_TIMEOUT); printf("Read Keys: %x (%d)\n",res[0], st); } libusb_close(usb_device); libusb_exit(NULL); return 0; }