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.

160 lines
4.7KB

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