1 /*---------------------------------------------------------------------------------------------
2 * USB Gecko Development Kit - http://www.usbgecko.com
3 * --------------------------------------------------------------------------------------------
6 * usb.c - V1.2 functions for the USB Gecko adapter (www.usbgecko.com).
7 * Now works for Wii Mode - use WIIMODE define in usb.h to set
8 * Copyright (c) 2008 - Nuke - <wiinuke@gmail.com>
10 *---------------------------------------------------------------------------------------------*/
13 #include <gccore.h> // If not using libogc need types
16 /*---------------------------------------------------------------------------------------------*
18 Description: Send byte to Gamecube/Wii over EXI memory card port
19 *----------------------------------------------------------------------------------------------*/
21 static int __usb_sendbyte (char sendbyte
)
25 exi_chan1sr
= 0x000000D0;
26 exi_chan1data
= 0xB0000000 | (sendbyte
<<20);
28 while((exi_chan1cr
)&1);
37 /*---------------------------------------------------------------------------------------------*
39 Description: Receive byte from Gamecube/Wii over EXI memory card port
40 *----------------------------------------------------------------------------------------------*/
42 static int __usb_receivebyte (char *receivebyte
)
46 exi_chan1sr
= 0x000000D0;
47 exi_chan1data
= 0xA0000000;
49 while((exi_chan1cr
)&1);
53 *receivebyte
=(i
>>16)&0xff;
59 /*---------------------------------------------------------------------------------------------*
60 Name: usb_checksendstatus
61 Description: Chesk the FIFO is ready to send
62 *----------------------------------------------------------------------------------------------*/
64 static int __usb_checksendstatus()
68 exi_chan1sr
= 0x000000D0;
69 exi_chan1data
= 0xC0000000;
71 while((exi_chan1cr
)&1);
80 /*---------------------------------------------------------------------------------------------*
81 Name: usb_checkreceivestatus
82 Description: Check the FIFO is ready to receive
83 *----------------------------------------------------------------------------------------------*/
85 static int __usb_checkreceivestatus()
88 exi_chan1sr
= 0x000000D0;
89 exi_chan1data
= 0xD0000000;
91 while((exi_chan1cr
)&1);
100 /*---------------------------------------------------------------------------------------------*
102 Description: Simple buffer send routine
103 *----------------------------------------------------------------------------------------------*/
105 void usb_sendbuffer (const void *buffer
, int size
)
107 char *sendbyte
= (char*) buffer
;
108 s32 bytesleft
= size
;
111 while (bytesleft
> 0)
113 returnvalue
= __usb_sendbyte(*sendbyte
);
121 /*---------------------------------------------------------------------------------------------*
122 Name: usb_receivebuffer
123 Description: Simple buffer receive routine
124 *----------------------------------------------------------------------------------------------*/
126 void usb_receivebuffer (void *buffer
, int size
)
128 char *receivebyte
= (char*)buffer
;
129 s32 bytesleft
= size
;
132 while (bytesleft
> 0)
134 returnvalue
= __usb_receivebyte(receivebyte
);
142 /*---------------------------------------------------------------------------------------------*
143 Name: usb_sendbuffersafe
144 Description: Simple buffer send routine with fifo check (use for large transfers)
145 *----------------------------------------------------------------------------------------------*/
147 void usb_sendbuffersafe (const void *buffer
, int size
)
149 char *sendbyte
= (char*) buffer
;
150 s32 bytesleft
= size
;
153 while (bytesleft
> 0)
155 if(__usb_checksendstatus()){
156 returnvalue
= __usb_sendbyte(*sendbyte
);
165 /*---------------------------------------------------------------------------------------------*
166 Name: usb_receivebuffersafe
167 Description: Simple buffer receive routine with fifo check (use for large transfers)
168 *----------------------------------------------------------------------------------------------*/
170 void usb_receivebuffersafe (void *buffer
, int size
)
172 char *receivebyte
= (char*)buffer
;
173 s32 bytesleft
= size
;
176 while (bytesleft
> 0)
178 if(__usb_checkreceivestatus()){
179 returnvalue
= __usb_receivebyte(receivebyte
);
188 /*---------------------------------------------------------------------------------------------*
190 Description: Chesk the Gecko is connected
191 *----------------------------------------------------------------------------------------------*/
196 exi_chan1sr
= 0x000000D0;
197 exi_chan1data
= 0x90000000;
199 while((exi_chan1cr
)&1);
208 /*---------------------------------------------------------------------------------------------*
210 Description: Flushes the FIFO, Use at the start of your program to avoid trash
211 *----------------------------------------------------------------------------------------------*/
217 while (__usb_receivebyte(&tempbyte
));