3 * - By John Hodge (thePowersGang)
12 #include "usb_lowlevel.h"
13 #include <workqueue.h>
15 typedef struct sAsyncOp tAsyncOp;
26 void USB_ReadDescriptor(tUSBInterface *Iface, int Type, int Index, int Length, void *Data);
27 void USB_Request(tUSBInterface *Iface, int Endpoint, int Type, int Req, int Value, int Index, int Len, void *Data);
28 void USB_AsyncCallback(void *Ptr, void *Buf, int Length);
29 void USB_AsyncThread(void *unused);
32 tWorkqueue gUSB_AsyncQueue;
35 void USB_ReadDescriptor(tUSBInterface *Iface, int Type, int Index, int Length, void *Data)
37 USB_int_ReadDescriptor(Iface->Dev, 0, Type, Index, Length, Data);
40 void USB_Request(tUSBInterface *Iface, int Endpoint, int Type, int Req, int Value, int Index, int Len, void *Data)
45 if(Endpoint < 0 || Endpoint >= Iface->nEndpoints)
48 // Get endpoint number
50 endpt = Iface->Endpoints[Endpoint-1].EndpointNum;
54 USB_int_Request(Iface->Dev->Host, Iface->Dev->Address, endpt, Type, Req, Value, Index, Len, Data);
58 void USB_SendData(tUSBInterface *Dev, int Endpoint, int Length, void *Data)
60 Log_Warning("USB", "TODO: Implement USB_SendData");
63 void USB_RecvData(tUSBInterface *Dev, int Endpoint, int Length, void *Data)
65 Log_Warning("USB", "TODO: Implement USB_RecvData");
68 void USB_RecvDataA(tUSBInterface *Dev, int Endpoint, int Length, void *DataBuf, tUSB_DataCallback Callback)
73 ENTER("pDev iEndpoint iLength pDataBuf", Dev, Endpoint, Length, DataBuf);
75 op = malloc(sizeof(*op));
77 op->Endpt = &Dev->Endpoints[Endpoint-1];
81 // TODO: Handle transfers that are larger than one packet
83 host = Dev->Dev->Host;
84 LOG("IN from %p %i:%i", host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum);
85 host->HostDef->SendIN(
86 host->Ptr, Dev->Dev->Address, op->Endpt->EndpointNum,
87 0, USB_AsyncCallback, op,
93 // Log_Warning("USB", "TODO: Implement USB_RecvDataA");
96 void USB_AsyncCallback(void *Ptr, void *Buf, int Length)
100 LOG("adding %p to work queue", op);
101 Workqueue_AddWork(&gUSB_AsyncQueue, op);
104 void USB_AsyncThread(void *Unused)
106 Threads_SetName("USB Async IO Thread");
109 tAsyncOp *op = Workqueue_GetWork(&gUSB_AsyncQueue);
110 tUSBInterface *iface = op->Endpt->Interface;
114 iface->Driver->Endpoints[op->Endpt->EndpointIdx].DataAvail(
115 iface, op->Endpt->EndpointIdx,
116 op->Length, op->Data);