Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

usb_seremu.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2013 PJRC.COM, LLC.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * 1. The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * 2. If the Software is incorporated into a build system that allows
  17. * selection among a list of target devices, then similar target
  18. * devices manufactured by PJRC.COM must be included in the list of
  19. * target devices and selectable in the same manner.
  20. *
  21. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  25. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  26. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  27. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  28. * SOFTWARE.
  29. */
  30. #ifndef USBseremu_h_
  31. #define USBseremu_h_
  32. #if defined(USB_HID) || defined(USB_MIDI) || defined(USB_RAWHID) || defined(USB_FLIGHTSIM)
  33. #include <inttypes.h>
  34. #if F_CPU >= 20000000
  35. // C language implementation
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. int usb_seremu_getchar(void);
  40. int usb_seremu_peekchar(void);
  41. int usb_seremu_available(void);
  42. void usb_seremu_flush_input(void);
  43. int usb_seremu_putchar(uint8_t c);
  44. int usb_seremu_write(const void *buffer, uint32_t size);
  45. void usb_seremu_flush_output(void);
  46. void usb_seremu_flush_callback(void);
  47. extern volatile uint8_t usb_seremu_transmit_flush_timer;
  48. extern volatile uint8_t usb_configuration;
  49. #ifdef __cplusplus
  50. }
  51. #endif
  52. // C++ interface
  53. #ifdef __cplusplus
  54. #include "Stream.h"
  55. class usb_seremu_class : public Stream
  56. {
  57. public:
  58. void begin(long) { /* TODO: call a function that tries to wait for enumeration */ };
  59. void end() { /* TODO: flush output and shut down USB port */ };
  60. virtual int available() { return usb_seremu_available(); }
  61. virtual int read() { return usb_seremu_getchar(); }
  62. virtual int peek() { return usb_seremu_peekchar(); }
  63. virtual void flush() { usb_seremu_flush_output(); }
  64. virtual size_t write(uint8_t c) { return usb_seremu_putchar(c); }
  65. virtual size_t write(const uint8_t *buffer, size_t size) { return usb_seremu_write(buffer, size); }
  66. size_t write(unsigned long n) { return write((uint8_t)n); }
  67. size_t write(long n) { return write((uint8_t)n); }
  68. size_t write(unsigned int n) { return write((uint8_t)n); }
  69. size_t write(int n) { return write((uint8_t)n); }
  70. using Print::write;
  71. void send_now(void) { usb_seremu_flush_output(); };
  72. uint32_t baud(void) { return 9600; }
  73. uint8_t stopbits(void) { return 1; }
  74. uint8_t paritytype(void) { return 0; }
  75. uint8_t numbits(void) { return 8; }
  76. uint8_t dtr(void) { return 1; }
  77. uint8_t rts(void) { return 1; }
  78. operator bool() { return usb_configuration; }
  79. };
  80. extern usb_seremu_class Serial;
  81. extern void serialEvent(void);
  82. #endif // __cplusplus
  83. #else // F_CPU < 20 MHz
  84. // Allow Arduino programs using Serial to compile, but Serial will do nothing.
  85. #ifdef __cplusplus
  86. #include "Stream.h"
  87. class usb_seremu_class : public Stream
  88. {
  89. public:
  90. void begin(long) { };
  91. void end() { };
  92. virtual int available() { return 0; }
  93. virtual int read() { return -1; }
  94. virtual int peek() { return -1; }
  95. virtual void flush() { }
  96. virtual size_t write(uint8_t c) { return 1; }
  97. virtual size_t write(const uint8_t *buffer, size_t size) { return size; }
  98. size_t write(unsigned long n) { return 1; }
  99. size_t write(long n) { return 1; }
  100. size_t write(unsigned int n) { return 1; }
  101. size_t write(int n) { return 1; }
  102. using Print::write;
  103. void send_now(void) { }
  104. uint32_t baud(void) { return 0; }
  105. uint8_t stopbits(void) { return 1; }
  106. uint8_t paritytype(void) { return 0; }
  107. uint8_t numbits(void) { return 8; }
  108. uint8_t dtr(void) { return 1; }
  109. uint8_t rts(void) { return 1; }
  110. operator bool() { return true; }
  111. };
  112. extern usb_seremu_class Serial;
  113. extern void serialEvent(void);
  114. #endif // __cplusplus
  115. #endif // F_CPU >= 20 MHz
  116. #endif // USB_HID
  117. #endif // USBseremu_h_