sanguino/cores/arduino/USBAPI.h

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 2
b373b0288715
permissions
-rw-r--r--

proper configuration, homing and planner optimization

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3 #ifndef __USBAPI__
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4 #define __USBAPI__
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 #if defined(USBCON)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 // USB
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 class USBDevice_
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 public:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 USBDevice_();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 bool configured();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 void attach();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 void detach(); // Serial port goes down too...
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20 void poll();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22 extern USBDevice_ USBDevice;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 // Serial over CDC (Serial1 is the physical port)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 class Serial_ : public Stream
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30 private:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 ring_buffer *_cdc_rx_buffer;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32 public:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33 void begin(uint16_t baud_count);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 void end(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36 virtual int available(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37 virtual void accept(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 virtual int peek(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39 virtual int read(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 virtual void flush(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41 virtual size_t write(uint8_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 operator bool();
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 extern Serial_ Serial;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48 // Mouse
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 #define MOUSE_LEFT 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51 #define MOUSE_RIGHT 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 #define MOUSE_MIDDLE 4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 #define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 class Mouse_
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
57 private:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
58 uint8_t _buttons;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
59 void buttons(uint8_t b);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
60 public:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
61 Mouse_(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
62 void begin(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
63 void end(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
64 void click(uint8_t b = MOUSE_LEFT);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
65 void move(signed char x, signed char y, signed char wheel = 0);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
66 void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
67 void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
68 bool isPressed(uint8_t b = MOUSE_LEFT); // check LEFT by default
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
69 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
70 extern Mouse_ Mouse;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
71
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
72 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
73 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
74 // Keyboard
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
75
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
76 #define KEY_LEFT_CTRL 0x80
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
77 #define KEY_LEFT_SHIFT 0x81
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
78 #define KEY_LEFT_ALT 0x82
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
79 #define KEY_LEFT_GUI 0x83
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
80 #define KEY_RIGHT_CTRL 0x84
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
81 #define KEY_RIGHT_SHIFT 0x85
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
82 #define KEY_RIGHT_ALT 0x86
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
83 #define KEY_RIGHT_GUI 0x87
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
84
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
85 #define KEY_UP_ARROW 0xDA
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
86 #define KEY_DOWN_ARROW 0xD9
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
87 #define KEY_LEFT_ARROW 0xD8
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
88 #define KEY_RIGHT_ARROW 0xD7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
89 #define KEY_BACKSPACE 0xB2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
90 #define KEY_TAB 0xB3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
91 #define KEY_RETURN 0xB0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
92 #define KEY_ESC 0xB1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
93 #define KEY_INSERT 0xD1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
94 #define KEY_DELETE 0xD4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
95 #define KEY_PAGE_UP 0xD3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
96 #define KEY_PAGE_DOWN 0xD6
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
97 #define KEY_HOME 0xD2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
98 #define KEY_END 0xD5
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
99 #define KEY_CAPS_LOCK 0xC1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
100 #define KEY_F1 0xC2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
101 #define KEY_F2 0xC3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
102 #define KEY_F3 0xC4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
103 #define KEY_F4 0xC5
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
104 #define KEY_F5 0xC6
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
105 #define KEY_F6 0xC7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
106 #define KEY_F7 0xC8
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
107 #define KEY_F8 0xC9
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
108 #define KEY_F9 0xCA
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
109 #define KEY_F10 0xCB
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
110 #define KEY_F11 0xCC
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
111 #define KEY_F12 0xCD
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
112
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
113 // Low level key report: up to 6 keys and shift, ctrl etc at once
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
114 typedef struct
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
115 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
116 uint8_t modifiers;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
117 uint8_t reserved;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
118 uint8_t keys[6];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
119 } KeyReport;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
120
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
121 class Keyboard_ : public Print
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
122 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
123 private:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
124 KeyReport _keyReport;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
125 void sendReport(KeyReport* keys);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
126 public:
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
127 Keyboard_(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
128 void begin(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
129 void end(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
130 virtual size_t write(uint8_t k);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
131 virtual size_t press(uint8_t k);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
132 virtual size_t release(uint8_t k);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
133 virtual void releaseAll(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
134 };
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
135 extern Keyboard_ Keyboard;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
136
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
137 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
138 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
139 // Low level API
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
140
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
141 typedef struct
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
142 {
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
143 uint8_t bmRequestType;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
144 uint8_t bRequest;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
145 uint8_t wValueL;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
146 uint8_t wValueH;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
147 uint16_t wIndex;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
148 uint16_t wLength;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
149 } Setup;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
150
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
151 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
152 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
153 // HID 'Driver'
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
154
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
155 int HID_GetInterface(uint8_t* interfaceNum);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
156 int HID_GetDescriptor(int i);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
157 bool HID_Setup(Setup& setup);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
158 void HID_SendReport(uint8_t id, const void* data, int len);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
159
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
160 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
161 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
162 // MSC 'Driver'
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
163
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
164 int MSC_GetInterface(uint8_t* interfaceNum);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
165 int MSC_GetDescriptor(int i);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
166 bool MSC_Setup(Setup& setup);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
167 bool MSC_Data(uint8_t rx,uint8_t tx);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
168
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
169 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
170 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
171 // CSC 'Driver'
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
172
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
173 int CDC_GetInterface(uint8_t* interfaceNum);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
174 int CDC_GetDescriptor(int i);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
175 bool CDC_Setup(Setup& setup);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
176
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
177 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
178 //================================================================================
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
179
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
180 #define TRANSFER_PGM 0x80
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
181 #define TRANSFER_RELEASE 0x40
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
182 #define TRANSFER_ZERO 0x20
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
183
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
184 int USB_SendControl(uint8_t flags, const void* d, int len);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
185 int USB_RecvControl(void* d, int len);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
186
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
187 uint8_t USB_Available(uint8_t ep);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
188 int USB_Send(uint8_t ep, const void* data, int len); // blocking
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
189 int USB_Recv(uint8_t ep, void* data, int len); // non-blocking
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
190 int USB_Recv(uint8_t ep); // non-blocking
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
191 void USB_Flush(uint8_t ep);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
192
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
193 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
194
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
195 #endif /* if defined(USBCON) */

mercurial