2019-03-20 16:11:42 +07:00
|
|
|
/*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018, hathach (tinyusb.org)
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* This file is part of the TinyUSB stack.
|
|
|
|
*/
|
2013-11-01 12:11:26 +07:00
|
|
|
|
|
|
|
#ifndef _TUSB_MSC_DEVICE_H_
|
|
|
|
#define _TUSB_MSC_DEVICE_H_
|
|
|
|
|
2018-04-18 17:12:58 +07:00
|
|
|
#include "common/tusb_common.h"
|
2013-11-01 12:11:26 +07:00
|
|
|
#include "device/usbd.h"
|
|
|
|
#include "msc.h"
|
|
|
|
|
2019-04-11 00:20:54 +07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2018-07-17 16:04:55 +07:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Class Driver Configuration
|
|
|
|
//--------------------------------------------------------------------+
|
2018-08-13 18:10:23 +07:00
|
|
|
TU_VERIFY_STATIC(CFG_TUD_MSC_BUFSIZE < UINT16_MAX, "Size is not correct");
|
2018-07-17 16:04:55 +07:00
|
|
|
|
|
|
|
#ifndef CFG_TUD_MSC_BUFSIZE
|
2019-04-17 13:43:07 +07:00
|
|
|
#error CFG_TUD_MSC_BUFSIZE must be defined, value of a block size should work well, the more the better
|
2018-07-17 16:04:55 +07:00
|
|
|
#endif
|
|
|
|
|
2013-11-22 15:16:24 +07:00
|
|
|
/** \addtogroup ClassDriver_MSC
|
|
|
|
* @{
|
|
|
|
* \defgroup MSC_Device Device
|
2014-03-31 11:59:43 +07:00
|
|
|
* @{ */
|
2013-11-22 15:16:24 +07:00
|
|
|
|
2018-07-26 15:59:13 +07:00
|
|
|
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier);
|
2018-07-25 12:24:16 +07:00
|
|
|
|
2013-11-21 12:47:55 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2019-05-01 23:26:52 +07:00
|
|
|
// Application Callbacks (WEAK is optional)
|
2013-11-21 12:47:55 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2019-05-01 23:26:52 +07:00
|
|
|
|
2018-07-26 22:41:46 +07:00
|
|
|
/**
|
2019-05-01 23:26:52 +07:00
|
|
|
* Invoked when received \ref SCSI_CMD_READ_10 command
|
2018-07-27 17:14:49 +07:00
|
|
|
* \param[in] lun Logical unit number
|
|
|
|
* \param[in] lba Logical Block Address to be read
|
|
|
|
* \param[in] offset Byte offset from LBA
|
|
|
|
* \param[out] buffer Buffer which application need to update with the response data.
|
2018-07-26 22:41:46 +07:00
|
|
|
* \param[in] bufsize Requested bytes
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2018-07-26 22:41:46 +07:00
|
|
|
* \return Number of byte read, if it is less than requested bytes by \a \b bufsize. Tinyusb will transfer
|
|
|
|
* this amount first and invoked this again for remaining data.
|
2018-04-20 20:23:22 +07:00
|
|
|
*
|
|
|
|
* \retval zero Indicate application is not ready yet to response e.g disk I/O is not complete.
|
2018-07-26 22:41:46 +07:00
|
|
|
* tinyusb will invoke this callback with the same parameters again some time later.
|
2018-04-20 20:23:22 +07:00
|
|
|
*
|
2018-07-26 22:41:46 +07:00
|
|
|
* \retval negative Indicate error e.g reading disk I/O. tinyusb will \b STALL the corresponding
|
2013-12-01 12:18:26 +07:00
|
|
|
* endpoint and return failed status in command status wrapper phase.
|
|
|
|
*/
|
2018-07-25 20:34:56 +07:00
|
|
|
int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
|
2013-12-01 12:18:26 +07:00
|
|
|
|
2018-07-26 22:41:46 +07:00
|
|
|
/**
|
2019-05-01 23:26:52 +07:00
|
|
|
* Invoked when received \ref SCSI_CMD_WRITE_10 command
|
2018-07-27 17:14:49 +07:00
|
|
|
* \param[in] lun Logical unit number
|
|
|
|
* \param[in] lba Logical Block Address to be write
|
|
|
|
* \param[in] offset Byte offset from LBA
|
|
|
|
* \param[out] buffer Buffer which holds written data.
|
2018-07-26 22:41:46 +07:00
|
|
|
* \param[in] bufsize Requested bytes
|
2018-04-20 20:23:22 +07:00
|
|
|
*
|
2018-07-26 22:41:46 +07:00
|
|
|
* \return Number of byte written, if it is less than requested bytes by \a \b bufsize. Tinyusb will proceed with
|
|
|
|
* other work and invoked this again with adjusted parameters.
|
2018-04-20 20:23:22 +07:00
|
|
|
*
|
|
|
|
* \retval zero Indicate application is not ready yet e.g disk I/O is not complete.
|
2018-07-26 22:41:46 +07:00
|
|
|
* Tinyusb will invoke this callback with the same parameters again some time later.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2018-04-20 20:23:22 +07:00
|
|
|
* \retval negative Indicate error writing disk I/O. Tinyusb will \b STALL the corresponding
|
2013-12-01 12:18:26 +07:00
|
|
|
* endpoint and return failed status in command status wrapper phase.
|
|
|
|
*/
|
2018-10-24 23:55:10 -07:00
|
|
|
int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
|
2018-04-18 16:55:44 +07:00
|
|
|
|
2019-05-03 23:46:01 +07:00
|
|
|
// Invoked when received SCSI_CMD_INQUIRY
|
|
|
|
// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
|
|
|
|
void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]);
|
|
|
|
|
2019-05-01 23:26:52 +07:00
|
|
|
// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
|
|
|
|
// Application update block count and block size
|
2018-11-22 12:11:06 +07:00
|
|
|
void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
|
|
|
|
|
2018-07-26 22:41:46 +07:00
|
|
|
/**
|
|
|
|
* Callback invoked when received an SCSI command not in built-in list below.
|
2018-07-27 17:14:49 +07:00
|
|
|
* \param[in] lun Logical unit number
|
|
|
|
* \param[in] scsi_cmd SCSI command contents which application must examine to response accordingly
|
2018-04-20 20:23:22 +07:00
|
|
|
* \param[out] buffer Buffer for SCSI Data Stage.
|
|
|
|
* - For INPUT: application must fill this with response.
|
|
|
|
* - For OUTPUT it holds the Data from host
|
|
|
|
* \param[in] bufsize Buffer's length.
|
2018-04-18 16:55:44 +07:00
|
|
|
*
|
2018-07-26 22:41:46 +07:00
|
|
|
* \return Actual bytes processed, can be zero for no-data command.
|
|
|
|
* \retval negative Indicate error e.g unsupported command, tinyusb will \b STALL the corresponding
|
2018-04-20 20:23:22 +07:00
|
|
|
* endpoint and return failed status in command status wrapper phase.
|
2018-07-26 22:41:46 +07:00
|
|
|
*
|
|
|
|
* \note Following command is automatically handled by tinyusb stack, callback should not be worried:
|
|
|
|
* - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
|
|
|
|
* - READ10 and WRITE10 has their own callbacks
|
2013-12-01 12:18:26 +07:00
|
|
|
*/
|
2018-07-25 20:34:56 +07:00
|
|
|
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
|
2013-11-30 22:29:37 +07:00
|
|
|
|
2019-04-18 22:31:35 +07:00
|
|
|
/*------------- Optional callbacks -------------*/
|
2018-11-22 12:11:06 +07:00
|
|
|
|
2019-05-01 23:26:52 +07:00
|
|
|
// Invoked when received GET_MAX_LUN request
|
2019-04-26 15:54:42 +07:00
|
|
|
ATTR_WEAK uint8_t tud_msc_maxlun_cb(void);
|
|
|
|
|
2018-11-22 12:11:06 +07:00
|
|
|
// Invoked when Read10 command is complete
|
2018-07-25 20:34:56 +07:00
|
|
|
ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
|
2018-11-22 12:11:06 +07:00
|
|
|
|
2019-05-01 23:26:52 +07:00
|
|
|
// Invoke when Write10 command is complete, can be used to flush flash caching
|
2018-07-25 20:34:56 +07:00
|
|
|
ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
|
2018-11-22 12:11:06 +07:00
|
|
|
|
|
|
|
// Invoked when command in tud_msc_scsi_cb is complete
|
2018-07-25 20:34:56 +07:00
|
|
|
ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]);
|
2018-04-18 17:12:58 +07:00
|
|
|
|
2018-11-22 12:11:06 +07:00
|
|
|
// Hook to make a mass storage device read-only. TODO remove
|
2018-10-24 23:55:10 -07:00
|
|
|
ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);
|
|
|
|
|
2013-11-22 15:16:24 +07:00
|
|
|
/** @} */
|
|
|
|
/** @} */
|
|
|
|
|
2013-11-01 12:11:26 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2019-03-27 17:48:42 +07:00
|
|
|
// Internal Class Driver API
|
2013-11-01 12:11:26 +07:00
|
|
|
//--------------------------------------------------------------------+
|
2013-11-13 12:40:11 +07:00
|
|
|
void mscd_init(void);
|
2018-12-12 13:00:59 +07:00
|
|
|
bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length);
|
2018-11-16 21:56:39 +07:00
|
|
|
bool mscd_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
|
|
|
|
bool mscd_control_request_complete (uint8_t rhport, tusb_control_request_t const * p_request);
|
2018-12-12 13:12:06 +07:00
|
|
|
bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
|
2018-07-13 16:09:26 +07:00
|
|
|
void mscd_reset(uint8_t rhport);
|
2013-11-01 12:11:26 +07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _TUSB_MSC_DEVICE_H_ */
|