1.1 --- a/test.c Sun Feb 17 01:07:49 2013 +0000
1.2 +++ b/test.c Sat Feb 23 19:10:59 2013 +0000
1.3 @@ -284,15 +284,6 @@
1.4 }
1.5
1.6 /**
1.7 - * Send HS payload for control transfers.
1.8 - */
1.9 -uint8_t max_send_hs()
1.10 -{
1.11 - uint8_t status = max_write(MAX_REG_HXFR, MAX_HXFR_HS);
1.12 - return max_wait_transfer(status);
1.13 -}
1.14 -
1.15 -/**
1.16 * Write the given data to the FIFO.
1.17 */
1.18 void max_write_fifo(uint8_t endpoint, uint8_t *data, uint8_t len)
1.19 @@ -329,9 +320,8 @@
1.20 */
1.21 uint8_t max_control(uint8_t address, uint8_t *setup)
1.22 {
1.23 - uint8_t status, hrsl = 0;
1.24 + uint8_t status, hrsl;
1.25
1.26 - printf("Writing FIFO with setup...\n");
1.27 max_write_fifo(0, setup, 8);
1.28
1.29 /* Set the address. */
1.30 @@ -342,12 +332,29 @@
1.31
1.32 do
1.33 {
1.34 - printf("Initiating transfer...\n");
1.35 status = max_write(MAX_REG_HXFR, MAX_HXFR_SETUP);
1.36 status = max_wait_transfer(status);
1.37 hrsl = max_read(MAX_REG_HRSL, &status);
1.38 - printf("HRSL = %x\n", hrsl);
1.39 - sleep(1);
1.40 + }
1.41 + while (hrsl & MAX_HRSL_HRSLT);
1.42 +
1.43 + return status;
1.44 +}
1.45 +
1.46 +/**
1.47 + * Perform a status transaction as part of a larger control transaction.
1.48 + * The out parameter is used to indicate the kind of status transfer to be
1.49 + * performed and should be the inverse of the control transfer direction.
1.50 + */
1.51 +uint8_t max_control_status(bool out)
1.52 +{
1.53 + uint8_t status, hrsl;
1.54 +
1.55 + do
1.56 + {
1.57 + status = max_write(MAX_REG_HXFR, MAX_HXFR_HS | (out ? MAX_HXFR_OUTNIN : 0));
1.58 + status = max_wait_transfer(status);
1.59 + hrsl = max_read(MAX_REG_HRSL, &status);
1.60 }
1.61 while (hrsl & MAX_HRSL_HRSLT);
1.62
1.63 @@ -564,6 +571,7 @@
1.64 setup_packet(setup, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, USB_DT_DEVICE, 0, USB_DT_DEVICE_SIZE);
1.65 max_control(0, setup);
1.66 max_recv(0, 0, data, &len, in_toggle);
1.67 + max_control_status(true);
1.68
1.69 if (len >= sizeof(struct usb_device_descriptor))
1.70 {