Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

USBCDC.h 4.0KB

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