aboutsummaryrefslogtreecommitdiffstats
path: root/examples/custom-class/firmware
diff options
context:
space:
mode:
authorChristian Starkjohann <cs+github@obdev.at>2008-05-13 15:15:13 +0000
committerChristian Starkjohann <cs+github@obdev.at>2008-05-13 15:15:13 +0000
commitdfcb2cf64a95e99e5325bf3290697ac7823994bc (patch)
treeefd8ac1bbba5bb0d3c5dbdbe56fb8d8cd652f5cd /examples/custom-class/firmware
parent1cc341a56727a0d1bcc3a2eb3d4f2a312ee740a3 (diff)
downloadv-usb-dfcb2cf64a95e99e5325bf3290697ac7823994bc.tar.gz
v-usb-dfcb2cf64a95e99e5325bf3290697ac7823994bc.tar.bz2
v-usb-dfcb2cf64a95e99e5325bf3290697ac7823994bc.zip
- added (optional) reliability test in custom-class example
Diffstat (limited to 'examples/custom-class/firmware')
-rw-r--r--examples/custom-class/firmware/main.c11
-rw-r--r--examples/custom-class/firmware/requests.h4
2 files changed, 13 insertions, 2 deletions
diff --git a/examples/custom-class/firmware/main.c b/examples/custom-class/firmware/main.c
index 940f62e..e12ef00 100644
--- a/examples/custom-class/firmware/main.c
+++ b/examples/custom-class/firmware/main.c
@@ -37,15 +37,22 @@ different port or bit, change the macros below:
usbMsgLen_t usbFunctionSetup(uchar data[8])
{
usbRequest_t *rq = (void *)data;
+static uchar dataBuffer[4]; /* buffer must stay valid when usbFunctionSetup returns */
- if(rq->bRequest == CUSTOM_RQ_SET_STATUS){
+ if(rq->bRequest == CUSTOM_RQ_ECHO){ /* echo -- used for reliability tests */
+ dataBuffer[0] = rq->wValue.bytes[0];
+ dataBuffer[1] = rq->wValue.bytes[1];
+ dataBuffer[2] = rq->wIndex.bytes[0];
+ dataBuffer[3] = rq->wIndex.bytes[1];
+ usbMsgPtr = dataBuffer; /* tell the driver which data to return */
+ return 4;
+ }else if(rq->bRequest == CUSTOM_RQ_SET_STATUS){
if(rq->wValue.bytes[0] & 1){ /* set LED */
LED_PORT_OUTPUT |= _BV(LED_BIT);
}else{ /* clear LED */
LED_PORT_OUTPUT &= ~_BV(LED_BIT);
}
}else if(rq->bRequest == CUSTOM_RQ_GET_STATUS){
- static uchar dataBuffer[1]; /* buffer must stay valid when usbFunctionSetup returns */
dataBuffer[0] = ((LED_PORT_OUTPUT & _BV(LED_BIT)) != 0);
usbMsgPtr = dataBuffer; /* tell the driver which data to return */
return 1; /* tell the driver to send 1 byte */
diff --git a/examples/custom-class/firmware/requests.h b/examples/custom-class/firmware/requests.h
index b6a3c2b..2e7fac3 100644
--- a/examples/custom-class/firmware/requests.h
+++ b/examples/custom-class/firmware/requests.h
@@ -16,6 +16,10 @@
#ifndef __REQUESTS_H_INCLUDED__
#define __REQUESTS_H_INCLUDED__
+#define CUSTOM_RQ_ECHO 0
+/* Request that the device sends back wValue and wIndex. This is used with
+ * random data to test the reliability of the communication.
+ */
#define CUSTOM_RQ_SET_STATUS 1
/* Set the LED status. Control-OUT.
* The requested status is passed in the "wValue" field of the control