Teensy 4.1 core updated for C++20
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.

126 satır
4.6KB

  1. #ifndef usb_serial_h__
  2. #define usb_serial_h__
  3. #include <stdint.h>
  4. #ifdef __cplusplus
  5. extern "C"{
  6. #endif
  7. /**************************************************************************
  8. *
  9. * Configurable Options
  10. *
  11. **************************************************************************/
  12. // You can change these to give your code its own name. On Windows,
  13. // these are only used before an INF file (driver install) is loaded.
  14. #define STR_MANUFACTURER L"Teensyduino"
  15. #define STR_PRODUCT L"USB Serial"
  16. // Some operating systems, especially Windows, may cache USB device
  17. // info. Changes to the device name may not update on the same
  18. // computer unless the vendor or product ID numbers change, or the
  19. // "bcdDevice" revision code is increased.
  20. // All USB serial devices are supposed to have a serial number
  21. // (according to Microsoft). On windows, a new COM port is created
  22. // for every unique serial/vendor/product number combination. If
  23. // you program 2 identical boards with 2 different serial numbers
  24. // and they are assigned COM7 and COM8, each will always get the
  25. // same COM port number because Windows remembers serial numbers.
  26. //
  27. // On Mac OS-X, a device file is created automatically which
  28. // incorperates the serial number, eg, /dev/cu-usbmodem12341
  29. //
  30. // Linux by default ignores the serial number, and creates device
  31. // files named /dev/ttyACM0, /dev/ttyACM1... in the order connected.
  32. // Udev rules (in /etc/udev/rules.d) can define persistent device
  33. // names linked to this serial number, as well as permissions, owner
  34. // and group settings.
  35. #define STR_SERIAL_NUMBER L"12345"
  36. // Mac OS-X and Linux automatically load the correct drivers. On
  37. // Windows, even though the driver is supplied by Microsoft, an
  38. // INF file is needed to load the driver. These numbers need to
  39. // match the INF file.
  40. #define VENDOR_ID 0x16C0
  41. #define PRODUCT_ID 0x0483
  42. // When you write data, it goes into a USB endpoint buffer, which
  43. // is transmitted to the PC when it becomes full, or after a timeout
  44. // with no more writes. Even if you write in exactly packet-size
  45. // increments, this timeout is used to send a "zero length packet"
  46. // that tells the PC no more data is expected and it should pass
  47. // any buffered data to the application that may be waiting. If
  48. // you want data sent immediately, call usb_serial_flush_output().
  49. #define TRANSMIT_FLUSH_TIMEOUT 3 /* in milliseconds */
  50. // If the PC is connected but not "listening", this is the length
  51. // of time before usb_serial_getchar() returns with an error. This
  52. // is roughly equivilant to a real UART simply transmitting the
  53. // bits on a wire where nobody is listening, except you get an error
  54. // code which you can ignore for serial-like discard of data, or
  55. // use to know your data wasn't sent.
  56. #define TRANSMIT_TIMEOUT 15 /* in milliseconds */
  57. /**************************************************************************
  58. *
  59. * Endpoint Buffer Configuration
  60. *
  61. **************************************************************************/
  62. // These buffer sizes are best for most applications, but perhaps if you
  63. // want more buffering on some endpoint at the expense of others, this
  64. // is where you can make such changes. The AT90USB162 has only 176 bytes
  65. // of DPRAM (USB buffers) and only endpoints 3 & 4 can double buffer.
  66. #define ENDPOINT0_SIZE 32
  67. #define CDC_ACM_ENDPOINT 2
  68. #define CDC_ACM_SIZE 8
  69. #define CDC_ACM_BUFFER EP_SINGLE_BUFFER
  70. #define CDC_RX_ENDPOINT 3
  71. #define CDC_RX_BUFFER EP_DOUBLE_BUFFER
  72. #define CDC_TX_ENDPOINT 4
  73. #define CDC_TX_BUFFER EP_DOUBLE_BUFFER
  74. #if defined(__AVR_AT90USB162__)
  75. #define CDC_RX_SIZE 32
  76. #define CDC_TX_SIZE 32
  77. #elif defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  78. #define CDC_RX_SIZE 64
  79. #define CDC_TX_SIZE 64
  80. #endif
  81. // setup
  82. void usb_init(void); // initialize everything
  83. void usb_shutdown(void); // shut off USB
  84. // zero when we are not configured, non-zero when enumerated
  85. extern volatile uint8_t usb_configuration;
  86. extern volatile uint8_t usb_suspended;
  87. // the time remaining before we transmit any partially full
  88. // packet, or send a zero length packet.
  89. extern volatile uint8_t transmit_flush_timer;
  90. extern uint8_t transmit_previous_timeout;
  91. // serial port settings (baud rate, control signals, etc) set
  92. // by the PC. These are ignored, but kept in RAM because the
  93. // CDC spec requires a read that returns the current settings.
  94. extern volatile uint8_t cdc_line_coding[7];
  95. extern volatile uint8_t cdc_line_rtsdtr;
  96. #ifdef __cplusplus
  97. } // extern "C"
  98. #endif
  99. #endif