/**
* Initialize USB stack.
*/
-void usb_init()
+void usb_init(u32 reg)
{
core.drivers = list_create();
core.devices = list_create();
core.nextaddress = 1;
- hcdi_init();
+ hcdi_init(reg);
}
/**
* for the core. usb_add_device expected that
* the device answers to address zero.
*/
-struct usb_device *usb_add_device()
+struct usb_device *usb_add_device(u8 lowspeed, u32 reg)
{
struct usb_device *dev = (struct usb_device *) malloc(sizeof(struct usb_device));
dev->conf = (struct usb_conf *) malloc(sizeof(struct usb_conf));
dev->address = 0;
- /* send at first time only 8 bytes */
- dev->bMaxPacketSize0 = 8;
+ dev->fullspeed = lowspeed ? 0 : 1;
+ /* send at first time only 8 bytes for lowspeed devices
+ * 64 bytes for fullspeed
+ */
+ dev->bMaxPacketSize0 = lowspeed ? 8 : 64;
+ dev->ohci = reg;
dev->epSize[0] = 64;
dev->epSize[1] = 64;
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADING WTF :O lolololololo \n");
+ printf("loolololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDNG WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDINGWTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDING WTF :Ololololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDING WTF :O llololololo \n");
+ printf("lololololool PADDING WTF :O loololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDING WTF :O loloooloo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
- printf("lololololool PADDING WTF :O lolololololo \n");
- printf("lololololool PADDING WTF :O lolololololo \n");
- printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDING WTF :O lolololoolo \n");
+ printf("lololololool PADDING WTF :O lololooolo \n");
+ printf("lololololool PADDING WTF :O loloolololo \n");
printf("lololol PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
- printf("lolololool PADDING WTF :O lolololololo \n");
+ printf("lolololool PADDING WTF :O lololoololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lolololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
- printf("lololololool PADDING WTF :O lolololololo \n");
- printf("lololololool PADDING WTF :O lolololololo \n");
+ printf("lololololool PADDING WTF :O loloolololo \n");
+ printf("lololololool PADDING WTF lololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
printf("lololololool PADDING WTF :O lolololololo \n");
#endif
/* print device info */
lsusb(dev);
+ //HID only!
+#define GET_PROTOCOL 0x03
+#define SET_PROTOCOL 0x0b
+#define GETit 0xa1
+#define SETit 0x21
+
+
+ u8 buf[255];
+#if 1
/* select configuration */
- ret = usb_set_configuration(dev, dev->conf->bConfigurationValue);
- printf("=============\nusb_set_configuration(ret: %d) %d\n", ret, dev->conf->bConfigurationValue);
- printf("=============\nusb_get_configuration: %d\n", usb_get_configuration(dev));
+ wait_ms(500);
+ ret = usb_set_configuration(dev, 1);
+ printf("=============\nusb_set_configuration(ret: %d): %d\n", ret, dev->conf->bConfigurationValue);
+ wait_ms(500);
+ printf("=============\nusb_get_configuration: %d (should be 1 here)\n", usb_get_configuration(dev));
+#endif
#if 0
- u8 buf[8];
+ memset(buf, 0, 0xff);
+ usb_control_msg(dev, 0x81, GET_DESCRIPTOR, 0x2200, 0x0, 0x41, buf, 0);
+ printf("wtf request\n");
+ hexdump((void*)buf, 0x41);
+#endif
+
+#if 0
+ /* set protocol */
+ /* see p48 in HID spec */
memset(buf, 0, 8);
- usb_control_msg(dev, 0x00, SET_INTERFACE, 0, dev->conf->intf->bInterfaceNumber, 0, buf, 0);
- printf("=============\nusb_set_interface: %d\n", dev->conf->intf->bInterfaceNumber);
+ usb_control_msg(dev, SETit, SET_PROTOCOL, 0, 0, 0, buf, 0);
+ printf("=============\nhid_set_protocol %d\n", 0);
hexdump((void*)buf, 8);
-
+#endif
+#if 0
memset(buf, 0, 8);
- usb_control_msg(dev, 0x81, GET_INTERFACE, 0, dev->conf->intf->bInterfaceNumber, 8, buf, 0);
+ usb_control_msg(dev, GETit, GET_PROTOCOL, 0, 0, 4, buf, 0);
printf("=============\nusb_get_interface: %d\n", buf[0]);
hexdump((void*)buf, 8);
#endif
+#if 0
+ /* I just don't know why on some devices
+ * {s,g}et_{configuration,interface} won't work.
+ * may the setter works and getter are poorly implemented?
+ * however, I try here some interrupt inputs, assuming
+ * the setters are fine*/
+
+ memset(buf, 0, 8);
+ s8 epnum = dev->conf->intf->endp->bEndpointAddress & 0xf;
+ printf("epnum: 0x%04X\n", epnum);
+ u8 muh = 10;
+ while(muh--) {
+ (void) usb_interrupt_read(dev, epnum, buf, 8, 0);
+ printf("============\nusb_interrupt_read:\n");
+ hexdump((void*)buf, 8);
+ udelay(2000000);
+ }
+#endif
+
#if 0
/* add device to device list */
element *tmp = (element *) malloc(sizeof(element));
printf("=== Device Descriptor === \n");
printf("bLength 0x%02X\n", dev->bLength);
printf("bDescriptorType 0x%02X\n", dev->bDeviceClass);
- printf("bcdUSB 0x%02X\n", dev->bcdUSB);
+ printf("bcdUSB 0x%04X\n", dev->bcdUSB);
printf("bDeviceClass 0x%02X\n", dev->bDeviceClass);
printf("bDeviceSubClass 0x%02X\n", dev->bDeviceSubClass);
printf("bDeviceProtocoll 0x%02X\n", dev->bDeviceProtocoll);
+ printf("bMaxPacketSize 0x%02X\n", dev->bMaxPacketSize0);
printf("idVendor 0x%04X\n", dev->idVendor);
printf("idProduct 0x%04X\n", dev->idProduct);
printf("bcdDevice 0x%04X\n", dev->bcdDevice);
printf("iProduct(0x%02X): \"%s\"\n", dev->iProduct, dev->iProduct ? usb_get_string_simple(dev, dev->iProduct) : "no String");
printf("iSerialNumber(0x%02X): \"%s\"\n", dev->iSerialNumber, dev->iSerialNumber ? usb_get_string_simple(dev, dev->iSerialNumber) : "no String");
printf("bNumConfigurations 0x%02X\n", dev->bNumConfigurations);
-
+
u8 c, i, e;
struct usb_conf *conf = dev->conf;
for(c=0; c <= dev->bNumConfigurations; c++) {
ed = ed->next;
} //endpoint
-
+
ifs = ifs->next;
} //interface
togl = togl ? 0 : 1;
/**** send token ****/
- hcdi_enqueue(td);
+ hcdi_enqueue(td, irp->dev->ohci);
/***************** Data Stage ***********************/
/**
}
/**** send token ****/
- hcdi_enqueue(td);
+ hcdi_enqueue(td, irp->dev->ohci);
/* pruefe ob noch weitere Pakete vom Device abgeholt werden muessen */
restlength = restlength - irp->epsize;
td->pid = USB_PID_IN;
}
/**** send token ****/
- hcdi_enqueue(td);
+ hcdi_enqueue(td, irp->dev->ohci);
free(td);
break;
case USB_BULK:
- core.stdout("bulk\r\n");
//u8 runloop=1;
//u16 restlength = irp->len;
//char * td_buf_ptr=irp->buffer;
/* schleife die die tds generiert */
while (runloop) {
-
td = usb_create_transfer_descriptor(irp);
td->endpoint = td->endpoint & 0x7F; /* clear direction bit */
td_buf_ptr = td_buf_ptr + irp->epsize;
td->togl = togl;
- if (togl == 0)
- togl = 1;
- else
- togl = 0;
+ togl = togl ? 0 : 1;
/**** send token ****/
- hcdi_enqueue(td);
+ hcdi_enqueue(td, irp->dev->ohci);
free(td);
}
/* next togl */
irp->dev->epTogl[(irp->endpoint & 0x7F)] = togl;
break;
+
+ case USB_INTR:
+ //u8 runloop=1;
+ //u16 restlength = irp->len;
+ //char * td_buf_ptr=irp->buffer;
+
+ /* schleife die die tds generiert */
+ while (runloop && (restlength > 0)) {
+ td = usb_create_transfer_descriptor(irp);
+ /* max packet size for given endpoint */
+ td->actlen = irp->epsize;
+
+ td->pid = USB_PID_IN;
+ /* TODO: USB_PID_OUT */
+
+ /* stop loop if all bytes are send */
+ if (restlength < irp->epsize) {
+ runloop = 0;
+ td->actlen = restlength;
+ }
+
+ td->buffer = td_buf_ptr;
+ /* move pointer for next packet */
+ td_buf_ptr += irp->epsize;
+
+ td->togl = togl;
+ togl = togl ? 0 : 1;
+
+ /**** send token ****/
+ hcdi_enqueue(td, irp->dev->ohci);
+ restlength = restlength - irp->epsize;
+ free(td);
+ }
+ break;
+ irp->dev->epTogl[(irp->endpoint & 0x7F)] = togl;
}
- hcdi_fire();
+ hcdi_fire(irp->dev->ohci);
return 1;
}
td->iso = 0;
td->state = USB_TRANSFER_DESCR_NONE;
td->maxp = irp->epsize;
+ td->fullspeed = irp->dev->fullspeed;
+ td->type = irp->type;
return td;
}