libdragon
Loading...
Searching...
No Matches
usb.h
1#ifndef UNFL_USB_H
2#define UNFL_USB_H
3
4 /*********************************
5 DataType macros
6 *********************************/
7
8 // UNCOMMENT THE #DEFINE IF USING LIBDRAGON
9 #define LIBDRAGON
10
11 // Settings
12 #define USE_OSRAW 0 // Use if you're doing USB operations without the PI Manager (libultra only)
13 #define DEBUG_ADDRESS_SIZE 8*1024*1024 // Max size of USB I/O. The bigger this value, the more ROM you lose!
14 #define CHECK_EMULATOR 0 // Stops the USB library from working if it detects an emulator to prevent problems
15
16 // Cart definitions
17 #define CART_NONE 0
18 #define CART_64DRIVE 1
19 #define CART_EVERDRIVE 2
20 #define CART_SC64 3
21
22 // Data types defintions
23 #define DATATYPE_TEXT 0x01
24 #define DATATYPE_RAWBINARY 0x02
25 #define DATATYPE_HEADER 0x03
26 #define DATATYPE_SCREENSHOT 0x04
27 #define DATATYPE_HEARTBEAT 0x05
28 #define DATATYPE_RDBPACKET 0x06
29
30
31 /*********************************
32 Convenience macros
33 *********************************/
34
35 // Use these to conveniently read the header from usb_poll()
36 #define USBHEADER_GETTYPE(header) (((header) & 0xFF000000) >> 24)
37 #define USBHEADER_GETSIZE(header) (((header) & 0x00FFFFFF))
38
39
40 /*********************************
41 USB Functions
42 *********************************/
43
44 /*==============================
45 usb_initialize
46 Initializes the USB buffers and pointers
47 @return 1 if the USB initialization was successful, 0 if not
48 ==============================*/
49
50 extern char usb_initialize(void);
51
52
53 /*==============================
54 usb_getcart
55 Returns which flashcart is currently connected
56 @return The CART macro that corresponds to the identified flashcart
57 ==============================*/
58
59 extern char usb_getcart(void);
60
61
62 /*==============================
63 usb_write
64 Writes data to the USB.
65 Will not write if there is data to read from USB
66 @param The DATATYPE that is being sent
67 @param A buffer with the data to send
68 @param The size of the data being sent
69 ==============================*/
70
71 extern void usb_write(int datatype, const void* data, int size);
72
73
74 /*==============================
75 usb_poll
76 Returns the header of data being received via USB
77 The first byte contains the data type, the next 3 the number of bytes left to read
78 @return The data header, or 0
79 ==============================*/
80
81 extern unsigned long usb_poll(void);
82
83
84 /*==============================
85 usb_read
86 Reads bytes from USB into the provided buffer
87 @param The buffer to put the read data in
88 @param The number of bytes to read
89 ==============================*/
90
91 extern void usb_read(void* buffer, int size);
92
93
94 /*==============================
95 usb_skip
96 Skips a USB read by the specified amount of bytes
97 @param The number of bytes to skip
98 ==============================*/
99
100 extern void usb_skip(int nbytes);
101
102
103 /*==============================
104 usb_rewind
105 Rewinds a USB read by the specified amount of bytes
106 @param The number of bytes to rewind
107 ==============================*/
108
109 extern void usb_rewind(int nbytes);
110
111
112 /*==============================
113 usb_purge
114 Purges the incoming USB data
115 ==============================*/
116
117 extern void usb_purge(void);
118
119
120 /*==============================
121 usb_timedout
122 Checks if the USB timed out recently
123 @return 1 if the USB timed out, 0 if not
124 ==============================*/
125
126 extern char usb_timedout(void);
127
128
129 /*==============================
130 usb_sendheartbeat
131 Sends a heartbeat packet to the PC
132 This is done once automatically at initialization,
133 but can be called manually to ensure that the
134 host side tool is aware of the current USB protocol
135 version.
136 ==============================*/
137
138 extern void usb_sendheartbeat(void);
139
140#endif