Project

General

Profile

Statistics
| Branch: | Revision:

root / arduino-1.0 / hardware / arduino / cores / arduino / USBAPI.h @ 58d82c77

History | View | Annotate | Download (4.43 KB)

1 58d82c77 Tom Mullins
2
3
#ifndef __USBAPI__
4
#define __USBAPI__
5
6
#if defined(USBCON)
7
8
//================================================================================
9
//================================================================================
10
//        USB
11
12
class USB_
13
{
14
public:
15
        USB_();
16
        bool configured();
17
18
        void attach();
19
        void detach();        // Serial port goes down too...
20
        void poll();
21
};
22
extern USB_ USB;
23
24
//================================================================================
25
//================================================================================
26
//        Serial over CDC (Serial1 is the physical port)
27
28
class Serial_ : public Stream
29
{
30
public:
31
        void begin(uint16_t baud_count);
32
        void end(void);
33
34
        virtual int available(void);
35
        virtual int peek(void);
36
        virtual int read(void);
37
        virtual void flush(void);
38
        virtual size_t write(uint8_t);
39
};
40
extern Serial_ Serial;
41
42
//================================================================================
43
//================================================================================
44
//        Mouse
45
46
#define MOUSE_LEFT 1
47
#define MOUSE_RIGHT 2
48
#define MOUSE_MIDDLE 4
49
#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
50
51
class Mouse_
52
{
53
private:
54
        uint8_t _buttons;
55
        void buttons(uint8_t b);
56
public:
57
        Mouse_();
58
        void click(uint8_t b = MOUSE_LEFT);
59
        void move(signed char x, signed char y, signed char wheel = 0);        
60
        void press(uint8_t b = MOUSE_LEFT);                // press LEFT by default
61
        void release(uint8_t b = MOUSE_LEFT);        // release LEFT by default
62
        bool isPressed(uint8_t b = MOUSE_ALL);        // check all buttons by default
63
};
64
extern Mouse_ Mouse;
65
66
//================================================================================
67
//================================================================================
68
//        Keyboard
69
70
#define KEY_MODIFIER_LEFT_CTRL                0x01
71
#define KEY_MODIFIER_LEFT_SHIFT                0x02
72
#define KEY_MODIFIER_LEFT_ALT                0x04
73
#define KEY_MODIFIER_LEFT_GUI                0x08
74
#define KEY_MODIFIER_RIGHT_CTRL                0x010
75
#define KEY_MODIFIER_RIGHT_SHIFT        0x020
76
#define KEY_MODIFIER_RIGHT_ALT                0x040
77
#define KEY_MODIFIER_RIGHT_GUI                0x080
78
79
//        Low level key report: up to 6 keys and shift, ctrl etc at once
80
typedef struct
81
{
82
        uint8_t modifiers;
83
        uint8_t reserved;
84
        uint8_t keys[6];
85
} KeyReport;
86
87
//        Map a character into a key report
88
//        Called from Print to map text to keycodes
89
class KeyMap
90
{
91
public:
92
        virtual void charToKey(int c, KeyReport* keyReport) = 0;
93
};
94
95
//        
96
class Keyboard_ : public Print
97
{
98
private:
99
        KeyMap* _keyMap;
100
        void sendReport(KeyReport* keys);
101
        void setKeyMap(KeyMap* keyMap);        
102
public:
103
        Keyboard_();
104
        virtual size_t write(uint8_t);
105
};
106
extern Keyboard_ Keyboard;
107
108
//================================================================================
109
//================================================================================
110
//        Low level API
111
112
typedef struct
113
{
114
        uint8_t bmRequestType;
115
        uint8_t bRequest;
116
        uint8_t wValueL;
117
        uint8_t wValueH;
118
        uint16_t wIndex;
119
        uint16_t wLength;
120
} Setup;
121
122
//================================================================================
123
//================================================================================
124
//        HID 'Driver'
125
126
int                HID_GetInterface(uint8_t* interfaceNum);
127
int                HID_GetDescriptor(int i);
128
bool        HID_Setup(Setup& setup);
129
void        HID_SendReport(uint8_t id, const void* data, int len);
130
131
//================================================================================
132
//================================================================================
133
//        MSC 'Driver'
134
135
int                MSC_GetInterface(uint8_t* interfaceNum);
136
int                MSC_GetDescriptor(int i);
137
bool        MSC_Setup(Setup& setup);
138
bool        MSC_Data(uint8_t rx,uint8_t tx);
139
140
//================================================================================
141
//================================================================================
142
//        CSC 'Driver'
143
144
int                CDC_GetInterface(uint8_t* interfaceNum);
145
int                CDC_GetDescriptor(int i);
146
bool        CDC_Setup(Setup& setup);
147
148
//================================================================================
149
//================================================================================
150
151
#define TRANSFER_PGM                0x80
152
#define TRANSFER_RELEASE        0x40
153
#define TRANSFER_ZERO                0x20
154
155
int USB_SendControl(uint8_t flags, const void* d, int len);
156
int USB_RecvControl(void* d, int len);
157
158
uint8_t        USB_Available(uint8_t ep);
159
int USB_Send(uint8_t ep, const void* data, int len);        // blocking
160
int USB_Recv(uint8_t ep, void* data, int len);                // non-blocking
161
int USB_Recv(uint8_t ep);                                                        // non-blocking
162
void USB_Flush(uint8_t ep);
163
164
#endif
165
166
#endif /* if defined(USBCON) */