]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/USBDevice/USBDevice/USBHAL.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / USBDevice / USBDevice / USBHAL.h
1 /* Copyright (c) 2010-2011 mbed.org, MIT License
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without
5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 */
18
19 #ifndef USBBUSINTERFACE_H
20 #define USBBUSINTERFACE_H
21
22 #include "mbed.h"
23 #include "USBEndpoints.h"
24 #include "toolchain.h"
25
26 //#ifdef __GNUC__
27 //#define __packed __attribute__ ((__packed__))
28 //#endif
29
30 class USBHAL {
31 public:
32     /* Configuration */
33     USBHAL();
34     ~USBHAL();
35     void connect(void);
36     void disconnect(void);
37     void configureDevice(void);
38     void unconfigureDevice(void);
39     void setAddress(uint8_t address);
40     void remoteWakeup(void);
41
42     /* Endpoint 0 */
43     void EP0setup(uint8_t *buffer);
44     void EP0read(void);
45     void EP0readStage(void);
46     uint32_t EP0getReadResult(uint8_t *buffer);
47     void EP0write(uint8_t *buffer, uint32_t size);
48     void EP0getWriteResult(void);
49     void EP0stall(void);
50
51     /* Other endpoints */
52     EP_STATUS endpointRead(uint8_t endpoint, uint32_t maximumSize);
53     EP_STATUS endpointReadResult(uint8_t endpoint, uint8_t *data, uint32_t *bytesRead);
54     EP_STATUS endpointWrite(uint8_t endpoint, uint8_t *data, uint32_t size);
55     EP_STATUS endpointWriteResult(uint8_t endpoint);
56     void stallEndpoint(uint8_t endpoint);
57     void unstallEndpoint(uint8_t endpoint);
58     bool realiseEndpoint(uint8_t endpoint, uint32_t maxPacket, uint32_t options);
59     bool getEndpointStallState(unsigned char endpoint);
60     uint32_t endpointReadcore(uint8_t endpoint, uint8_t *buffer);
61
62 protected:
63     virtual void busReset(void){};
64     virtual void EP0setupCallback(void){};
65     virtual void EP0out(void){};
66     virtual void EP0in(void){};
67     virtual void connectStateChanged(unsigned int connected){};
68     virtual void suspendStateChanged(unsigned int suspended){};
69     virtual void SOF(int frameNumber){};
70
71     virtual bool EP1_OUT_callback(){return false;};
72     virtual bool EP1_IN_callback(){return false;};
73     virtual bool EP2_OUT_callback(){return false;};
74     virtual bool EP2_IN_callback(){return false;};
75     virtual bool EP3_OUT_callback(){return false;};
76     virtual bool EP3_IN_callback(){return false;};
77 #if !defined(TARGET_STM32F4)
78     virtual bool EP4_OUT_callback(){return false;};
79     virtual bool EP4_IN_callback(){return false;};
80 #if !(defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549))
81     virtual bool EP5_OUT_callback(){return false;};
82     virtual bool EP5_IN_callback(){return false;};
83     virtual bool EP6_OUT_callback(){return false;};
84     virtual bool EP6_IN_callback(){return false;};
85     virtual bool EP7_OUT_callback(){return false;};
86     virtual bool EP7_IN_callback(){return false;};
87     virtual bool EP8_OUT_callback(){return false;};
88     virtual bool EP8_IN_callback(){return false;};
89     virtual bool EP9_OUT_callback(){return false;};
90     virtual bool EP9_IN_callback(){return false;};
91     virtual bool EP10_OUT_callback(){return false;};
92     virtual bool EP10_IN_callback(){return false;};
93     virtual bool EP11_OUT_callback(){return false;};
94     virtual bool EP11_IN_callback(){return false;};
95     virtual bool EP12_OUT_callback(){return false;};
96     virtual bool EP12_IN_callback(){return false;};
97     virtual bool EP13_OUT_callback(){return false;};
98     virtual bool EP13_IN_callback(){return false;};
99     virtual bool EP14_OUT_callback(){return false;};
100     virtual bool EP14_IN_callback(){return false;};
101     virtual bool EP15_OUT_callback(){return false;};
102     virtual bool EP15_IN_callback(){return false;};
103 #endif
104 #endif
105
106 private:
107     void usbisr(void);
108     static void _usbisr(void);
109     static USBHAL * instance;
110
111 #if defined(TARGET_LPC11UXX) || defined(TARGET_LPC11U6X) || defined(TARGET_LPC1347) || defined(TARGET_LPC1549)
112         bool (USBHAL::*epCallback[10 - 2])(void);
113 #elif defined(TARGET_STM32F4)
114         bool (USBHAL::*epCallback[8 - 2])(void);
115 #else
116         bool (USBHAL::*epCallback[32 - 2])(void);
117 #endif
118
119
120 };
121 #endif