Sensor reporting over USB CDC
Dependencies: MAG3110 MMA8451Q SLCD- TSI USBDevice mbed
USBDevice/USBSerial/USBCDC.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 USBCDC_H |
wue | 0:7b58cdacf811 | 20 | #define USBCDC_H |
wue | 0:7b58cdacf811 | 21 | |
wue | 0:7b58cdacf811 | 22 | /* These headers are included for child class. */ |
wue | 0:7b58cdacf811 | 23 | #include "USBEndpoints.h" |
wue | 0:7b58cdacf811 | 24 | #include "USBDescriptor.h" |
wue | 0:7b58cdacf811 | 25 | #include "USBDevice_Types.h" |
wue | 0:7b58cdacf811 | 26 | |
wue | 0:7b58cdacf811 | 27 | #include "USBDevice.h" |
wue | 0:7b58cdacf811 | 28 | |
wue | 0:7b58cdacf811 | 29 | class USBCDC: public USBDevice { |
wue | 0:7b58cdacf811 | 30 | public: |
wue | 0:7b58cdacf811 | 31 | |
wue | 0:7b58cdacf811 | 32 | /* |
wue | 0:7b58cdacf811 | 33 | * Constructor |
wue | 0:7b58cdacf811 | 34 | * |
wue | 0:7b58cdacf811 | 35 | * @param vendor_id Your vendor_id |
wue | 0:7b58cdacf811 | 36 | * @param product_id Your product_id |
wue | 0:7b58cdacf811 | 37 | * @param product_release Your preoduct_release |
wue | 0:7b58cdacf811 | 38 | * @param connect_blocking define if the connection must be blocked if USB not plugged in |
wue | 0:7b58cdacf811 | 39 | */ |
wue | 0:7b58cdacf811 | 40 | USBCDC(uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect_blocking); |
wue | 0:7b58cdacf811 | 41 | |
wue | 0:7b58cdacf811 | 42 | protected: |
wue | 0:7b58cdacf811 | 43 | |
wue | 0:7b58cdacf811 | 44 | /* |
wue | 0:7b58cdacf811 | 45 | * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
wue | 0:7b58cdacf811 | 46 | * |
wue | 0:7b58cdacf811 | 47 | * @returns pointer to the device descriptor |
wue | 0:7b58cdacf811 | 48 | */ |
wue | 0:7b58cdacf811 | 49 | virtual uint8_t * deviceDesc(); |
wue | 0:7b58cdacf811 | 50 | |
wue | 0:7b58cdacf811 | 51 | /* |
wue | 0:7b58cdacf811 | 52 | * Get string product descriptor |
wue | 0:7b58cdacf811 | 53 | * |
wue | 0:7b58cdacf811 | 54 | * @returns pointer to the string product descriptor |
wue | 0:7b58cdacf811 | 55 | */ |
wue | 0:7b58cdacf811 | 56 | virtual uint8_t * stringIproductDesc(); |
wue | 0:7b58cdacf811 | 57 | |
wue | 0:7b58cdacf811 | 58 | /* |
wue | 0:7b58cdacf811 | 59 | * Get string interface descriptor |
wue | 0:7b58cdacf811 | 60 | * |
wue | 0:7b58cdacf811 | 61 | * @returns pointer to the string interface descriptor |
wue | 0:7b58cdacf811 | 62 | */ |
wue | 0:7b58cdacf811 | 63 | virtual uint8_t * stringIinterfaceDesc(); |
wue | 0:7b58cdacf811 | 64 | |
wue | 0:7b58cdacf811 | 65 | /* |
wue | 0:7b58cdacf811 | 66 | * Get configuration descriptor |
wue | 0:7b58cdacf811 | 67 | * |
wue | 0:7b58cdacf811 | 68 | * @returns pointer to the configuration descriptor |
wue | 0:7b58cdacf811 | 69 | */ |
wue | 0:7b58cdacf811 | 70 | virtual uint8_t * configurationDesc(); |
wue | 0:7b58cdacf811 | 71 | |
wue | 0:7b58cdacf811 | 72 | /* |
wue | 0:7b58cdacf811 | 73 | * Send a buffer |
wue | 0:7b58cdacf811 | 74 | * |
wue | 0:7b58cdacf811 | 75 | * @param endpoint endpoint which will be sent the buffer |
wue | 0:7b58cdacf811 | 76 | * @param buffer buffer to be sent |
wue | 0:7b58cdacf811 | 77 | * @param size length of the buffer |
wue | 0:7b58cdacf811 | 78 | * @returns true if successful |
wue | 0:7b58cdacf811 | 79 | */ |
wue | 0:7b58cdacf811 | 80 | bool send(uint8_t * buffer, uint32_t size); |
wue | 0:7b58cdacf811 | 81 | |
wue | 0:7b58cdacf811 | 82 | /* |
wue | 0:7b58cdacf811 | 83 | * Read a buffer from a certain endpoint. Warning: blocking |
wue | 0:7b58cdacf811 | 84 | * |
wue | 0:7b58cdacf811 | 85 | * @param endpoint endpoint to read |
wue | 0:7b58cdacf811 | 86 | * @param buffer buffer where will be stored bytes |
wue | 0:7b58cdacf811 | 87 | * @param size the number of bytes read will be stored in *size |
wue | 0:7b58cdacf811 | 88 | * @param maxSize the maximum length that can be read |
wue | 0:7b58cdacf811 | 89 | * @returns true if successful |
wue | 0:7b58cdacf811 | 90 | */ |
wue | 0:7b58cdacf811 | 91 | bool readEP(uint8_t * buffer, uint32_t * size); |
wue | 0:7b58cdacf811 | 92 | |
wue | 0:7b58cdacf811 | 93 | /* |
wue | 0:7b58cdacf811 | 94 | * Read a buffer from a certain endpoint. Warning: non blocking |
wue | 0:7b58cdacf811 | 95 | * |
wue | 0:7b58cdacf811 | 96 | * @param endpoint endpoint to read |
wue | 0:7b58cdacf811 | 97 | * @param buffer buffer where will be stored bytes |
wue | 0:7b58cdacf811 | 98 | * @param size the number of bytes read will be stored in *size |
wue | 0:7b58cdacf811 | 99 | * @param maxSize the maximum length that can be read |
wue | 0:7b58cdacf811 | 100 | * @returns true if successful |
wue | 0:7b58cdacf811 | 101 | */ |
wue | 0:7b58cdacf811 | 102 | bool readEP_NB(uint8_t * buffer, uint32_t * size); |
wue | 0:7b58cdacf811 | 103 | |
wue | 0:7b58cdacf811 | 104 | /* |
wue | 0:7b58cdacf811 | 105 | * Called by USBCallback_requestCompleted when CDC line coding is changed |
wue | 0:7b58cdacf811 | 106 | * Warning: Called in ISR |
wue | 0:7b58cdacf811 | 107 | * |
wue | 0:7b58cdacf811 | 108 | * @param baud The baud rate |
wue | 0:7b58cdacf811 | 109 | * @param bits The number of bits in a word (5-8) |
wue | 0:7b58cdacf811 | 110 | * @param parity The parity |
wue | 0:7b58cdacf811 | 111 | * @param stop The number of stop bits (1 or 2) |
wue | 0:7b58cdacf811 | 112 | */ |
wue | 0:7b58cdacf811 | 113 | virtual void lineCodingChanged(int baud, int bits, int parity, int stop) {}; |
wue | 0:7b58cdacf811 | 114 | |
wue | 0:7b58cdacf811 | 115 | protected: |
wue | 0:7b58cdacf811 | 116 | virtual bool USBCallback_request(); |
wue | 0:7b58cdacf811 | 117 | virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length); |
wue | 0:7b58cdacf811 | 118 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
wue | 0:7b58cdacf811 | 119 | volatile bool terminal_connected; |
wue | 0:7b58cdacf811 | 120 | |
wue | 0:7b58cdacf811 | 121 | }; |
wue | 0:7b58cdacf811 | 122 | |
wue | 0:7b58cdacf811 | 123 | #endif |