static report_t buttonState;
static report_t reportBuffer;
+static uint8_t pollInProgress = 0;
usbMsgLen_t usbFunctionSetup(uchar data[8]) {
usbRequest_t *rq = (void *)data;
}
ISR(TIMER1_COMPA_vect) {
+ if(pollInProgress) // Mutex, to prevent infinite recursion if terribly many USB interrupts (shouldn't happen, but safety net)
+ return; // We've already started polling the SNES controller, return up the stack so that the original ISR can finish
+ pollInProgress = 1; // Acquire lock
+ sei(); // Allow for nested interrupts - namely, USB interrupts.
buttonState.buttons = pollSnes();
+ pollInProgress = 0; // Release lock
}
static void initPins() {
/* 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!
*/
+
+ cli(); // Disable interrupts
//DBG1(0x00, 0, 0); /* debug output: main starts */
_delay_ms(1);
}
usbDeviceConnect();
- sei(); // Enable interrupts
+ sei(); // Enable interrupts (after device reconnect)
//DBG1(0x01, 0, 0); /* debug output: main loop starts */
uchar counter = 0;