Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

92 lines
3.5KB

  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. // C language implementation
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. int usb_seremu_getchar(void);
  39. int usb_seremu_peekchar(void);
  40. int usb_seremu_available(void);
  41. void usb_seremu_flush_input(void);
  42. int usb_seremu_putchar(uint8_t c);
  43. int usb_seremu_write(const void *buffer, uint32_t size);
  44. void usb_seremu_flush_output(void);
  45. void usb_seremu_flush_callback(void);
  46. extern volatile uint8_t usb_seremu_transmit_flush_timer;
  47. extern volatile uint8_t usb_configuration;
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. // C++ interface
  52. #ifdef __cplusplus
  53. #include "Stream.h"
  54. class usb_seremu_class : public Stream
  55. {
  56. public:
  57. void begin(long) { /* TODO: call a function that tries to wait for enumeration */ };
  58. void end() { /* TODO: flush output and shut down USB port */ };
  59. virtual int available() { return usb_seremu_available(); }
  60. virtual int read() { return usb_seremu_getchar(); }
  61. virtual int peek() { return usb_seremu_peekchar(); }
  62. virtual void flush() { usb_seremu_flush_output(); }
  63. virtual size_t write(uint8_t c) { return usb_seremu_putchar(c); }
  64. virtual size_t write(const uint8_t *buffer, size_t size) { return usb_seremu_write(buffer, size); }
  65. size_t write(unsigned long n) { return write((uint8_t)n); }
  66. size_t write(long n) { return write((uint8_t)n); }
  67. size_t write(unsigned int n) { return write((uint8_t)n); }
  68. size_t write(int n) { return write((uint8_t)n); }
  69. using Print::write;
  70. void send_now(void) { usb_seremu_flush_output(); };
  71. uint32_t baud(void) { return 9600; }
  72. uint8_t stopbits(void) { return 1; }
  73. uint8_t paritytype(void) { return 0; }
  74. uint8_t numbits(void) { return 8; }
  75. uint8_t dtr(void) { return 1; }
  76. uint8_t rts(void) { return 1; }
  77. operator bool() { return usb_configuration; }
  78. };
  79. extern usb_seremu_class Serial;
  80. #endif // __cplusplus
  81. #endif // USB_HID
  82. #endif // USBseremu_h_