Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

133 lines
4.7KB

  1. /* Teensyduino Core Library
  2. * http://www.pjrc.com/teensy/
  3. * Copyright (c) 2017 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. #pragma once
  31. #include "usb_desc.h"
  32. #if defined(SEREMU_INTERFACE) && !defined(CDC_STATUS_INTERFACE) && !defined(CDC_DATA_INTERFACE)
  33. #include <stdint.h>
  34. // C language implementation
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. void usb_seremu_reset(void);
  39. void usb_seremu_configure(void);
  40. int usb_seremu_getchar(void);
  41. int usb_seremu_peekchar(void);
  42. int usb_seremu_available(void);
  43. void usb_seremu_flush_input(void);
  44. int usb_seremu_putchar(uint8_t c);
  45. int usb_seremu_write(const void *buffer, uint32_t size);
  46. int usb_seremu_write_buffer_free(void);
  47. void usb_seremu_flush_output(void);
  48. extern volatile uint8_t usb_configuration;
  49. extern volatile uint8_t usb_seremu_online;
  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. constexpr usb_seremu_class() {}
  60. void begin(long) { /* TODO: call a function that tries to wait for enumeration */ };
  61. void end() { /* TODO: flush output and shut down USB port */ };
  62. virtual int available() { return usb_seremu_available(); }
  63. virtual int read() { return usb_seremu_getchar(); }
  64. virtual int peek() { return usb_seremu_peekchar(); }
  65. virtual void flush() { usb_seremu_flush_output(); }
  66. virtual size_t write(uint8_t c) { return usb_seremu_putchar(c); }
  67. virtual size_t write(const uint8_t *buffer, size_t size) { return usb_seremu_write(buffer, size); }
  68. size_t write(unsigned long n) { return write((uint8_t)n); }
  69. size_t write(long n) { return write((uint8_t)n); }
  70. size_t write(unsigned int n) { return write((uint8_t)n); }
  71. size_t write(int n) { return write((uint8_t)n); }
  72. virtual int availableForWrite() { return usb_seremu_write_buffer_free(); }
  73. using Print::write;
  74. void send_now(void) { usb_seremu_flush_output(); };
  75. uint32_t baud(void) { return 9600; }
  76. uint8_t stopbits(void) { return 1; }
  77. uint8_t paritytype(void) { return 0; }
  78. uint8_t numbits(void) { return 8; }
  79. uint8_t dtr(void) { return 1; }
  80. uint8_t rts(void) { return 1; }
  81. operator bool() { return usb_configuration && usb_seremu_online; }
  82. };
  83. extern usb_seremu_class Serial;
  84. extern void serialEvent(void);
  85. #endif // __cplusplus
  86. #if 0
  87. // Allow Arduino programs using Serial to compile, but Serial will do nothing.
  88. #ifdef __cplusplus
  89. #include "Stream.h"
  90. class usb_seremu_class : public Stream
  91. {
  92. public:
  93. constexpr usb_seremu_class() {}
  94. void begin(long) { };
  95. void end() { };
  96. virtual int available() { return 0; }
  97. virtual int read() { return -1; }
  98. virtual int peek() { return -1; }
  99. virtual void flush() { }
  100. virtual size_t write(uint8_t c) { return 1; }
  101. virtual size_t write(const uint8_t *buffer, size_t size) { return size; }
  102. size_t write(unsigned long n) { return 1; }
  103. size_t write(long n) { return 1; }
  104. size_t write(unsigned int n) { return 1; }
  105. size_t write(int n) { return 1; }
  106. int availableForWrite() { return 0; }
  107. using Print::write;
  108. void send_now(void) { }
  109. uint32_t baud(void) { return 0; }
  110. uint8_t stopbits(void) { return 1; }
  111. uint8_t paritytype(void) { return 0; }
  112. uint8_t numbits(void) { return 8; }
  113. uint8_t dtr(void) { return 1; }
  114. uint8_t rts(void) { return 1; }
  115. operator bool() { return true; }
  116. };
  117. extern usb_seremu_class Serial;
  118. extern void serialEvent(void);
  119. #endif // __cplusplus
  120. #endif
  121. #endif // SEREMU_INTERFACE