summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2014-03-30 19:30:54 +0200
committerFlorian Jung <flo@windfisch.org>2014-03-30 19:30:54 +0200
commit14cd49b3b3c2eb6b8c8c7f26d762f3363ea63b07 (patch)
tree94329d380708a0f4df45773abc256a3336dcdd71
parent0dc2a225b7716d05d0526336566e715c1d421fc5 (diff)
pc can read and write \o/
-rw-r--r--main.c36
-rw-r--r--usbdrv/usbconfig.h2
2 files changed, 36 insertions, 2 deletions
diff --git a/main.c b/main.c
index f7c8756..a3d1b28 100644
--- a/main.c
+++ b/main.c
@@ -6,11 +6,17 @@
#include <avr/interrupt.h>
#include "usbdrv/usbdrv.h"
-
+static uchar replyBuf[18]= "Hello, World!";
/* device is detected, however unreliably. dunno why. */
+static uchar dataReceived, dataLength;
+void debug(int i)
+{
+ if (i >= 63) i=63;
+ PORTB = ~i;
+}
USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
{
@@ -20,12 +26,40 @@ USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
{
case 0: PORTB |= 1; break;
case 1: PORTB &= ~1; break;
+
+ case 2: usbMsgPtr = replyBuf; return sizeof(replyBuf); // pc reads
+ case 3: // alter byte
+ PORTB = ~(rq->wIndex.word & 0xFF);
+ if ((rq->wIndex.word >= 0) && (rq->wIndex.word < sizeof(replyBuf)))
+ {
+ replyBuf[rq->wIndex.word] = rq->wValue.word;
+ }
+ break;
+ case 4: // pc writes
+ dataLength = rq->wLength.word;
+ debug(dataLength);
+ dataReceived = 0;
+
+ return USB_NO_MSG;
+
}
return 0;
}
+USB_PUBLIC uchar usbFunctionWrite(uchar* data, uchar len)
+{
+ PORTB&=~32;
+ for (uchar i = 0; dataReceived < dataLength && i < len; i++, dataReceived++)
+ {
+ if (0 <= dataReceived && dataReceived < sizeof(replyBuf))
+ replyBuf[dataReceived] = data[i];
+ }
+
+ return (dataReceived >= dataLength);
+}
+
int main (void)
{
diff --git a/usbdrv/usbconfig.h b/usbdrv/usbconfig.h
index 858c95d..48d4a93 100644
--- a/usbdrv/usbconfig.h
+++ b/usbdrv/usbconfig.h
@@ -123,7 +123,7 @@ section at the end of this file).
* The value is in milliamperes. [It will be divided by two since USB
* communicates power requirements in units of 2 mA.]
*/
-#define USB_CFG_IMPLEMENT_FN_WRITE 0
+#define USB_CFG_IMPLEMENT_FN_WRITE 1
/* Set this to 1 if you want usbFunctionWrite() to be called for control-out
* transfers. Set it to 0 if you don't need it and want to save a couple of
* bytes.