IUSBHostSerial.h 2.7 KB

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