mikroSDK Reference Manual
msc_host.h
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
44typedef struct {
45 msc_cbw_t const* cbw; // SCSI command
46 msc_csw_t const* csw; // SCSI status
47 void* scsi_data; // SCSI Data
48 uintptr_t user_arg; // user argument
50
51typedef bool (*tuh_msc_complete_cb_t)(uint8_t dev_addr, tuh_msc_complete_data_t const* cb_data);
52
53//--------------------------------------------------------------------+
54// Application API
55//--------------------------------------------------------------------+
56
57// Check if device supports MassStorage interface.
58// This function true after tuh_msc_mounted_cb() and false after tuh_msc_unmounted_cb()
59bool tuh_msc_mounted(uint8_t dev_addr);
60
61// Check if the interface is currently ready or busy transferring data
62bool tuh_msc_ready(uint8_t dev_addr);
63
64// Get Max Lun
65uint8_t tuh_msc_get_maxlun(uint8_t dev_addr);
66
67// Get number of block
68uint32_t tuh_msc_get_block_count(uint8_t dev_addr, uint8_t lun);
69
70// Get block size in bytes
71uint32_t tuh_msc_get_block_size(uint8_t dev_addr, uint8_t lun);
72
73// Perform a full SCSI command (cbw, data, csw) in non-blocking manner.
74// Complete callback is invoked when SCSI op is complete.
75// return true if success, false if there is already pending operation.
76bool tuh_msc_scsi_command(uint8_t dev_addr, msc_cbw_t const* cbw, void* data, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
77
78// Perform SCSI Inquiry command
79// Complete callback is invoked when SCSI op is complete.
80bool tuh_msc_inquiry(uint8_t dev_addr, uint8_t lun, scsi_inquiry_resp_t* response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
81
82// Perform SCSI Test Unit Ready command
83// Complete callback is invoked when SCSI op is complete.
84bool tuh_msc_test_unit_ready(uint8_t dev_addr, uint8_t lun, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
85
86// Perform SCSI Request Sense 10 command
87// Complete callback is invoked when SCSI op is complete.
88bool tuh_msc_request_sense(uint8_t dev_addr, uint8_t lun, void *response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
89
90// Perform SCSI Read 10 command. Read n blocks starting from LBA to buffer
91// Complete callback is invoked when SCSI op is complete.
92bool 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, uintptr_t arg);
93
94// Perform SCSI Write 10 command. Write n blocks starting from LBA to device
95// Complete callback is invoked when SCSI op is complete.
96bool 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, uintptr_t arg);
97
98// Perform SCSI Read Capacity 10 command
99// Complete callback is invoked when SCSI op is complete.
100// Note: during enumeration, host stack already carried out this request. Application can retrieve capacity by
101// simply call tuh_msc_get_block_count() and tuh_msc_get_block_size()
102bool tuh_msc_read_capacity(uint8_t dev_addr, uint8_t lun, scsi_read_capacity10_resp_t* response, tuh_msc_complete_cb_t complete_cb, uintptr_t arg);
103
104//------------- Application Callback -------------//
105
106// Invoked when a device with MassStorage interface is mounted
107TU_ATTR_WEAK void tuh_msc_mount_cb(uint8_t dev_addr);
108
109// Invoked when a device with MassStorage interface is unmounted
110TU_ATTR_WEAK void tuh_msc_umount_cb(uint8_t dev_addr);
111
112//--------------------------------------------------------------------+
113// Internal Class Driver API
114//--------------------------------------------------------------------+
115
116void msch_init (void);
117bool msch_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
118bool msch_set_config (uint8_t dev_addr, uint8_t itf_num);
119void msch_close (uint8_t dev_addr);
120bool msch_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
121
122#ifdef __cplusplus
123 }
124#endif
125
126#endif /* _TUSB_MSC_HOST_H_ */
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
SCSI Read Capacity 10 Response Data.
Definition msc.h:357
Definition msc_host.h:44