Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

164 lines
4.8KB

  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. #define VENDOR_ID 0x16C0
  13. #define PRODUCT_ID 0x0484
  14. #ifndef STR_PRODUCT
  15. #define STR_PRODUCT L"Teensy Disk/Keyboard"
  16. #endif
  17. #ifndef STR_SERIAL_NUMBER
  18. #define STR_SERIAL_NUMBER L"123456789ABCDEF0"
  19. #endif
  20. // Some operating systems, especially Windows, may cache USB device
  21. // info. Changes to the device name may not update on the same
  22. // computer unless the vendor or product ID numbers change, or the
  23. // "bcdDevice" revision code is increased.
  24. #define TRANSMIT_FLUSH_TIMEOUT 4 /* in milliseconds */
  25. #define TRANSMIT_TIMEOUT 25 /* in milliseconds */
  26. /**************************************************************************
  27. *
  28. * Endpoint Buffer Configuration
  29. *
  30. **************************************************************************/
  31. #if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  32. #define ENDPOINT0_SIZE 64
  33. #define DISK_INTERFACE 0
  34. #define DISK_RX_ENDPOINT 3
  35. #define DISK_RX_SIZE 64
  36. #define DISK_RX_BUFFER EP_DOUBLE_BUFFER
  37. #define DISK_TX_ENDPOINT 4
  38. #define DISK_TX_SIZE 64
  39. #define DISK_TX_BUFFER EP_DOUBLE_BUFFER
  40. #define KEYBOARD_INTERFACE 1
  41. #define KEYBOARD_ENDPOINT 5
  42. #define KEYBOARD_SIZE 8
  43. #define KEYBOARD_BUFFER EP_DOUBLE_BUFFER
  44. #define KEYBOARD_INTERVAL 1
  45. #define DEBUG_INTERFACE 2
  46. #define DEBUG_TX_ENDPOINT 1
  47. #define DEBUG_TX_SIZE 64
  48. #define DEBUG_TX_BUFFER EP_DOUBLE_BUFFER
  49. #define DEBUG_TX_INTERVAL 1
  50. #define DEBUG_RX_ENDPOINT 2
  51. #define DEBUG_RX_SIZE 32
  52. #define DEBUG_RX_BUFFER EP_DOUBLE_BUFFER
  53. #define DEBUG_RX_INTERVAL 2
  54. #define NUM_ENDPOINTS 7
  55. #define NUM_INTERFACE 3
  56. #elif defined(__AVR_AT90USB162__)
  57. #error "USB Disk is not supported on Teensy 1.0\n"
  58. #endif
  59. // setup
  60. void usb_init(void); // initialize everything
  61. void usb_shutdown(void); // shut off USB
  62. // variables
  63. extern volatile uint8_t usb_configuration;
  64. extern volatile uint8_t usb_suspended;
  65. extern volatile uint8_t debug_flush_timer;
  66. extern uint8_t keyboard_report_data[];
  67. extern uint8_t keyboard_idle_count;
  68. extern volatile uint8_t keyboard_leds;
  69. extern uint8_t mouse_buttons;
  70. // disk media access functions
  71. void media_claim(void);
  72. uint8_t media_read_sector(uint32_t lba, uint8_t *buffer);
  73. uint8_t media_write_sector(uint32_t lba, const uint8_t *buffer);
  74. void media_release(uint8_t read_only_mode);
  75. #define OK_UNUSED __attribute__ ((unused))
  76. #if defined(__AVR_AT90USB1286__)
  77. static void (*boot_flash_page_erase_and_write)(uint32_t addr) OK_UNUSED = (void (*)(uint32_t))0xFFE4;
  78. static void (*boot_flash_fill_temp_buffer)(uint16_t data, uint16_t addr) OK_UNUSED = (void (*)(uint16_t, uint16_t))0xFFEA;
  79. static void (*boot_flash_prg_page)(uint32_t addr) OK_UNUSED = (void (*)(uint32_t))0xFFEC;
  80. static void (*boot_flash_page_erase)(uint32_t addr) OK_UNUSED = (void (*)(uint32_t))0xFFEE;
  81. #elif defined(__AVR_AT90USB646__)
  82. static void (*boot_flash_page_erase_and_write)(uint16_t addr) OK_UNUSED = (void (*)(uint16_t))0x7FE4;
  83. static void (*boot_flash_fill_temp_buffer)(uint16_t data, uint16_t addr) OK_UNUSED = (void (*)(uint16_t, uint16_t))0x7FEA;
  84. static void (*boot_flash_prg_page)(uint16_t addr) OK_UNUSED = (void (*)(uint16_t))0x7FEC;
  85. static void (*boot_flash_page_erase)(uint16_t addr) OK_UNUSED = (void (*)(uint16_t))0x7FEE;
  86. #endif
  87. #if defined(__AVR_ATmega32U4__)
  88. #define LPM "lpm "
  89. #define EPZ 0x3F
  90. #if defined(USB_DISK_SDFLASH)
  91. #define READ_ONLY 0
  92. #else
  93. #define READ_ONLY 1
  94. #endif
  95. #elif defined(__AVR_AT90USB646__)
  96. #define LPM "lpm "
  97. #define EPZ 0x7E
  98. #define READ_ONLY 0
  99. #elif defined(__AVR_AT90USB1286__)
  100. #define LPM "elpm "
  101. #define EPZ 0xFE
  102. #define READ_ONLY 0
  103. #endif
  104. #define MS_STATE_IDLE 0
  105. #define MS_STATE_STALLED 1
  106. #define MS_STATE_SEND_STATUS 2
  107. #define MS_STATE_SEND_ZEROPAD 3
  108. #define MS_STATE_SEND_DATA 4
  109. #define MS_STATE_RECEIVE_DATA 5
  110. #define SCSI_CMD_TEST_UNIT_READY 0x00
  111. #define SCSI_CMD_REQUEST_SENSE 0x03
  112. #define SCSI_CMD_INQUIRY 0x12
  113. #define SCSI_CMD_MODE_SENSE_6 0x1A
  114. #define SCSI_CMD_MODE_SENSE_10 0x5A
  115. #define SCSI_CMD_READ_CAPACITY 0x25
  116. #define SCSI_CMD_READ_10 0x28
  117. #define SCSI_CMD_WRITE_10 0x2A
  118. #define SCSI_CMD_FORMAT_UNIT 0x04
  119. #define SCSI_CMD_SEND_DIAGNOSTIC 0x1D
  120. #define SCSI_CMD_PREVENT_ALLOW_MEDIA_REMOVAL 0x1E
  121. #define SCSI_CMD_READ_FORMAT_CAPACITIES 0x23
  122. #define SCSI_SENSE_OK 0x00 // http://docs.hp.com/en/A5159-96003/apas01.html
  123. #define SCSI_SENSE_NOT_READY 0x02
  124. #define SCSI_SENSE_ILLEGAL_REQUEST 0x05
  125. #define SCSI_SENSE_UNIT_ATTENTION 0x06
  126. #define SCSI_ASENSE_NONE 0x00
  127. #define SCSI_ASENSE_INVALID_COMMAND 0x20
  128. #define SCSI_ASENSE_NOT_READY_TO_READY 0x28
  129. #define SCSI_ASENSE_MEDIUM_NOT_PRESENT 0x3A
  130. #ifdef __cplusplus
  131. } // extern "C"
  132. #endif
  133. #endif