Commit 53985415 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

Add USB test host-side software (not working)

parent 1ff35de5
CC = gcc
INCLUDE =
SOURCES = usbled.c
LIB = -L/usr/lib/i386-linux-gnu
LDFLAGS = -lusb
all:
$(CC) $(INCLUDE) $(LIB) $(LDFLAGS) -o usbled $(SOURCES)
#include <stdio.h>
#include <usb.h>
#define LED_SET 0x11
int main()
{
static usb_dev_handle *pDevH = NULL; // USB device handle
static struct usb_device *pDev;
static struct usb_bus *pBus;
int led = 0;
usb_init();
usb_find_busses();
usb_find_devices();
// Enumerate USB devices ...
for ( pBus = usb_get_busses(); pBus; pBus = pBus->next)
{
for ( pDev = pBus->devices; pDev; pDev = pDev->next)
{
if ( ( pDev->descriptor.idVendor == 0x10C4 ) &&
( pDev->descriptor.idProduct == 0x00ff ) )
{
pDevH = usb_open( pDev );
if ( pDevH )
{
if ( usb_set_configuration(
pDevH, pDev->config->bConfigurationValue ) != 0 )
{
usb_close( pDevH );
pDevH = NULL;
printf("FAIL: usb_set_configuration");
}
if ( pDev->descriptor.idProduct == 0x00ff )
{
if ( usb_claim_interface( pDevH, 0 ) != 0 )
{
usb_close( pDevH );
pDevH = NULL;
printf("FAIL: usb_claim_interface");
}
}
}
}
}
}
while (1) {
led ^= 1;
if ( pDevH )
{
usb_control_msg(
pDevH, // Device handle
USB_ENDPOINT_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
// bmRequestType
LED_SET, // bRequest
0, // wValue
led, // wIndex
NULL, // char *pBuffer
1, // wLength
1000 ); // Timeout (ms)
sleep(1);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment