summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c84
1 files changed, 33 insertions, 51 deletions
diff --git a/main.c b/main.c
index 8cb3146..ef9c55c 100644
--- a/main.c
+++ b/main.c
@@ -114,7 +114,6 @@ USB_PUBLIC uchar usbFunctionSetup(uchar data[8])
if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_CLASS &&
(rq->bRequest == USBRQ_HID_GET_REPORT))
{
- debug(32);
// wValue: ReportType (highbyte), ReportID (lowbyte)
usbMsgPtr = (void *)&reportBuffer; // we only have this one
return sizeof(reportBuffer);
@@ -300,8 +299,7 @@ char decode_byte(char* bufptr)
int main (void)
{
- char rand=123;
- unsigned char ltrig=0, rtrig=0;
+ unsigned char ltrig=0, rtrig=0; // only used for rumbling test.
DDRC=0x00;
PORTC=0x00;
@@ -325,74 +323,61 @@ int main (void)
sei();
debug(4);
- int temp=5;
int n_received;
int toggle=0;
- int count=0;
int count2=0;
int count3=0;
while(1)
{
- toggle=~toggle;
+ wdt_reset();
+
+
+
+ // DEBUGGING CODE starts here
+
+ toggle=~toggle; // debug mainloop duration
debug(toggle);
- count++;
- if (count>=1500) count=0;
- count2++;
- if (count2>=512-ltrig) count2=0;
+ count2++; // debug rumble
+ if (count2>=256+ltrig) count2=0;
count3++;
if (count3>=25) count3=0;
- wdt_reset();
+ // DEBUGGING CODE ends here.
+
+
+
+ // USB CODE starts here
+
usbPoll();
if(usbInterruptIsReady())
- {
-
usbSetInterrupt((void *)&reportBuffer, sizeof(reportBuffer));
-// debug(2);
- }
+ // USB CODE ends here
-/* temp++;
- if (!(PIND & 0x08)) // check if uC is hung up
- {
- //PORTB=~(1 << ((temp>>9)%6));
- PORTB=~temp;
- }
- else if (!(PIND & 0x20)) // debug num_received
- {
- PORTB=~n_received>>3;
- }
- else if (!(PIND & 0x40)) // clear debug output
- {
- PORTB=~0x00;
- }
- else*/
- {
- // decode "buffer" and write button states to PORTB
+ _delay_us(10);
- //PORTB=~buffer[4];
- }
- //debug(temp % 64);
-// _delay_ms(0.3);
- _delay_us(10);
- char foo[] = { 0x40, 0x03, 0x00 };
- //char foo[] = { 0x40, 0x03, 0x02 };
+ // GAMECUBE COMMUNICATION starts here
+
+ char getid_msg=0x00;
+ send_recv_gc(&getid_msg, 1); // send get-id message; probably unneccessary.
- if (count2<256 && count3<rtrig/10)
- foo[2]|=0x01;
+
+
+ char getstatus_msg[] = { 0x40, 0x03, 0x00 };
+
+ if (count2<256 && count3<rtrig/10) // set rumbling bit, if appropriate
+ getstatus_msg[2]|=0x01;
- char foo2=0x00;
- send_recv_gc(&foo2, 1);
- n_received=send_recv_gc(foo, 3);
- if (n_received == 64)
- {
+ n_received=send_recv_gc(getstatus_msg, 3); // send get-status message.
+ if (n_received == 64) // sanity check to detect corrupted communication.
+ { // this happens once in a while because USB interrupt kicks in.
reportBuffer.x=decode_byte(buffer+16);
reportBuffer.y=~decode_byte(buffer+24);
@@ -411,12 +396,9 @@ debug(4);
ltrig=decode_byte(buffer+48);
rtrig=decode_byte(buffer+56);
-
- }
- else
- {
- temp++;
}
+
+ // GAMECUBE COMMUNICATION ends here.
}
return 0; // never reached