summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/main.c72
-rw-r--r--firmware/usbconfig.h8
2 files changed, 13 insertions, 67 deletions
diff --git a/firmware/main.c b/firmware/main.c
index c6694d2..5a863e9 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -31,80 +31,24 @@ Application examples:
#ifndef TEST_DRIVER_SIZE /* define this to check out size of pure driver */
-static uchar actionTimers[8];
-static uchar permstatus = 255;
-
-/* This is the AT90S2313 version of the routine. Change for others. */
-static void outputByte(uchar b)
-{
- DDRB = ~b;
-}
-
-static uchar computeTemporaryChanges(void)
-{
- return 0;
-}
-
-static void computeOutputStatus(void)
-{
- outputByte(permstatus);
-}
-
-/* We poll for the timer interrupt instead of declaring an interrupt handler
- * with global interrupts enabled. This saves recursion depth. Our timer does
- * not need high precision and does not run at a high rate anyway.
- */
-static void timerInterrupt(void)
-{
-static uchar prescaler;
-uchar i;
-
- if(!prescaler--){
- prescaler = 8; /* rate = 12M / 1024 * 256 * 9 */
- for(i=0;i<8;i++){
- if(actionTimers[i])
- actionTimers[i]--;
- }
- computeOutputStatus();
- }
-}
-
USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
{
usbRequest_t *rq = (void *)data;
-uchar status = permstatus;
static uchar replyBuf[2];
usbMsgPtr = replyBuf;
- if(rq->bRequest == 0){ /* ECHO */
+ if(rq->bRequest == 0) { /* ECHO */
replyBuf[0] = rq->wValue.bytes[0];
replyBuf[1] = rq->wValue.bytes[1];
return 2;
}
- if(rq->bRequest == 1){ /* GET_STATUS -> result = 2 bytes */
+ if(rq->bRequest == 1) { /* GET_STATUS -> result = 1 bytes */
replyBuf[0] = PINB;
- replyBuf[1] = computeTemporaryChanges();
- return 2;
+ return 1;
}
- if(rq->bRequest == 2 || rq->bRequest == 3){ /* SWITCH_ON or SWITCH_OFF, index = bit number */
- uchar bit = rq->wIndex.bytes[0] & 7;
- uchar mask = 1 << bit;
- uchar needChange, isOn = status & mask;
- if(rq->bRequest == 2){ /* SWITCH_ON */
- status |= mask;
- needChange = !isOn;
- }else{ /* SWITCH_OFF */
- status &= ~mask;
- needChange = isOn;
- }
- if(rq->wValue.bytes[0] == 0){ /* duration == 0 -> permanent switch */
- actionTimers[bit] = 0;
- permstatus = status;
- }else if(needChange){ /* temporary switch: value = duration in 200ms units */
- actionTimers[bit] = rq->wValue.bytes[0];
- }
+ if(rq->bRequest == 2) { /* SET_STATUS. Payload byte is output. */
+ DDRB = ~(rq->wIndex.bytes[0]);
}
- computeOutputStatus();
return 0;
}
@@ -131,7 +75,6 @@ uchar i;
* that it should re-enumerate the device. Otherwise the host's and device's
* concept of the device-ID would be out of sync.
*/
- computeOutputStatus(); /* set output status before we do the delay */
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
i = 0;
while(--i){ /* fake USB disconnect for > 500 ms */
@@ -147,7 +90,10 @@ uchar i;
usbPoll();
if(TIFR & (1 << TOV0)){
TIFR |= 1 << TOV0; /* clear pending flag */
- timerInterrupt();
+ /*
+ * a periodic (low-frequency, low-accuracy) loop function can
+ * be placed here.
+ */
}
}
return 0;
diff --git a/firmware/usbconfig.h b/firmware/usbconfig.h
index beaec6a..585d16d 100644
--- a/firmware/usbconfig.h
+++ b/firmware/usbconfig.h
@@ -141,8 +141,8 @@ the newest features and options.
#define USB_CFG_DEVICE_VERSION 0x00, 0x01
/* Version number of the device: Minor number first, then major number.
*/
-#define USB_CFG_VENDOR_NAME 'w', 'w', 'w', '.', 'o', 'b', 'd', 'e', 'v', '.', 'a', 't'
-#define USB_CFG_VENDOR_NAME_LEN 12
+#define USB_CFG_VENDOR_NAME 'f', 'i', 'n', 'a', 'l', 'r', 'e', 'w', 'i', 'n', 'd', '.', 'o', 'r', 'g'
+#define USB_CFG_VENDOR_NAME_LEN 15
/* These two values define the vendor name returned by the USB device. The name
* must be given as a list of characters under single quotes. The characters
* are interpreted as Unicode (UTF-16) entities.
@@ -151,8 +151,8 @@ the newest features and options.
* obdev's free shared VID/PID pair. See the file USBID-License.txt for
* details.
*/
-#define USB_CFG_DEVICE_NAME 'P', 'o', 'w', 'e', 'r', 'S', 'w', 'i', 't', 'c', 'h'
-#define USB_CFG_DEVICE_NAME_LEN 11
+#define USB_CFG_DEVICE_NAME 'V', 'U', 'S', 'B', '-', 'I', '2', 'C'
+#define USB_CFG_DEVICE_NAME_LEN 8
/* Same as above for the device name. If you don't want a device name, undefine
* the macros. See the file USBID-License.txt before you assign a name.
*/