Код: Выделить всё
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
struct joy_report
{
uint8_t buttons;
};
int __attribute__((noreturn)) main(void)
{
uchar i;
wdt_enable(WDTO_1S);
DDRA=0x00;
PORTA=0xFF;
/* 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.
*/
odDebugInit();
DBG1(0x00, 0, 0); /* debug output: main starts */
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();
sei();
DBG1(0x01, 0, 0); /* debug output: main loop starts */
for(;;){ /* main event loop */
DBG1(0x02, 0, 0); /* debug output: main loop iterates */
wdt_reset();
if (!CHECKBIT(PORTA, 0))
{
reportBuffer.button1=0xff;
}
else
{
reportBuffer.button1=0x00;
}
usbPoll();
if(usbInterruptIsReady()){
/* called after every poll of the interrupt endpoint */
DBG1(0x03, 0, 0); /* debug output: interrupt report prepared */
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
}
}
}

