Blame | Last modification | View Log | RSS feed
#include <avr/io.h>#include <avr/interrupt.h>#include <avr/wdt.h>#include "usbdrv.h"#define F_CPU 12000000#include <util/delay.h>#define USB_LED_OFF 0#define USB_LED_ON 1int main() {uchar i;DDRD |= (1 << PD6); // PB0 as outputwdt_enable(WDTO_1S); // enable 1s watchdog timerusbInit();usbDeviceDisconnect(); // enforce re-enumerationfor(i = 0; i<250; i++) { // wait 500 mswdt_reset(); // keep the watchdog happy_delay_ms(2);}usbDeviceConnect();sei(); // Enable interrupts after re-enumerationwhile(1) {wdt_reset(); // keep the watchdog happyusbPoll();}return 0;}// this gets called when custom control message is receivedUSB_PUBLIC uchar usbFunctionSetup(uchar data[8]) {usbRequest_t *rq = (void *)data; // cast data to correct typeswitch(rq->bRequest) { // custom command is in the bRequest fieldcase USB_LED_ON:PORTD |= (1 << PD6); // turn LED onreturn 0;case USB_LED_OFF:PORTD &= ~(1 << PD6); // turn LED offreturn 0;}return 0; // should not get here}