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