Skip to content

Commit

Permalink
Use xusb on all consoles
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryOderNichts committed Jun 13, 2022
1 parent 04fcff0 commit 5186c04
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
24 changes: 9 additions & 15 deletions bdk/usb/xusbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,9 @@ static int _xusb_wait_ep_stopped(u32 endpoint)

static int _xusb_handle_transfer_event(transfer_event_trb_t *trb)
{
if (trb->comp_code != XUSB_COMP_SUCCESS)
gfx_printf("Error: ep_id %d comp_code %d\n", trb->ep_id, trb->comp_code);

// Advance dequeue list.
data_trb_t *next_trb;
switch (trb->ep_id)
Expand Down Expand Up @@ -1359,16 +1362,6 @@ static int _xusb_handle_port_change()
return USB_RES_OK;
}

static int _xusb_handle_get_ep_status(u32 ep_idx)
{
u32 ep_mask = BIT(ep_idx);
static u8 xusb_ep_status_descriptor[2] = {0};

xusb_ep_status_descriptor[0] =
(XUSB_DEV_XHCI(XUSB_DEV_XHCI_EP_HALT) & ep_mask) ? USB_STATUS_EP_HALTED : USB_STATUS_EP_OK;
return _xusb_issue_data_trb(xusb_ep_status_descriptor, 2, USB_DIR_IN);
}

static int _xusb_handle_get_class_request(usb_ctrl_setup_t *ctrl_setup)
{
u8 _bRequest = ctrl_setup->bRequest;
Expand Down Expand Up @@ -1445,9 +1438,7 @@ static int _xusbd_handle_ep0_control_transfer(usb_ctrl_setup_t *ctrl_setup)
u16 _wLength = ctrl_setup->wLength;

static u8 xusb_dev_status_descriptor[2] = {USB_STATUS_DEV_SELF_POWERED, 0};
static u8 xusb_interface_descriptor[4] = {0};
static u8 xusb_configuration_descriptor[2] = {0};
static u8 xusb_status_descriptor[2] = {0};

//gfx_printf("ctrl: %02X %02X %04X %04X %04X\n", _bmRequestType, _bRequest, _wValue, _wIndex, _wLength);

Expand Down Expand Up @@ -1519,13 +1510,16 @@ static int _xusbd_handle_ep0_control_transfer(usb_ctrl_setup_t *ctrl_setup)
break;
case USB_REQ_CUSTOM:
// after we overwrote the stack, consider this device configured
usbd_xotg->device_state = XUSB_CONFIGURED;
usbd_xotg->device_state = XUSB_CONFIGURED_STS_WAIT;

// fall through
case USB_REQUEST_GET_DESCRIPTOR:
size = device_setup(&udpih_device, ctrl_setup, (u8 *)USB_DESCRIPTOR_ADDR, usbd_xotg->port_speed == XUSB_HIGH_SPEED);
transmit_data = true;
break;
if (size >= 0)
return _xusb_issue_data_trb((u8 *)USB_DESCRIPTOR_ADDR, size, USB_DIR_IN);
// Unknown desc req.
xusb_set_ep_stall(XUSB_EP_CTRL_IN, USB_EP_CFG_STALL);
return USB_RES_OK;
case USB_REQUEST_GET_CONFIGURATION:
xusb_configuration_descriptor[0] = usbd_xotg->config_num;
desc = xusb_configuration_descriptor;
Expand Down
13 changes: 6 additions & 7 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void run_udpih()

gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
display_backlight_brightness(150, 1000);

gfx_printf("Hold both volume buttons to cancel.\n");
gfx_printf("Starting USB...\n");

if ((res = usb_ops.usb_device_init()))
Expand All @@ -73,6 +73,7 @@ void run_udpih()
gfx_printf("Stage 0 disconnecting...\n");

usb_ops.usbd_end(true, true);
usb_ops.usb_device_init();

udpih_device.state = STATE_DEVICE1_CONNECTED;
gfx_printf("Stage 1 connecting...\n");
Expand All @@ -83,6 +84,7 @@ void run_udpih()
gfx_printf("Stage 1 disconnecting...\n");

usb_ops.usbd_end(true, true);
usb_ops.usb_device_init();

udpih_device.state = STATE_DEVICE2_CONNECTED;
gfx_printf("Stage 2 connecting...\n");
Expand Down Expand Up @@ -389,14 +391,11 @@ void ipl_main()
minerva_change_freq(FREQ_800);

// Get USB Controller ops.
if (hw_get_chip_id() == GP_HIDREV_MAJOR_T210)
usb_device_get_ops(&usb_ops);
else
// udpih note: xusb is entirely untested
xusb_device_get_ops(&usb_ops);
xusb_device_get_ops(&usb_ops);

// start the usb controller to allow keeping the usb cable plugged in
// reset the usb controller to allow plugging in the cable before starting the gadget
usb_ops.usb_device_init();
usleep(10000);
usb_ops.usbd_end(true, true);

while (true)
Expand Down
2 changes: 1 addition & 1 deletion udpih/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static const usb_cfg_descr_t config_descriptor = {
.bDescriptorType = USB_DESCRIPTOR_CONFIGURATION,
.wTotalLength = cpu_to_le16(sizeof(usb_cfg_descr_t)),
.bNumInterfaces = 0,
.bConfigurationValue = 0,
.bConfigurationValue = 1,
.iConfiguration = 0,
.bmAttributes = USB_ATTR_SELF_POWERED | USB_ATTR_BUS_POWERED_RSVD,
.bMaxPower = 32 / 2,
Expand Down

0 comments on commit 5186c04

Please sign in to comment.