* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+/*
+ ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
+ libusb like interface
+
+Copyright (C) 2009 Bernhard Urban <lewurm@gmx.net>
+Copyright (C) 2009 Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
+
+# This code is licensed to you under the terms of the GNU GPL, version 2;
+# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+*/
+
#include "usb.h"
#include "core.h"
#include "../host/host.h"
/******************* Control Transfer **********************/
-
/**
* Create a control transfer.
*/
s8 usb_control_msg(struct usb_device *dev, u8 requesttype, u8 request,
u16 value, u16 index, u16 length, u8 *buf, u16 timeout)
{
- struct usb_irp *irp = (struct usb_irp*)malloc(sizeof(struct usb_irp));
- irp->dev = dev;
- irp->endpoint = 0;
-
- irp->epsize = dev->bMaxPacketSize0;
- irp->type = USB_CTRL;
+ static struct usb_irp irp;
+ memset(&irp, 0, sizeof(struct usb_irp));
+
+ irp.dev = dev;
+ irp.endpoint = 0;
+
+ irp.epsize = dev->bMaxPacketSize0;
+ irp.type = USB_CTRL;
buf[0]=(u8)requesttype;
buf[1]=(u8)request;
buf[6]=(u8)(length);
buf[7]=(u8)(length >> 8);
- irp->buffer = buf;
- irp->len = length;
- irp->timeout = timeout;
+ irp.buffer = buf;
+ irp.len = length;
+ irp.timeout = timeout;
- usb_submit_irp(irp);
- free(irp);
+ usb_submit_irp(&irp);
return 0;
}
off += 7;
}
}
-
- printf("=============\nafter usb_get_desc_config_ext:\n");
- hexdump((void*) gbuf, dev->conf->wTotalLength);
return 0;
}
{
cleargbuf();
usb_control_msg(dev, 0x00, SET_ADDRESS, address, 0, 0, gbuf, 0);
+ wait_ms(210);
return 0;
}
u8 usb_get_configuration(struct usb_device *dev)
{
cleargbuf();
- usb_control_msg(dev, 0x80, GET_CONFIGURATION, 0, 0, 8, gbuf, 0);
+ usb_control_msg(dev, 0x80, GET_CONFIGURATION, 0, 0, 4, gbuf, 0);
+ printf("=============\nafter usb_get_configuration:\n");
+ hexdump((void*) gbuf, 8);
return gbuf[0];
}
{
cleargbuf();
usb_control_msg(dev, 0x00, SET_CONFIGURATION, configuration, 0, 0, gbuf, 0);
+ printf("=============\nafter usb_set_configuration:\n");
+ hexdump((void*) gbuf, 8);
+ wait_ms(20);
return 0;
}
return 0;
}
+static s8 usb_gen_rw(struct usb_device *dev, u8 ep, u8 *buf, u8 size, u8 timeout, u8 type) {
+ static struct usb_irp irp;
+ memset(&irp, 0, sizeof(struct usb_irp));
+ irp.dev = dev;
+ irp.endpoint = ep;
+ irp.epsize = dev->epSize[ep & 0x7F];
+ irp.type = type;
-/******************* Bulk Transfer **********************/
+ irp.buffer = buf;
+ irp.len = size;
+ irp.timeout = timeout;
+
+ usb_submit_irp(&irp);
+ return 0;
+}
+/******************* Bulk Transfer **********************/
/**
* Write to an a bulk endpoint.
*/
s8 usb_bulk_write(struct usb_device *dev, u8 ep, u8 *buf, u8 size, u8 timeout)
{
- struct usb_irp * irp = (struct usb_irp*)malloc(sizeof(struct usb_irp));
- irp->dev = dev;
- //irp->devaddress = dev->address;
-
- irp->endpoint = ep;
- irp->epsize = dev->epSize[ep]; // ermitteln
- irp->type = USB_BULK;
-
- irp->buffer = buf;
- irp->len = size;
- irp->timeout = timeout;
-
- usb_submit_irp(irp);
- free(irp);
-
- return 0;
+ return usb_gen_rw(dev, ep, buf, size, timeout, USB_BULK);
}
/**
*/
s8 usb_bulk_read(struct usb_device *dev, u8 ep, u8 *buf, u8 size, u8 timeout)
{
- struct usb_irp * irp = (struct usb_irp*)malloc(sizeof(struct usb_irp));
- //irp->devaddress = dev->address;
- irp->dev = dev;
-
- irp->endpoint = ep | 0x80; // from device to host
- irp->epsize = dev->epSize[ep]; // ermitteln
- irp->type = USB_BULK;
-
- irp->buffer = buf;
- irp->len = size;
- irp->timeout = timeout;
-
- usb_submit_irp(irp);
- free(irp);
-
- return 0;
+ return usb_gen_rw(dev, ep|0x80, buf, size, timeout, USB_BULK);
}
*/
s8 usb_interrupt_write(struct usb_device *dev, u8 ep, u8 *buf, u8 size, u8 timeout)
{
-
- return 0;
+ return usb_gen_rw(dev, ep, buf, size, timeout, USB_INTR);
}
/**
*/
s8 usb_interrupt_read(struct usb_device *dev, u8 ep, u8 *buf, u8 size, u8 timeout)
{
-
- return 0;
+ return usb_gen_rw(dev, ep|0x80, buf, size, timeout, USB_INTR);
}
return 0;
}
-
-//#endif //_USB_H_