Commit | Line | Data |
---|---|---|
47b0bbd2 MM |
1 | /* Copyright (c) 2010-2011 mbed.org, MIT License\r |
2 | *\r | |
3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software\r | |
4 | * and associated documentation files (the "Software"), to deal in the Software without\r | |
5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish,\r | |
6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the\r | |
7 | * Software is furnished to do so, subject to the following conditions:\r | |
8 | *\r | |
9 | * The above copyright notice and this permission notice shall be included in all copies or\r | |
10 | * substantial portions of the Software.\r | |
11 | *\r | |
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING\r | |
13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r | |
14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\r | |
15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r | |
16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r | |
17 | */\r | |
18 | \r | |
19 | #ifndef USBDEVICE_H\r | |
20 | #define USBDEVICE_H\r | |
21 | \r | |
22 | // #include "mbed.h"\r | |
23 | #include "USBDevice_Types.h"\r | |
24 | #include "USBHAL.h"\r | |
25 | \r | |
26 | #include "../descriptor.h"\r | |
27 | \r | |
28 | class USBDevice: public USBHAL\r | |
29 | {\r | |
30 | public:\r | |
31 | USBDevice();\r | |
32 | \r | |
47b0bbd2 MM |
33 | bool configured(void);\r |
34 | \r | |
47b0bbd2 MM |
35 | bool setDescriptors(usbdesc_base ** descriptors);\r |
36 | \r | |
47b0bbd2 MM |
37 | void connect(void);\r |
38 | \r | |
47b0bbd2 MM |
39 | void disconnect(void);\r |
40 | \r | |
47b0bbd2 MM |
41 | bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);\r |
42 | \r | |
47b0bbd2 | 43 | bool readStart(uint8_t endpoint, uint32_t maxSize);\r |
47b0bbd2 | 44 | bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);\r |
47b0bbd2 MM |
45 | bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);\r |
46 | \r | |
47b0bbd2 | 47 | bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);\r |
47b0bbd2 MM |
48 | bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);\r |
49 | \r | |
47b0bbd2 MM |
50 | virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };\r |
51 | \r | |
47b0bbd2 MM |
52 | virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };\r |
53 | \r | |
47b0bbd2 MM |
54 | protected:\r |
55 | virtual bool USBEvent_busReset(void);\r | |
56 | \r | |
57 | virtual void EP0setupCallback(void);\r | |
58 | virtual void EP0out(void);\r | |
59 | virtual void EP0in(void);\r | |
60 | \r | |
61 | virtual bool USBEvent_Frame(uint16_t);\r | |
62 | \r | |
47b0bbd2 MM |
63 | int findDescriptorIndex(uint8_t start, uint8_t descriptorType, uint8_t descriptorIndex, uint8_t alternate);\r |
64 | int findDescriptorIndex(uint8_t descriptorType, uint8_t descriptorIndex);\r | |
65 | uint8_t * findDescriptor(uint8_t descriptorType, uint8_t descriptorIndex);\r | |
66 | uint8_t * findDescriptor(uint8_t descriptorType);\r | |
67 | \r | |
68 | CONTROL_TRANSFER * getTransferPtr(void);\r | |
69 | \r | |
70 | uint16_t VENDOR_ID;\r | |
71 | uint16_t PRODUCT_ID;\r | |
72 | uint16_t PRODUCT_RELEASE;\r | |
73 | \r | |
74 | private:\r | |
75 | bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);\r | |
76 | bool requestGetDescriptor(void);\r | |
77 | bool controlOut(void);\r | |
78 | bool controlIn(void);\r | |
79 | bool requestSetAddress(void);\r | |
80 | bool requestSetConfiguration(void);\r | |
81 | bool requestSetFeature(void);\r | |
82 | bool requestClearFeature(void);\r | |
83 | bool requestGetStatus(void);\r | |
84 | bool requestSetup(void);\r | |
85 | bool controlSetup(void);\r | |
86 | void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);\r | |
87 | bool requestGetConfiguration(void);\r | |
88 | bool requestGetInterface(void);\r | |
89 | bool requestSetInterface(void);\r | |
90 | bool assembleConfigDescriptor(void);\r | |
91 | \r | |
92 | usbdesc_base **descriptors;\r | |
93 | \r | |
94 | volatile uint16_t lastFrameIndex;\r | |
95 | \r | |
96 | CONTROL_TRANSFER transfer;\r | |
97 | USB_DEVICE device;\r | |
98 | \r | |
99 | uint16_t currentInterface;\r | |
100 | uint8_t currentAlternate;\r | |
101 | };\r | |
102 | \r | |
103 | \r | |
104 | #endif\r |