Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

softusb: move retrieval of device descriptor to separate function

  • Loading branch information...
commit b2fc9ce37389b8575a89e62d6c9edd606b921809 1 parent efd771a
@wpwrak wpwrak authored sbourdeauducq committed
Showing with 17 additions and 11 deletions.
  1. +17 −11 softusb-input/main.c
View
28 softusb-input/main.c
@@ -527,6 +527,22 @@ static const char unsupported_device[] PROGMEM = "unsupported device\n";
static const char mouse[] PROGMEM = "mouse\n";
static const char keyboard[] PROGMEM = "keyboard\n";
+static int get_device_descriptor(unsigned char *buf, int size)
+{
+ struct setup_packet packet;
+
+ packet.bmRequestType = 0x80;
+ packet.bRequest = 0x06;
+ packet.wValue[0] = 0x00;
+ packet.wValue[1] = 0x01;
+ packet.wIndex[0] = 0x00;
+ packet.wIndex[1] = 0x00;
+ packet.wLength[0] = size;
+ packet.wLength[1] = 0x00;
+
+ return control_transfer(ADDR, &packet, 0, buf, size);
+}
+
static void port_service(struct port_status *p, char name)
{
if(p->state > PORT_STATE_BUS_RESET)
@@ -600,19 +616,9 @@ static void port_service(struct port_status *p, char name)
break;
}
case PORT_STATE_GET_DEVICE_DESCRIPTOR: {
- struct setup_packet packet;
unsigned char device_descriptor[18];
- packet.bmRequestType = 0x80;
- packet.bRequest = 0x06;
- packet.wValue[0] = 0x00;
- packet.wValue[1] = 0x01;
- packet.wIndex[0] = 0x00;
- packet.wIndex[1] = 0x00;
- packet.wLength[0] = 18;
- packet.wLength[1] = 0x00;
-
- if(control_transfer(ADDR, &packet, 0, device_descriptor, 18) >= 0) {
+ if(get_device_descriptor(device_descriptor, 18) >= 0) {
p->retry_count = 0;
print_string(vid);
print_hex(device_descriptor[9]);
Please sign in to comment.
Something went wrong with that request. Please try again.