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.

пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. int usb_seremu_write_buffer_free(void);
  46. void usb_seremu_flush_output(void);
  47. void usb_seremu_flush_callback(void);
  48. extern volatile uint8_t usb_seremu_transmit_flush_timer;
  49. extern volatile uint8_t usb_configuration;
  50. #ifdef __cplusplus
  51. }
  52. #endif
  53. // C++ interface
  54. #ifdef __cplusplus
  55. #include "Stream.h"
  56. class usb_seremu_class : public Stream
  57. {
  58. public:
  59. void begin(long) { /* TODO: call a function that tries to wait for enumeration */ };
  60. void end() { /* TODO: flush output and shut down USB port */ };
  61. virtual int available() { return usb_seremu_available(); }
  62. virtual int read() { return usb_seremu_getchar(); }
  63. virtual int peek() { return usb_seremu_peekchar(); }
  64. virtual void flush() { usb_seremu_flush_output(); }
  65. virtual size_t write(uint8_t c) { return usb_seremu_putchar(c); }
  66. virtual size_t write(const uint8_t *buffer, size_t size) { return usb_seremu_write(buffer, size); }
  67. size_t write(unsigned long n) { return write((uint8_t)n); }
  68. size_t write(long n) { return write((uint8_t)n); }
  69. size_t write(unsigned int n) { return write((uint8_t)n); }
  70. size_t write(int n) { return write((uint8_t)n); }
  71. int availableForWrite() { return usb_seremu_write_buffer_free(); }
  72. using Print::write;
  73. void send_now(void) { usb_seremu_flush_output(); };
  74. uint32_t baud(void) { return 9600; }
  75. uint8_t stopbits(void) { return 1; }
  76. uint8_t paritytype(void) { return 0; }
  77. uint8_t numbits(void) { return 8; }
  78. uint8_t dtr(void) { return 1; }
  79. uint8_t rts(void) { return 1; }
  80. operator bool() { return usb_configuration; }
  81. };
  82. extern usb_seremu_class Serial;
  83. extern void serialEvent(void);
  84. #endif // __cplusplus
  85. #else // F_CPU < 20 MHz
  86. // Allow Arduino programs using Serial to compile, but Serial will do nothing.
  87. #ifdef __cplusplus
  88. #include "Stream.h"
  89. class usb_seremu_class : public Stream
  90. {
  91. public:
  92. void begin(long) { };
  93. void end() { };
  94. virtual int available() { return 0; }
  95. virtual int read() { return -1; }
  96. virtual int peek() { return -1; }
  97. virtual void flush() { }
  98. virtual size_t write(uint8_t c) { return 1; }
  99. virtual size_t write(const uint8_t *buffer, size_t size) { return size; }
  100. size_t write(unsigned long n) { return 1; }
  101. size_t write(long n) { return 1; }
  102. size_t write(unsigned int n) { return 1; }
  103. size_t write(int n) { return 1; }
  104. int availableForWrite() { return 0; }
  105. using Print::write;
  106. void send_now(void) { }
  107. uint32_t baud(void) { return 0; }
  108. uint8_t stopbits(void) { return 1; }
  109. uint8_t paritytype(void) { return 0; }
  110. uint8_t numbits(void) { return 8; }
  111. uint8_t dtr(void) { return 1; }
  112. uint8_t rts(void) { return 1; }
  113. operator bool() { return true; }
  114. };
  115. extern usb_seremu_class Serial;
  116. extern void serialEvent(void);
  117. #endif // __cplusplus
  118. #endif // F_CPU >= 20 MHz
  119. #endif // USB_HID
  120. #endif // USBseremu_h_