source: rtos_arduino/trunk/arduino_lib/hardware/arduino/samd/cores/arduino/USB/USBAPI.h@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 6.7 KB
Line 
1/*
2 Copyright (c) 2012 Arduino. All right reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 See the GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#ifndef __USBAPI__
20#define __USBAPI__
21
22
23/* Define attribute */
24#if defined ( __CC_ARM ) /* Keil uVision 4 */
25 #define WEAK (__attribute__ ((weak)))
26#elif defined ( __ICCARM__ ) /* IAR Ewarm 5.41+ */
27 #define WEAK __weak
28#elif defined ( __GNUC__ ) /* GCC CS */
29 #define WEAK __attribute__ ((weak))
30#endif
31
32
33#if defined __cplusplus
34
35#include "Stream.h"
36#include "RingBuffer.h"
37
38//================================================================================
39//================================================================================
40// USB
41
42class USBDevice_
43{
44public:
45 USBDevice_();
46 bool configured();
47
48 bool attach();
49 bool detach(); // Serial port goes down too...
50 void poll();
51 void init();
52};
53extern USBDevice_ USBDevice;
54
55//================================================================================
56//================================================================================
57// Serial over CDC (Serial1 is the physical port)
58
59class Serial_ : public Stream
60{
61private:
62 RingBuffer *_cdc_rx_buffer;
63public:
64 void begin(uint32_t baud_count);
65 void begin(unsigned long, uint8_t);
66 void end(void);
67
68 virtual int available(void);
69 virtual void accept(void);
70 virtual int peek(void);
71 virtual int read(void);
72 virtual void flush(void);
73 virtual size_t write(uint8_t);
74 virtual size_t write(const uint8_t *buffer, size_t size);
75 using Print::write; // pull in write(str) from Print
76 operator bool();
77};
78extern Serial_ SerialUSB;
79
80//================================================================================
81//================================================================================
82// Mouse
83
84#define MOUSE_LEFT 1
85#define MOUSE_RIGHT 2
86#define MOUSE_MIDDLE 4
87#define MOUSE_ALL (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)
88
89class Mouse_
90{
91private:
92 uint8_t _buttons;
93 void buttons(uint8_t b);
94public:
95 Mouse_(void);
96 void begin(void);
97 void end(void);
98 void click(uint8_t b = MOUSE_LEFT);
99 void move(signed char x, signed char y, signed char wheel = 0);
100 void press(uint8_t b = MOUSE_LEFT); // press LEFT by default
101 void release(uint8_t b = MOUSE_LEFT); // release LEFT by default
102 bool isPressed(uint8_t b = MOUSE_ALL); // check all buttons by default
103};
104extern Mouse_ Mouse;
105
106//================================================================================
107//================================================================================
108// Keyboard
109
110#define KEY_LEFT_CTRL 0x80
111#define KEY_LEFT_SHIFT 0x81
112#define KEY_LEFT_ALT 0x82
113#define KEY_LEFT_GUI 0x83
114#define KEY_RIGHT_CTRL 0x84
115#define KEY_RIGHT_SHIFT 0x85
116#define KEY_RIGHT_ALT 0x86
117#define KEY_RIGHT_GUI 0x87
118
119#define KEY_UP_ARROW 0xDA
120#define KEY_DOWN_ARROW 0xD9
121#define KEY_LEFT_ARROW 0xD8
122#define KEY_RIGHT_ARROW 0xD7
123#define KEY_BACKSPACE 0xB2
124#define KEY_TAB 0xB3
125#define KEY_RETURN 0xB0
126#define KEY_ESC 0xB1
127#define KEY_INSERT 0xD1
128#define KEY_DELETE 0xD4
129#define KEY_PAGE_UP 0xD3
130#define KEY_PAGE_DOWN 0xD6
131#define KEY_HOME 0xD2
132#define KEY_END 0xD5
133#define KEY_CAPS_LOCK 0xC1
134#define KEY_F1 0xC2
135#define KEY_F2 0xC3
136#define KEY_F3 0xC4
137#define KEY_F4 0xC5
138#define KEY_F5 0xC6
139#define KEY_F6 0xC7
140#define KEY_F7 0xC8
141#define KEY_F8 0xC9
142#define KEY_F9 0xCA
143#define KEY_F10 0xCB
144#define KEY_F11 0xCC
145#define KEY_F12 0xCD
146
147// Low level key report: up to 6 keys and shift, ctrl etc at once
148typedef struct
149{
150 uint8_t modifiers;
151 uint8_t reserved;
152 uint8_t keys[6];
153} KeyReport;
154
155class Keyboard_ : public Print
156{
157private:
158 KeyReport _keyReport;
159 void sendReport(KeyReport* keys);
160public:
161 Keyboard_(void);
162 void begin(void);
163 void end(void);
164 virtual size_t write(uint8_t k);
165 virtual size_t press(uint8_t k);
166 virtual size_t release(uint8_t k);
167 virtual void releaseAll(void);
168};
169extern Keyboard_ Keyboard;
170
171//================================================================================
172//================================================================================
173// Low level API
174
175typedef struct
176{
177 uint8_t bmRequestType;
178 uint8_t bRequest;
179 uint8_t wValueL;
180 uint8_t wValueH;
181 uint16_t wIndex;
182 uint16_t wLength;
183 uint8_t data[8];
184} Setup;
185
186//================================================================================
187//================================================================================
188// HID 'Driver'
189
190const void* WEAK HID_GetInterface(void);
191uint32_t WEAK HID_GetInterfaceLength(void);
192uint32_t HID_SizeReportDescriptor(void);
193
194uint32_t HID_GetDescriptor(void);
195bool HID_Setup(Setup& setup);
196void HID_SendReport(uint8_t id, const void* data, uint32_t len);
197
198//================================================================================
199//================================================================================
200// MSC 'Driver'
201
202uint32_t MSC_GetInterface(uint8_t* interfaceNum);
203uint32_t MSC_GetDescriptor(uint32_t i);
204bool MSC_Setup(Setup& setup);
205bool MSC_Data(uint8_t rx,uint8_t tx);
206
207//================================================================================
208//================================================================================
209// CDC 'Driver'
210
211const void* CDC_GetInterface(/*uint8_t* interfaceNum*/);
212uint32_t WEAK CDC_GetInterfaceLength(void);
213uint32_t CDC_GetOtherInterface(uint8_t* interfaceNum);
214uint32_t CDC_GetDescriptor(uint32_t i);
215bool CDC_Setup(Setup& setup);
216
217//================================================================================
218//================================================================================
219
220uint32_t USBD_SendControl(uint8_t flags, const void* d, uint32_t len);
221uint32_t USBD_RecvControl(void* d, uint32_t len);
222uint32_t USBD_SendInterfaces(void);
223bool USBD_ClassInterfaceRequest(Setup& setup);
224
225uint32_t USBD_Available(uint32_t ep);
226uint32_t USBD_SendSpace(uint32_t ep);
227uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len);
228uint32_t USBD_Recv(uint32_t ep, void* data, uint32_t len); // non-blocking
229uint32_t USBD_Recv(uint32_t ep); // non-blocking
230void USBD_Flush(uint32_t ep);
231uint32_t USBD_Connected(void);
232
233#endif // __cplusplus
234#endif // __USBAPI__
Note: See TracBrowser for help on using the repository browser.