Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

usb_private.h 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #ifndef STR_MANUFACTURER
  15. #define STR_MANUFACTURER L"Teensyduino"
  16. #endif
  17. #ifndef STR_PRODUCT
  18. #define STR_PRODUCT L"Serial+Keyboard+Mouse+Joystick"
  19. #endif
  20. #ifndef STR_SERIAL
  21. #define STR_SERIAL L"Serial"
  22. #endif
  23. // Some operating systems, especially Windows, may cache USB device
  24. // info. Changes to the device name may not update on the same
  25. // computer unless the vendor or product ID numbers change, or the
  26. // "bcdDevice" revision code is increased.
  27. // All USB serial devices are supposed to have a serial number
  28. // (according to Microsoft). On windows, a new COM port is created
  29. // for every unique serial/vendor/product number combination. If
  30. // you program 2 identical boards with 2 different serial numbers
  31. // and they are assigned COM7 and COM8, each will always get the
  32. // same COM port number because Windows remembers serial numbers.
  33. //
  34. // On Mac OS-X, a device file is created automatically which
  35. // incorperates the serial number, eg, /dev/cu-usbmodem12341
  36. //
  37. // Linux by default ignores the serial number, and creates device
  38. // files named /dev/ttyACM0, /dev/ttyACM1... in the order connected.
  39. // Udev rules (in /etc/udev/rules.d) can define persistent device
  40. // names linked to this serial number, as well as permissions, owner
  41. // and group settings.
  42. #ifndef STR_SERIAL_NUMBER
  43. #define STR_SERIAL_NUMBER L"12345"
  44. #endif
  45. // Mac OS-X and Linux automatically load the correct drivers. On
  46. // Windows, even though the driver is supplied by Microsoft, an
  47. // INF file is needed to load the driver. These numbers need to
  48. // match the INF file.
  49. #define VENDOR_ID 0x16C0
  50. #define PRODUCT_ID 0x0487
  51. // When you write data, it goes into a USB endpoint buffer, which
  52. // is transmitted to the PC when it becomes full, or after a timeout
  53. // with no more writes. Even if you write in exactly packet-size
  54. // increments, this timeout is used to send a "zero length packet"
  55. // that tells the PC no more data is expected and it should pass
  56. // any buffered data to the application that may be waiting. If
  57. // you want data sent immediately, call usb_serial_flush_output().
  58. #define TRANSMIT_FLUSH_TIMEOUT 3 /* in milliseconds */
  59. // If the PC is connected but not "listening", this is the length
  60. // of time before usb_serial_getchar() returns with an error. This
  61. // is roughly equivilant to a real UART simply transmitting the
  62. // bits on a wire where nobody is listening, except you get an error
  63. // code which you can ignore for serial-like discard of data, or
  64. // use to know your data wasn't sent.
  65. #define TRANSMIT_TIMEOUT 15 /* in milliseconds */
  66. /**************************************************************************
  67. *
  68. * Endpoint Buffer Configuration
  69. *
  70. **************************************************************************/
  71. #define ENDPOINT0_SIZE 64
  72. #define KEYBOARD_INTERFACE 2
  73. #define KEYBOARD_ENDPOINT 1
  74. #define KEYBOARD_SIZE 8
  75. #define KEYBOARD_BUFFER EP_DOUBLE_BUFFER
  76. #define KEYBOARD_INTERVAL 1
  77. #define CDC_ACM_ENDPOINT 2
  78. #define CDC_ACM_SIZE 16
  79. #define CDC_ACM_BUFFER EP_SINGLE_BUFFER
  80. #define CDC_RX_ENDPOINT 3
  81. #define CDC_RX_SIZE 64
  82. #define CDC_RX_BUFFER EP_DOUBLE_BUFFER
  83. #define CDC_TX_ENDPOINT 4
  84. #define CDC_TX_BUFFER EP_DOUBLE_BUFFER
  85. #define CDC_TX_SIZE 64
  86. #define MOUSE_INTERFACE 3
  87. #define MOUSE_ENDPOINT 5
  88. #define MOUSE_SIZE 8
  89. #define MOUSE_BUFFER EP_DOUBLE_BUFFER
  90. #define MOUSE_INTERVAL 2
  91. #define JOYSTICK_INTERFACE 4
  92. #define JOYSTICK_ENDPOINT 6
  93. #define JOYSTICK_SIZE 16
  94. #define JOYSTICK_BUFFER EP_DOUBLE_BUFFER
  95. #define JOYSTICK_INTERVAL 1
  96. // setup
  97. void usb_init(void); // initialize everything
  98. void usb_shutdown(void); // shut off USB
  99. // zero when we are not configured, non-zero when enumerated
  100. extern volatile uint8_t usb_configuration;
  101. extern volatile uint8_t usb_suspended;
  102. // the time remaining before we transmit any partially full
  103. // packet, or send a zero length packet.
  104. extern volatile uint8_t transmit_flush_timer;
  105. extern uint8_t transmit_previous_timeout;
  106. // serial port settings (baud rate, control signals, etc) set
  107. // by the PC. These are ignored, but kept in RAM because the
  108. // CDC spec requires a read that returns the current settings.
  109. extern volatile uint8_t cdc_line_coding[7];
  110. extern volatile uint8_t cdc_line_rtsdtr;
  111. extern uint8_t keyboard_report_data[];
  112. extern uint8_t keyboard_idle_count;
  113. extern volatile uint8_t keyboard_leds;
  114. extern uint8_t mouse_buttons;
  115. extern uint8_t joystick_report_data[12];
  116. #ifdef __cplusplus
  117. } // extern "C"
  118. #endif
  119. #endif