1.1 --- a/test.c Wed Feb 13 00:06:17 2013 +0000
1.2 +++ b/test.c Wed Feb 13 00:29:18 2013 +0000
1.3 @@ -309,6 +309,33 @@
1.4 }
1.5
1.6 /**
1.7 + * Send a control request to the given address consisting of the given setup
1.8 + * data.
1.9 + */
1.10 +uint8_t max_control(uint8_t address, uint8_t *setup)
1.11 +{
1.12 + uint8_t status, hrsl = 0;
1.13 +
1.14 + max_write_fifo(0, setup, 8);
1.15 +
1.16 + /* Set the address. */
1.17 +
1.18 + max_write(MAX_REG_PERADDR, address);
1.19 +
1.20 + /* Initiate the transfer. */
1.21 +
1.22 + do
1.23 + {
1.24 + status = max_write(MAX_REG_HXFR, MAX_HXFR_SETUP);
1.25 + status = max_wait_transfer(status);
1.26 + hrsl = max_read(MAX_REG_HRSL, &status);
1.27 + }
1.28 + while ((hrsl & MAX_HRSL_HRSLT) != 0);
1.29 +
1.30 + return status;
1.31 +}
1.32 +
1.33 +/**
1.34 * Send a request to the given address and endpoint, using the supplied data
1.35 * payload with the given length, indicating the preserved toggle state of the
1.36 * endpoint (which will be updated).
1.37 @@ -319,7 +346,8 @@
1.38
1.39 max_write_fifo(endpoint, data, len);
1.40
1.41 - max_set_send_toggle(*toggle);
1.42 + if (endpoint)
1.43 + max_set_send_toggle(*toggle);
1.44
1.45 /* Set the address. */
1.46
1.47 @@ -329,7 +357,7 @@
1.48
1.49 do
1.50 {
1.51 - status = max_write(MAX_REG_HXFR, endpoint | MAX_HXFR_OUTNIN | (endpoint ? 0 : MAX_HXFR_SETUP));
1.52 + status = max_write(MAX_REG_HXFR, endpoint | MAX_HXFR_OUTNIN);
1.53 status = max_wait_transfer(status);
1.54
1.55 /* Test for usable data. */
1.56 @@ -341,7 +369,8 @@
1.57 }
1.58 while ((hrsl & MAX_HRSL_HRSLT) != 0);
1.59
1.60 - *toggle = max_get_send_toggle();
1.61 + if (endpoint)
1.62 + *toggle = max_get_send_toggle();
1.63
1.64 return status;
1.65 }
1.66 @@ -349,21 +378,16 @@
1.67 /**
1.68 * Make a request for data from the given address and endpoint, collecting it in
1.69 * the supplied buffer with the given length, indicating the preserved toggle
1.70 - * state of the endpoint (which will be updated), and providing optional setup
1.71 - * data (for control transfers). The length will be updated to indicate the
1.72 - * total length of the received data.
1.73 + * state of the endpoint (which will be updated) The length will be updated to
1.74 + * indicate the total length of the received data.
1.75 */
1.76 -uint8_t max_recv(uint8_t address, uint8_t endpoint, uint8_t *data, uint8_t *len, bool *toggle, uint8_t *setup)
1.77 +uint8_t max_recv(uint8_t address, uint8_t endpoint, uint8_t *data, uint8_t *len, bool *toggle)
1.78 {
1.79 uint8_t *datalimit = data + *len;
1.80 uint8_t status, hrsl = 0;
1.81
1.82 - /* Write control transfer information, if appropriate. */
1.83 -
1.84 - if (!endpoint)
1.85 - max_write_fifo(endpoint, setup, 8);
1.86 -
1.87 - max_set_send_toggle(*toggle);
1.88 + if (endpoint)
1.89 + max_set_send_toggle(*toggle);
1.90
1.91 /* Set the address. */
1.92
1.93 @@ -395,7 +419,8 @@
1.94 }
1.95 while (status & MAX_HIRQ_RCVDAVIRQ);
1.96
1.97 - *toggle = max_get_send_toggle();
1.98 + if (endpoint)
1.99 + *toggle = max_get_send_toggle();
1.100
1.101 return status;
1.102 }
1.103 @@ -599,7 +624,8 @@
1.104 {
1.105 printf("Sending control request to address 0, endpoint 0...\n");
1.106 setup_packet(setup, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, USB_DT_DEVICE, 0, USB_DT_DEVICE_SIZE);
1.107 - max_recv(0, 0, data, &len, &in_toggle, setup);
1.108 + max_control(0, setup);
1.109 + max_recv(0, 0, data, &len, &in_toggle);
1.110 }
1.111 if (status & MAX_HIRQ_SUSDNIRQ)
1.112 printf("Suspend done.\n");