diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -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) { |