Austin Schuh | 41baf20 | 2022-01-01 14:33:40 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * The MIT License (MIT) |
| 3 | * |
| 4 | * Copyright (c) 2019 Ha Thach (tinyusb.org) |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | * |
| 24 | * This file is part of the TinyUSB stack. |
| 25 | */ |
| 26 | |
| 27 | #ifndef _TUSB_MSC_HOST_H_ |
| 28 | #define _TUSB_MSC_HOST_H_ |
| 29 | |
| 30 | #include "msc.h" |
| 31 | |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | |
| 36 | //--------------------------------------------------------------------+ |
| 37 | // Class Driver Configuration |
| 38 | //--------------------------------------------------------------------+ |
| 39 | |
| 40 | #ifndef CFG_TUH_MSC_MAXLUN |
| 41 | #define CFG_TUH_MSC_MAXLUN 4 |
| 42 | #endif |
| 43 | |
| 44 | typedef bool (*tuh_msc_complete_cb_t)(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw); |
| 45 | |
| 46 | //--------------------------------------------------------------------+ |
| 47 | // Application API |
| 48 | //--------------------------------------------------------------------+ |
| 49 | |
| 50 | // Check if device supports MassStorage interface. |
| 51 | // This function true after tuh_msc_mounted_cb() and false after tuh_msc_unmounted_cb() |
| 52 | bool tuh_msc_mounted(uint8_t dev_addr); |
| 53 | |
| 54 | // Check if the interface is currently ready or busy transferring data |
| 55 | bool tuh_msc_ready(uint8_t dev_addr); |
| 56 | |
| 57 | // Get Max Lun |
| 58 | uint8_t tuh_msc_get_maxlun(uint8_t dev_addr); |
| 59 | |
| 60 | // Get number of block |
| 61 | uint32_t tuh_msc_get_block_count(uint8_t dev_addr, uint8_t lun); |
| 62 | |
| 63 | // Get block size in bytes |
| 64 | uint32_t tuh_msc_get_block_size(uint8_t dev_addr, uint8_t lun); |
| 65 | |
| 66 | // Perform a full SCSI command (cbw, data, csw) in non-blocking manner. |
| 67 | // Complete callback is invoked when SCSI op is complete. |
| 68 | // return true if success, false if there is already pending operation. |
| 69 | bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb); |
| 70 | |
| 71 | // Perform SCSI Inquiry command |
| 72 | // Complete callback is invoked when SCSI op is complete. |
| 73 | bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb); |
| 74 | |
| 75 | // Perform SCSI Test Unit Ready command |
| 76 | // Complete callback is invoked when SCSI op is complete. |
| 77 | bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb); |
| 78 | |
| 79 | // Perform SCSI Request Sense 10 command |
| 80 | // Complete callback is invoked when SCSI op is complete. |
| 81 | bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *resposne, tuh_msc_complete_cb_t complete_cb); |
| 82 | |
| 83 | // Perform SCSI Read 10 command. Read n blocks starting from LBA to buffer |
| 84 | // Complete callback is invoked when SCSI op is complete. |
| 85 | bool tuh_msc_read10(uint8_t dev_addr, uint8_t lun, void * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb); |
| 86 | |
| 87 | // Perform SCSI Write 10 command. Write n blocks starting from LBA to device |
| 88 | // Complete callback is invoked when SCSI op is complete. |
| 89 | bool tuh_msc_write10(uint8_t dev_addr, uint8_t lun, void const * buffer, uint32_t lba, uint16_t block_count, tuh_msc_complete_cb_t complete_cb); |
| 90 | |
| 91 | // Perform SCSI Read Capacity 10 command |
| 92 | // Complete callback is invoked when SCSI op is complete. |
| 93 | // Note: during enumeration, host stack already carried out this request. Application can retrieve capacity by |
| 94 | // simply call tuh_msc_get_block_count() and tuh_msc_get_block_size() |
| 95 | bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb); |
| 96 | |
| 97 | //------------- Application Callback -------------// |
| 98 | |
| 99 | // Invoked when a device with MassStorage interface is mounted |
| 100 | TU_ATTR_WEAK void tuh_msc_mount_cb(uint8_t dev_addr); |
| 101 | |
| 102 | // Invoked when a device with MassStorage interface is unmounted |
| 103 | TU_ATTR_WEAK void tuh_msc_umount_cb(uint8_t dev_addr); |
| 104 | |
| 105 | //--------------------------------------------------------------------+ |
| 106 | // Internal Class Driver API |
| 107 | //--------------------------------------------------------------------+ |
| 108 | |
| 109 | void msch_init (void); |
| 110 | bool msch_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len); |
| 111 | bool msch_set_config (uint8_t dev_addr, uint8_t itf_num); |
| 112 | void msch_close (uint8_t dev_addr); |
| 113 | bool msch_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); |
| 114 | |
| 115 | #ifdef __cplusplus |
| 116 | } |
| 117 | #endif |
| 118 | |
| 119 | #endif /* _TUSB_MSC_HOST_H_ */ |