-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
73 lines (55 loc) · 1.23 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/delay.h>
// oscillator calibration routine
#include "libs-device/osccal.h"
// v-usb lib
#include "usbconfig.h"
#include "usbdrv/usbdrv.h"
// #include "usbdrv/oddebug.h"
// controller modules
#ifdef SNES
#include "snes/snes.h"
#endif
#ifdef NES
#include "nes/nes.h"
#endif
// USB reset hook, see usbconfig.h
void hadUsbReset(void) {
cli(); // usbMeasureFrameLength() counts CPU cycles, so disable interrupts.
calibrateOscillator();
sei();
}
usbMsgLen_t usbFunctionSetup(uchar data[8]) {
return 0; // Nothing implemented
}
int main(void) {
// enable Watchdog Timer
wdt_enable(WDTO_1S);
// Disable analog comparator to save power
ACSR |= (1<<ACD);
// force USB re-enumeration
usbDeviceDisconnect();
_delay_ms(500);
usbDeviceConnect();
initController();
// init USB
usbInit();
// enable interrupts
sei();
// MAIN LOOP START
for(;;) {
// pet the Watchdog
wdt_reset();
// poll USB
usbPoll();
// send report if host is ready
if(usbInterruptIsReady()){
readController();
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
}
}
// MAIN LOOP end
}