1 #if !defined(__MASSTORAGE_H__)
2 #define __MASSTORAGE_H__
8 #include <avr/pgmspace.h>
14 #if defined(ARDUINO) && ARDUINO >=100
22 #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b)))
24 #define bmREQ_MASSOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
25 #define bmREQ_MASSIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
28 #define MASS_SUBCLASS_SCSI_NOT_REPORTED 0x00 // De facto use
29 #define MASS_SUBCLASS_RBC 0x01
30 #define MASS_SUBCLASS_ATAPI 0x02 // MMC-5 (ATAPI)
31 #define MASS_SUBCLASS_OBSOLETE1 0x03 // Was QIC-157
32 #define MASS_SUBCLASS_UFI 0x04 // Specifies how to interface Floppy Disk Drives to USB
33 #define MASS_SUBCLASS_OBSOLETE2 0x05 // Was SFF-8070i
34 #define MASS_SUBCLASS_SCSI 0x06 // SCSI Transparent Command Set
35 #define MASS_SUBCLASS_LSDFS 0x07 // Specifies how host has to negotiate access before trying SCSI
36 #define MASS_SUBCLASS_IEEE1667 0x08
39 #define MASS_PROTO_CBI 0x00 // CBI (with command completion interrupt)
40 #define MASS_PROTO_CBI_NO_INT 0x01 // CBI (without command completion interrupt)
41 #define MASS_PROTO_OBSOLETE 0x02
42 #define MASS_PROTO_BBB 0x50 // Bulk Only Transport
43 #define MASS_PROTO_UAS 0x62
46 #define MASS_REQ_ADSC 0x00
47 #define MASS_REQ_GET 0xFC
48 #define MASS_REQ_PUT 0xFD
49 #define MASS_REQ_GET_MAX_LUN 0xFE
50 #define MASS_REQ_BOMSR 0xFF // Bulk-Only Mass Storage Reset
52 #define MASS_CBW_SIGNATURE 0x43425355
53 #define MASS_CSW_SIGNATURE 0x53425355
55 #define MASS_CMD_DIR_OUT (0 << 7)
56 #define MASS_CMD_DIR_IN (1 << 7)
58 #define SCSI_CMD_INQUIRY 0x12
59 #define SCSI_CMD_REPORT_LUNS 0xA0
60 #define SCSI_CMD_REQUEST_SENSE 0x03
61 #define SCSI_CMD_FORMAT_UNIT 0x04
62 #define SCSI_CMD_READ_6 0x08
63 #define SCSI_CMD_READ_10 0x28
64 #define SCSI_CMD_READ_CAPACITY_10 0x25
65 #define SCSI_CMD_TEST_UNIT_READY 0x00
66 #define SCSI_CMD_WRITE_6 0x0A
67 #define SCSI_CMD_WRITE_10 0x2A
68 #define SCSI_CMD_MODE_SENSE_6 0x1A
69 #define SCSI_CMD_MODE_SENSE_10 0x5A
70 #define SCSI_CMD_START_STOP_UNIT 0x1B
72 #define SCSI_S_NOT_READY 0x02
73 #define SCSI_S_MEDIUM_ERROR 0x03
74 #define SCSI_S_ILLEGAL_REQUEST 0x05
75 #define SCSI_S_UNIT_ATTENTION 0x06
77 #define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A
78 #define SCSI_ASC_LBA_OUT_OF_RANGE 0x21
81 #define MASS_ERR_SUCCESS 0x00
82 #define MASS_ERR_PHASE_ERROR 0x02
83 #define MASS_ERR_UNIT_NOT_READY 0x03
84 #define MASS_ERR_UNIT_BUSY 0x04
85 #define MASS_ERR_STALL 0x05
86 #define MASS_ERR_CMD_NOT_SUPPORTED 0x06
87 #define MASS_ERR_INVALID_CSW 0x07
88 #define MASS_ERR_NO_MEDIA 0x08
89 #define MASS_ERR_BAD_LBA 0x09
90 #define MASS_ERR_DEVICE_DISCONNECTED 0x11
91 #define MASS_ERR_UNABLE_TO_RECOVER 0x12 // Reset recovery error
92 #define MASS_ERR_INVALID_LUN 0x13
93 #define MASS_ERR_GENERAL_SCSI_ERROR 0xFE
94 #define MASS_ERR_GENERAL_USB_ERROR 0xFF
95 #define MASS_ERR_USER 0xA0 // For subclasses to define their own error codes
97 #define MASS_TRANS_FLG_CALLBACK 0x01 // Callback is involved
98 #define MASS_TRANS_FLG_NO_STALL_CHECK 0x02 // STALL condition is not checked
99 #define MASS_TRANS_FLG_NO_PHASE_CHECK 0x04 // PHASE_ERROR is not checked
105 } __attribute__((packed));
137 } __attribute__((packed));
144 } __attribute__((packed));
159 } __attribute__((packed));
166 } __attribute__((packed));
185 } __attribute__((packed));
187 #define MASS_MAX_ENDPOINTS 3
244 uint8_t
Inquiry(uint8_t lun, uint16_t size, uint8_t *buf);
246 uint8_t
ReadCapacity(uint8_t lun, uint16_t size, uint8_t *buf);
247 uint8_t
RequestSense(uint8_t lun, uint16_t size, uint8_t *buf);
248 uint8_t
ModeSense(uint8_t lun, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t len, uint8_t *buf);
249 uint8_t
MediaCTL(uint8_t lun, uint8_t ctl);
250 uint8_t
Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, uint8_t *buf);
251 uint8_t
Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks,
USBReadParser *prs);
252 uint8_t
Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks,
const uint8_t *buf);
255 virtual uint8_t
Init(uint8_t parent, uint8_t port,
bool lowspeed);
257 virtual uint8_t
Poll();
274 #endif // __MASSTORAGE_H__