2018.07.26
Dependencies: FATFileSystem2 mbed-rtos
Fork of USBHost by
USBHost3GModule/IUSBHostSerial.h@43:78f328f311dc, 2018-07-26 (annotated)
- Committer:
- sayzyas
- Date:
- Thu Jul 26 00:19:16 2018 +0000
- Revision:
- 43:78f328f311dc
2018.07.26
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sayzyas | 43:78f328f311dc | 1 | /* IUSBHostSerial.h */ |
sayzyas | 43:78f328f311dc | 2 | /* Copyright (c) 2010-2012 mbed.org, MIT License |
sayzyas | 43:78f328f311dc | 3 | * |
sayzyas | 43:78f328f311dc | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
sayzyas | 43:78f328f311dc | 5 | * and associated documentation files (the "Software"), to deal in the Software without |
sayzyas | 43:78f328f311dc | 6 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
sayzyas | 43:78f328f311dc | 7 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
sayzyas | 43:78f328f311dc | 8 | * Software is furnished to do so, subject to the following conditions: |
sayzyas | 43:78f328f311dc | 9 | * |
sayzyas | 43:78f328f311dc | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
sayzyas | 43:78f328f311dc | 11 | * substantial portions of the Software. |
sayzyas | 43:78f328f311dc | 12 | * |
sayzyas | 43:78f328f311dc | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
sayzyas | 43:78f328f311dc | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
sayzyas | 43:78f328f311dc | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
sayzyas | 43:78f328f311dc | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
sayzyas | 43:78f328f311dc | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
sayzyas | 43:78f328f311dc | 18 | */ |
sayzyas | 43:78f328f311dc | 19 | |
sayzyas | 43:78f328f311dc | 20 | #ifndef IUSBHOSTSERIAL_H_ |
sayzyas | 43:78f328f311dc | 21 | #define IUSBHOSTSERIAL_H_ |
sayzyas | 43:78f328f311dc | 22 | |
sayzyas | 43:78f328f311dc | 23 | /** |
sayzyas | 43:78f328f311dc | 24 | * Generic interface to abstract 3G dongles' impl |
sayzyas | 43:78f328f311dc | 25 | */ |
sayzyas | 43:78f328f311dc | 26 | |
sayzyas | 43:78f328f311dc | 27 | #include "USBHostConf.h" |
sayzyas | 43:78f328f311dc | 28 | |
sayzyas | 43:78f328f311dc | 29 | #ifdef USBHOST_3GMODULE |
sayzyas | 43:78f328f311dc | 30 | |
sayzyas | 43:78f328f311dc | 31 | #include "IUSBHostSerialListener.h" |
sayzyas | 43:78f328f311dc | 32 | |
sayzyas | 43:78f328f311dc | 33 | // This is needed by some versions of GCC |
sayzyas | 43:78f328f311dc | 34 | #undef putc |
sayzyas | 43:78f328f311dc | 35 | #undef getc |
sayzyas | 43:78f328f311dc | 36 | |
sayzyas | 43:78f328f311dc | 37 | class IUSBHostSerial { |
sayzyas | 43:78f328f311dc | 38 | public: |
sayzyas | 43:78f328f311dc | 39 | |
sayzyas | 43:78f328f311dc | 40 | enum IrqType { |
sayzyas | 43:78f328f311dc | 41 | RxIrq, |
sayzyas | 43:78f328f311dc | 42 | TxIrq |
sayzyas | 43:78f328f311dc | 43 | }; |
sayzyas | 43:78f328f311dc | 44 | |
sayzyas | 43:78f328f311dc | 45 | /* |
sayzyas | 43:78f328f311dc | 46 | * Get a char from the dongle's serial interface |
sayzyas | 43:78f328f311dc | 47 | */ |
sayzyas | 43:78f328f311dc | 48 | virtual int getc() = 0; |
sayzyas | 43:78f328f311dc | 49 | |
sayzyas | 43:78f328f311dc | 50 | /* |
sayzyas | 43:78f328f311dc | 51 | * Put a char to the dongle's serial interface |
sayzyas | 43:78f328f311dc | 52 | */ |
sayzyas | 43:78f328f311dc | 53 | virtual int putc(int c) = 0; |
sayzyas | 43:78f328f311dc | 54 | |
sayzyas | 43:78f328f311dc | 55 | /* |
sayzyas | 43:78f328f311dc | 56 | * Read a packet from the dongle's serial interface, to be called after multiple getc() calls |
sayzyas | 43:78f328f311dc | 57 | */ |
sayzyas | 43:78f328f311dc | 58 | virtual int readPacket() = 0; |
sayzyas | 43:78f328f311dc | 59 | |
sayzyas | 43:78f328f311dc | 60 | /* |
sayzyas | 43:78f328f311dc | 61 | * Write a packet to the dongle's serial interface, to be called after multiple putc() calls |
sayzyas | 43:78f328f311dc | 62 | */ |
sayzyas | 43:78f328f311dc | 63 | virtual int writePacket() = 0; |
sayzyas | 43:78f328f311dc | 64 | |
sayzyas | 43:78f328f311dc | 65 | /** |
sayzyas | 43:78f328f311dc | 66 | * Check the number of bytes available. |
sayzyas | 43:78f328f311dc | 67 | * |
sayzyas | 43:78f328f311dc | 68 | * @returns the number of bytes available |
sayzyas | 43:78f328f311dc | 69 | */ |
sayzyas | 43:78f328f311dc | 70 | virtual int readable() = 0; |
sayzyas | 43:78f328f311dc | 71 | |
sayzyas | 43:78f328f311dc | 72 | /** |
sayzyas | 43:78f328f311dc | 73 | * Check the free space in output. |
sayzyas | 43:78f328f311dc | 74 | * |
sayzyas | 43:78f328f311dc | 75 | * @returns the number of bytes available |
sayzyas | 43:78f328f311dc | 76 | */ |
sayzyas | 43:78f328f311dc | 77 | virtual int writeable() = 0; |
sayzyas | 43:78f328f311dc | 78 | |
sayzyas | 43:78f328f311dc | 79 | /** |
sayzyas | 43:78f328f311dc | 80 | * Attach a handler to call when a packet is received / when a packet has been transmitted. |
sayzyas | 43:78f328f311dc | 81 | * |
sayzyas | 43:78f328f311dc | 82 | * @param pListener instance of the listener deriving from the IUSBHostSerialListener |
sayzyas | 43:78f328f311dc | 83 | */ |
sayzyas | 43:78f328f311dc | 84 | virtual void attach(IUSBHostSerialListener* pListener) = 0; |
sayzyas | 43:78f328f311dc | 85 | |
sayzyas | 43:78f328f311dc | 86 | /** |
sayzyas | 43:78f328f311dc | 87 | * Enable or disable readable/writeable callbacks |
sayzyas | 43:78f328f311dc | 88 | */ |
sayzyas | 43:78f328f311dc | 89 | virtual void setupIrq(bool en, IrqType irq = RxIrq) = 0; |
sayzyas | 43:78f328f311dc | 90 | |
sayzyas | 43:78f328f311dc | 91 | }; |
sayzyas | 43:78f328f311dc | 92 | |
sayzyas | 43:78f328f311dc | 93 | #endif /* USBHOST_3GMODULE */ |
sayzyas | 43:78f328f311dc | 94 | |
sayzyas | 43:78f328f311dc | 95 | #endif /* IUSBHOSTSERIAL_H_ */ |