Example #1
0
int main(void)
{
	uchar   i = 1;
	uchar	hidCurrentMode = 255;
	char remainingData=0;
	uchar offset=0;

	HardwareInit();
	usbInit();

	// Set up descriptor
	hidMode = HIDM_1P;
	ReadController(1);
	SetHIDMode();

    for(;;){                /* main event loop */
        usbPoll();
        if(usbInterruptIsReady()){
            /* called after every poll of the interrupt endpoint */
			ReadController(i);
			RemapButtons(&(reportBuffer.b1), &(reportBuffer.b2));
			RemapButtons(&(reportBufferWheel.b1), &(reportBufferWheel.b2));
			remainingData=reportBufferLength;
			offset=0;
			// handle report with more than 8 byte length (for NegCon and future expansion)
			do {
				if (remainingData<=8) {
					usbSetInterrupt(reportBufferAddress+offset, remainingData);
					remainingData=0;
				}
				else {	
					usbSetInterrupt(reportBufferAddress+offset, 8);				
					offset+=8;
					remainingData-=8;
					do {
						usbPoll();
					} while (!usbInterruptIsReady());	
				}
			} while (remainingData>0);				
				
			i++;
			if (i > hidNumReports) i = 1;
			if (hidCurrentMode != hidMode)
			{
				SetHIDMode();
				hidCurrentMode = hidMode;
			}
        }
    }

    return 0;
}
void sendPS3Data(dataForController data)
{
/* The data being transferred is in the following format:
	byte0 - 8 buttons ( bit0...bit7 =
				[blue][green][red][yellow][orange][star power][is higher frets][unused]
	byte1 - 5 buttons, 3bits padding bit0...bit7 = 
				[select][start][??][??],[ps3 button],[pad][pad][pad]
	byte2 - hat switch 
			0000 N, 0001 N/E, 0010 E, 0011 SE, 0100 S, 0101 SW, 0110 W, 0111, NW, 1000, nothing pressed
	byte3 - x axis (unused)
	byte4 - y axis (unused)
	byte5 - z axis (Whammy Bar)
	byte6 - rzaxis (Choose solo style)
*/
       //set the buttons to all at default positions
        reportBuffer[0] = 0b00000000;
        reportBuffer[1] = 0b00000000;
        reportBuffer[2] = 0b00001000;
        reportBuffer[3] = 0b10000000;
        reportBuffer[4] = 0b10000000;
        reportBuffer[5] = 0b10000000;
        reportBuffer[6] = 0b00000000;


        // Since 'colorOn' is 1 when a fret is pressed, we shift it to the proper place and | it to set the
        // corresponding button bit to one, which corresponds to a button press.
        reportBuffer[0] |= (data.orangeOn << ORANGE_BIT);
        reportBuffer[0] |= (data.blueOn << BLUE_BIT);
        reportBuffer[0] |= (data.yellowOn << YELLOW_BIT);
        reportBuffer[0] |= (data.redOn << RED_BIT);
        reportBuffer[0] |= (data.greenOn << GREEN_BIT);

        // On the PS3, the strumming shows up as a hat switch, so we have to use conditionals for this..
        if (data.upOn)
                reportBuffer[2] = 0b00000000;
        if (data.downOn)
                reportBuffer[2] = 0b00000100;

		// Now set the whammy bar data
		reportBuffer[5] = data.numberOfStringsPressed;

		//Finally, Start, Star Power, and the Home button (not working yet)
		reportBuffer[1] |= (data.plusOn << PLUS_BIT);
        reportBuffer[0] |= (data.minusOn << MINUS_BIT);
		reportBuffer[1] |= (data.homeOn << HOME_BIT);

        //Then we finish off some USB stuff.
        wdt_reset();  //Reset the watchdog timer
        usbPoll();    //USB poll - must be called at least once per 10ms

        // Now, regardless of mode, we have to send the data to the 
        // USB controlling library from the buffer we've been building
        if(usbInterruptIsReady())
        {
            /* called after every poll of the interrupt endpoint */
            usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
        }
                

}
Example #3
0
void
usb_keyboard_periodic(void) {
	if(keyDidChange && usbInterruptIsReady()){
		USBKEYBOARDDEBUG("usb set interrupt lastkey %c, key: %i\n",lastKey, key);
        buildReport(lastKey);
		usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
	}
	// send end of key
	while (keyDidChange && !usbInterruptIsReady()){
		_delay_ms(10); // as slow speed device we have to wait until next call
		usbPoll();
		buildReport(0);
		usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
		keyDidChange = 0;
	}
}
Example #4
0
int main(void) {
	wdt_enable(WDTO_1S);
  initPodControls();

	/* Even if you don't use the watchdog, turn it off here. On newer devices,
	 * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
	 */
	/* RESET status: all port bits are inputs without pull-up.
	 * That's the way we need D+ and D-. Therefore we don't need any
	 * additional hardware initialization.
	 */
	usbInit();
	usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
	uchar i = 0;
	while(--i){             /* fake USB disconnect for > 250 ms */
			wdt_reset();
			_delay_ms(1);
	}

	usbDeviceConnect();
	sei();
	for(;;){                /* main event loop */
			wdt_reset();
			usbPoll();
			if(usbInterruptIsReady()){
				/* called after every poll of the interrupt endpoint */
				usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
			} else {
				updateSensorData();
        updateLEDState();
      }
	}
}
Example #5
0
int main( void )
{
	usbInit();
	sei();
	
	init_joy();
	
	for ( ;; )
	{
		usbPoll();
		
		// Don't bother reading joy if previous changes haven't gone out yet.
		// Forces delay after changes which serves to debounce controller as well.
		if ( usbInterruptIsReady() )
		{
			read_joy();
			
			// Don't send update unless joystick changed
			if ( memcmp( report_out, report, sizeof report ) )
			{
				memcpy( report_out, report, sizeof report );
				usbSetInterrupt( report_out, sizeof report_out );
				toggle_led();
			}
		}
	}
	
	return 0;
}
Example #6
0
void AVRISP_poll(void)
{
  extern uchar usbNewDeviceAddr;
  usbPoll();
  if ((STK500_rxLen))
    {
      STK500_processmessage();
      STK500_rxLen = 0; 
	}
  if(usbNewDeviceAddr)
    leds[LED_BLUE].frequency = LED_ON;

  if ((STK500_txLen) && (usbInterruptIsReady()))
    {
	  RSP_Pkg_Len = STK500_txLen - STK500_txLen_tmp;
	  if(RSP_Pkg_Len > USB_EP_SIZE)
		RSP_Pkg_Len = USB_EP_SIZE;
	  usbSetInterrupt((uchar*)STK500_Buffer + STK500_txLen_tmp,RSP_Pkg_Len);
		STK500_txLen_tmp += RSP_Pkg_Len;
      if(RSP_Pkg_Len < USB_EP_SIZE)
		{
	 	  STK500_txLen = 0;
		  STK500_txLen_tmp = 0;
		}
    }
}
Example #7
0
File: hid_usb.c Project: lsitec/PCR
void sendHidReport()
{
    wdt_reset();
    usbPoll();
    if(usbInterruptIsReady()) {
        usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
    }
}
Example #8
0
void updateUSB(void) {
    wdt_reset();
    usbPoll();
    if (isDataChanged() && usbInterruptIsReady()) {
        reportBuffer.number = getData();
        usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
    }
}
Example #9
0
int main(void)
{
    bool suspended = false;
#if USB_COUNT_SOF
    uint16_t last_timer = timer_read();
#endif
#if !defined(__AVR_ATmega32__)
    CLKPR = 0x80, CLKPR = 0;
#endif
#ifndef PS2_USE_USART
    uart_init(UART_BAUD_RATE);
#endif

    keyboard_init();
    host_set_driver(vusb_driver());

    debug("initForUsbConnectivity()\n");
    initForUsbConnectivity();

    debug("main loop\n");
    while (1) {
#if USB_COUNT_SOF
        if (usbSofCount != 0) {
            suspended = false;
            usbSofCount = 0;
            last_timer = timer_read();
        } else {
            // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
            if (timer_elapsed(last_timer) > 5) {
                suspended = true;
/*
                uart_putchar('S');
                _delay_ms(1);
                cli();
                set_sleep_mode(SLEEP_MODE_PWR_DOWN);
                sleep_enable();
                sleep_bod_disable();
                sei();
                sleep_cpu();
                sleep_disable();
                _delay_ms(10);
                uart_putchar('W');
*/
            }
        }
#endif
        if (!suspended) {
            usbPoll();

            // TODO: configuration process is incosistent. it sometime fails.
            // To prevent failing to configure NOT scan keyboard during configuration
            if (usbConfiguration && usbInterruptIsReady()) {
                keyboard_task();
            }
            vusb_transfer_keyboard();
        }
    }
}
Example #10
0
/****************************************************************************
 * main()																	*
 *																			*
 *																			*
 ***************************************************************************/
int main(void) {
	
	uchar i;
	uchar calibrationValue;


    calibrationValue = eeprom_read_byte(0); /* calibration value from last time */
    if(calibrationValue != 0xff){
        OSCCAL = calibrationValue;
    }

	i2c_init();
	
    usbInit();
    usbDeviceDisconnect(); 

    i = 0;
    while(--i) {
        _delay_ms(1);
    }

    usbDeviceConnect();

	DDRB &= ~_BV(DDB1);			// input from slave to indicate a msg is waiting

/////////
//	DDRB = 0b0010; // set pb1 as output
/////////
	
	sei();

    for(;;) {

        usbPoll();

		if (PINB & _BV(PB1)) {
			while (PINB & _BV(PB1)) {
				// wait until off
			}

			i2c_start((DEVICE_ID << 1) + I2C_READ);
			action = i2c_read(0);
			i2c_stop();

			if (action <= sizeof(keys)/sizeof(uchar)) {
				reportCount = 0;
			}
		}

		if(usbInterruptIsReady() && (reportCount < 2)){ /* we can send another key */
        	buildReport();
           	usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
        }

    }

    return 0;
}
Example #11
0
void
usb_mouse_periodic(void) {
	if (flags & FLG_CMD_RECEIVED) {
		if (usbInterruptIsReady()){
			usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
		}
		flags &= ~FLG_CMD_RECEIVED;
	}
}
/**
 * This function is used to guarantee that the data is sent to the computer once.
 * Sends the usb report through the serial interface.
 *
 * @param data - USB Report type
 * @param len - sizeof(USB Report)
 */
void usbSendHidReport(byte* data, uchar len){
	while(1){
		usbPoll();
		if (usbInterruptIsReady()){
			usbSetInterrupt(data, len);
			break;
		}
	}
}
Example #13
0
void usbReportSend() {
	// perform usb background tasks until the report can be sent, then send it
	while (1) {
		usbPoll(); // this needs to be called at least once every 10 ms
		if (usbInterruptIsReady()) {
			usbSetInterrupt((uint8_t*)report_buffer, 8); // send
			break;
			// see http://vusb.wikidot.com/driver-api
		}
	}
}
Example #14
0
File: usb.c Project: Grawp/dx5e
void xxxProcess()
{
	wdt_reset();
	usbPoll();
	
	if (changed) {
		if(usbInterruptIsReady()){
			changed = false;
			// called after every poll of the interrupt endpoint
			usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
		}
	}
}
Example #15
0
int main(void) {
    wdt_enable(WDTO_1S);

    odDebugInit();
    DBG1(0x00, 0, 0);  /* debug output: main starts */

    ppmInit();

    usbInit();

    usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
    uchar i = 0;
    while(--i){  /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
	
	DDRC|=3; // LEDs: Output

    sei();
    DBG1(0x01, 0, 0);  /* debug output: main loop starts */

    uchar changed=0;
    ppmNewData=1;
    for(;;){ /* main event loop */
        DBG1(0x02, 0, 0);  /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();

        if (ppmNewData) {
            ppmNewData=0;
            for (i=0;i<sizeof(reportBuffer);i++) {
                unsigned char val=ppmGet(i);
                if (reportBuffer[i]!=val) {
                    reportBuffer[i]=val;
                    changed=1;
                }
            }
            if (changed) {
                if(usbInterruptIsReady()){
                    changed=0;
                    // called after every poll of the interrupt endpoint
                    DBG1(0x03, 0, 0);  // debug output: interrupt report prepared
                    usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
                }

            }
        }
    }
}
Example #16
0
/* transfer keyboard report from buffer */
void vusb_transfer_keyboard(void)
{
    if (usbInterruptIsReady()) {
        if (kbuf_head != kbuf_tail) {
            usbSetInterrupt((void *)&kbuf[kbuf_tail], sizeof(report_keyboard_t));
            kbuf_tail = (kbuf_tail + 1) % KBUF_SIZE;
            if (debug_keyboard) {
                print("V-USB: kbuf["); pdec(kbuf_tail); print("->"); pdec(kbuf_head); print("](");
                phex((kbuf_head < kbuf_tail) ? (KBUF_SIZE - kbuf_tail + kbuf_head) : (kbuf_head - kbuf_tail));
                print(")\n");
            }
        }
    }
}
Example #17
0
int main()
{
	initStatusLED();
	initUSB();

	// Globally enable interrupts
	sei();

	init_modules();
	// Endless loop
	for (;;) {

		/* Regularly restart watchdog timer to prevent it from elapsing. */
		wdt_reset();
		usbPoll();
		
		if (usbInterruptIsReady()) {
      if (isSendingSysExMsg) {
        handleMidiSend();
      } else {
        switch (module_type) {
          case ANALOG_INPUT:
            analog_input_device_main_loop(uADC);
            break;

          case ANALOG_OUTPUT:
            analog_output_device_main_loop();
            break;

          case DIGITAL_INPUT:
            digital_input_device_main_loop(uADC);
            break;

          case DIGITAL_OUTPUT:
            digital_output_device_main_loop();
            break;

          case I2C_DEVICE:
            /* Not implemented yet. */
            break;

          default:
            break;
        }
      }
		}
	}
	return 0;
}
Example #18
0
void JIG_Task(void)
{
	static uchar bytes_in = 0;
   if (usbInterruptIsReady() && state == p5_challenged && expire == 0) 
	{
		if (bytes_in < 64) {
         pUsbSetInterrupt(&jig_response[bytes_in], 8);
			bytes_in += 8;
			if (bytes_in >= 64) {
				state = p5_responded;
				expire = 15;
			}
		}
	}
}
Example #19
0
void transferGamepadReport(int id)
{
	if (usbInterruptIsReady())
	{
		char len;
		char xfer_len;
		char j;

		len = getGamepadReport(reportBuffer, id);

		for (j=0; j<len; j+=8)
		{
			xfer_len = (len-j) < 8 ? (len-j) : 8;

			while (!usbInterruptIsReady())
			{
				usbPoll();
				wdt_reset();
			}
			usbSetInterrupt(reportBuffer+j, xfer_len);

		}
	}
}
Example #20
0
void send_report_once()
{
	// perform usb background tasks until the report can be sent, then send it
	while (1)
	{
		usbPoll(); // this needs to be called at least once every 10 ms
		if (usbInterruptIsReady())
		{
			usbSetInterrupt(&keyboard_report, sizeof(keyboard_report)); // send
			break;
			
			// see http://vusb.wikidot.com/driver-api
		}
	}
}
Example #21
0
void HUB_Task(void)
{
	if (usbInterruptIsReady())
	{
		if (hub_int_response) {
			if (hub_int_force_data0) {
            resetDataToggle();
				hub_int_force_data0 = 0;
			}
         interruptWrite_Byte(hub_int_response);
         sendInterruptBuffer();
         DBGX2("Hub resp: ", &hub_int_response, 1);
			hub_int_response = 0x00;
		}
	}
}
Example #22
0
File: main.c Project: nagi/geekfit
int main(void)
{
    inInitialize();
    outInitialize();
    usbInitialize();
    for(;;){ 
        wdt_reset();
        usbPoll();
        getInput();
        if(usbInterruptIsReady()){
            /* called after every poll of the interrupt endpoint */
            /* This is a push to the host */
            usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
        }
    }
    return 0;
}
Example #23
0
File: main.c Project: mmitch/tasta
int main(void)
{
	uchar key, lastKey = 0, keyDidChange = 0;
	uchar idleCounter = 0;

	hardwareInit();
	sei();
	for (;;) /* main event loop */
	{
		wdt_reset();
		usbPoll();
		key = keyPressed();
		if (lastKey != key)
		{
			lastKey = key;
			keyDidChange = 1;
		}
		if (TIFR & (1<<TOV0)) /* ~63 ms timer */
		{
			TIFR = 1<<TOV0; /* clear overflow */
			if (idleRate != 0)
			{
				if (idleCounter >= OVERFLOWS_4MS)
				{
					idleCounter -= OVERFLOWS_4MS;
				}
				else
				{
					/* USB HID poll timer reached
					 * send current state regardless of real key change */
					idleCounter = idleRate;
					keyDidChange = 1;
				}
			}
		}
		if (keyDidChange && usbInterruptIsReady())
		{
			keyDidChange = 0;
			/* use last key and not current key status in order to avoid lost
			   changes in key status. */
			buildReport(lastKey);
			usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
		}
	}
	return 0;
}
Example #24
0
int main(void)
{
    bool suspended = false;
#if USB_COUNT_SOF
    uint16_t last_timer = timer_read();
#endif

    CLKPR = 0x80, CLKPR = 0;
#ifndef NO_UART
    uart_init(UART_BAUD_RATE);
#endif

    keyboard_init();
    host_set_driver(vusb_driver());

    debug("initForUsbConnectivity()\n");
    initForUsbConnectivity();

    debug("main loop\n");
    while (1) {
#if USB_COUNT_SOF
        if (usbSofCount != 0) {
            suspended = false;
            usbSofCount = 0;
            last_timer = timer_read();
        } else {
            // Suspend when no SOF in 3ms-10ms(7.1.7.4 Suspending of USB1.1)
            if (timer_elapsed(last_timer) > 5) {
                suspended = true;
            }
        }
#endif
        if (!suspended) {
            usbPoll();

            // TODO: configuration process is incosistent. it sometime fails.
            // To prevent failing to configure NOT scan keyboard during configuration
            if (usbConfiguration && usbInterruptIsReady()) {
                keyboard_task();
            }
            vusb_transfer_keyboard();
        } else if (suspend_wakeup_condition()) {
            usb_remote_wakeup();
        }
    }
}
Example #25
0
int main(void) {
  	wdt_enable(WDTO_2S); /* Enable watchdog timer 2s */
	hardwareInit(); /* Initialize hardware (I/O) */  
  	usbInit(); /* Initialize USB stack processing */
	Setup_init();
  	speed_init();
  	PWM_init();
	KeyScan_init();
	
	switch (Setup_key12LED){
		case Setup_key12LED_Always:
		case Setup_key12LED_OftenOn:
			PWM_setOutputLevel(0,PWM_TotalLevel);
			PWM_setOutputLevel(1,PWM_TotalLevel);			
			break;
		case Setup_key12LED_Never:
		case Setup_key12LED_OftenOff:	
			PWM_setOutputLevel(0,0);
			PWM_setOutputLevel(1,0);			
	}
	


  	sei(); /* Enable global interrupts */
	WorkMode_set(WorkMode_Unused);

  	for(;;){  /* Main loop */
	    wdt_reset(); /* Reset the watchdog */
		
		usbPoll();

	    if(KeyScan_keyChanged && usbInterruptIsReady()){
	      KeyScan_keyChanged = 0;
		  buildReport();
	      usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
	    }else{	
			if(TIFR0&(1<<TOV0)){	
				TIFR0 |= 1<<TOV0;
				PWM_Generator();
			}
				
		}		
  	}
  	return 0;
}
Example #26
0
int main(void) {
    uchar key, lastKey = 0, keyDidChange = 0;
    uchar idleCounter = 0;

    wdt_enable(WDTO_2S);
    hardwareInit();
    usbInit();
    sei();

    for(;;) {
        wdt_reset();
        usbPoll();

        key = keyPressed();

        if(lastKey != key) {
            lastKey = key;
            keyDidChange = 1;
        }

        // 22 ms timer
        if(TIFR & (1<<TOV0)) {
            TIFR = 1<<TOV0;
            if(idleRate != 0) {
                if(idleCounter > 4) {
                    // 22 ms in units of 4 ms
                    idleCounter -= 5;
                } else {
                    idleCounter = idleRate;
                    keyDidChange = 1;
                }
            }
        }

        if(keyDidChange && usbInterruptIsReady()) {
            keyDidChange = 0;
            // use last key and not current key status in order to avoid lost
            // changes in key status.
            buildReport(lastKey);
            usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
        }
    }
    return 0;
}
Example #27
0
File: firmware.c Project: fs495/avr
void main(void)
{
    usbInit();
    usbDeviceDisconnect();
    _delay_ms(100);
    usbDeviceConnect();
    sei();

    for(;;) {
	usbPoll();
	if(usbInterruptIsReady()) {
	    DDRB ^= 1;
	    hid_report.button ^= 1;
	    usbSetInterrupt((void*)&hid_report, sizeof(hid_report));
	}

	_delay_ms(1);
    }
}
Example #28
0
void sendDataUSB(uchar* data, unsigned int byteCount) {
	int currentByte;
	int currentCount;

	currentByte = 0;

	while(currentByte < byteCount) {
		currentCount = byteCount - currentByte;

		if(currentCount > 8)
			currentCount = 8;

		while(!usbInterruptIsReady())
			usbPoll();

		usbSetInterrupt(data + currentByte, currentCount*sizeof(uchar));
		currentByte += currentCount;		
	}
}
Example #29
0
int main() {
    
    //--setup
    changed= 0;
    PORTB= 0b11111111;      //internal pull-ups
    PORTD= 0b01110011;      //internal pull-ups
    lastPINB= 0;           //used to detect changes
    lastPIND= 0;           //used to detect changes
    wdt_enable(WDTO_1S);    //enable 1s watchdog timer
    usbInit();
    usbDeviceDisconnect();  //enforce re-enumeration, do this while interrupts are disabled!
    uchar i= 0;
    while(--i) {            //fake USB disconnect for > 250 ms
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
    sei();                  //Enable interrupts after re-enumeration
    
    //--loop
    while(1) {
        wdt_reset(); // keep the watchdog happy
        usbPoll();
        
        if(PINB!=lastPINB) {
            changed= 1;
            lastPINB= PINB;
            reportBuffer[0]= lastPINB;
        }
        if((PIND&0b01110011)!=lastPIND) {
            changed= 1;
            lastPIND= PIND&0b01110011;
            reportBuffer[1]= lastPIND;
        }
        
        if(usbInterruptIsReady()&&changed) {
			usbSetInterrupt(reportBuffer, sizeof(reportBuffer));
			changed= 0;
		}
    }
    return 0;
}
Example #30
0
int __attribute__((noreturn)) main(void)
{
uchar   i;

    wdt_enable(WDTO_1S);
    /* Even if you don't use the watchdog, turn it off here. On newer devices,
     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
     */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 0;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
    usbDeviceConnect();
	RED_LED_OUT();
    sei();
    for(;;){                /* main event loop */
        wdt_reset();
        usbPoll();
        if(usbInterruptIsReady()){
			if(state == SEND) {
				reportBuffer.keys[0] = 0x52; /* 'UP' */
				//reportBuffer.modifier |= (1 << 2); /* SHIFT */
				state = NO_KEYS;
				counter = 0;
			}
			usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
			reportBuffer.keys[0] = 0; /* Empty the report (no keys pressed) */
			reportBuffer.modifier = 0;
		}
		counter++;
		if(counter == 30000) {
			state = SEND;
		}
    }
}