buttonState.buttons = pollSnes();
}
-void initTimer() {
+static void initPins() {
+ // Enable PD3 as output high (pull-up to D-)
+ DDRD |= _BV(PIND3);
+ PORTD |= _BV(PIND3);
+
+ // Enable PC1:0 as output, and set data clock high
+ // Serial data is PC2 (input, hi-z)
+ // Data latch is PC1 (output, default LOW)
+ // Data clock is PC0 (output, default HIGH)
+ DDRC |= _BV(PINC1) | _BV(PINC0);
+ PORTC |= _BV(PINC0);
+}
+
+static void initTimer() {
// See section 15.11 for reference
// Using CTC mode (non-PWM)
{
uchar i;
wdt_enable(WDTO_1S); // Enable watchdog with 1s reset time
+
/* 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!
*/
* additional hardware initialization on the USB side.
*/
- // We need to setup the pin configuration for D3, which is an output pin
-
+ // We need to set up the pin configuration for D3 and everything on the SNES side
+ initPins();
// Set up the clock prescaler to CLKI_O/8, which gives us 2250000 ticks per second
// This makes 37500 such ticks give us a 60Hz signal, which is exactly how we set up
// the timer interrupt to poll the SNES controller
-
+ initTimer();
+ // Start with no buttons pressed
+ buttonState.buttons = 0;
+ reportBuffer.buttons = 0;
//odDebugInit();
usbDeviceConnect();
sei(); // Enable interrupts
//DBG1(0x01, 0, 0); /* debug output: main loop starts */
+
+ uchar counter = 0;
+
for(;;){ /* main event loop */
//DBG1(0x02, 0, 0); /* debug output: main loop iterates */
wdt_reset();
usbPoll();
if(usbInterruptIsReady()){
- reportBuffer.buttons = buttonState.buttons;
/* called after every poll of the interrupt endpoint */
- //advanceCircleByFixedAngle();
+ // Actual code to be executed - updates the HID report with the status of the SNES controller
+ //reportBuffer.buttons = buttonState.buttons;
+
+ // Testing USB reports - change button state every second, incrementing the report buffer by 1.
+ if(counter++ == 60) {
+ reportBuffer.buttons++;
+ counter = 0;
+ }
//DBG1(0x03, 0, 0); /* debug output: interrupt report prepared */
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
}