Subversion Repositories group.electronics

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 pfowler 1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <avr/wdt.h>
4
 
5
#include "usbdrv.h"
6
 
7
#define F_CPU 12000000
8
#include <util/delay.h>
9
 
10
#define USB_LED_OFF 0
11
#define USB_LED_ON  1
12
 
13
 
14
int main() {
15
    uchar i;
16
	DDRD |= (1 << PD6); // PB0 as output
17
 
18
    wdt_enable(WDTO_1S); // enable 1s watchdog timer
19
 
20
    usbInit();
21
 
22
    usbDeviceDisconnect(); // enforce re-enumeration
23
    for(i = 0; i<250; i++) { // wait 500 ms
24
        wdt_reset(); // keep the watchdog happy
25
        _delay_ms(2);
26
    }
27
    usbDeviceConnect();
28
 
29
    sei(); // Enable interrupts after re-enumeration
30
 
31
    while(1) {
32
        wdt_reset(); // keep the watchdog happy
33
        usbPoll();
34
    }
35
 
36
    return 0;
37
}
38
 
39
// this gets called when custom control message is received
40
USB_PUBLIC uchar usbFunctionSetup(uchar data[8]) {
41
    usbRequest_t *rq = (void *)data; // cast data to correct type
42
 
43
    switch(rq->bRequest) { // custom command is in the bRequest field
44
    case USB_LED_ON:
45
        PORTD |= (1 << PD6); // turn LED on
46
        return 0;
47
    case USB_LED_OFF: 
48
        PORTD &= ~(1 << PD6); // turn LED off
49
        return 0;
50
    }
51
 
52
    return 0; // should not get here
53
}