Open FFBoard
Open source force feedback firmware
msc_device.h
Go to the documentation of this file.
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_DEVICE_H_
28#define _TUSB_MSC_DEVICE_H_
29
30#include "common/tusb_common.h"
31#include "msc.h"
32
33#ifdef __cplusplus
34 extern "C" {
35#endif
36
37//--------------------------------------------------------------------+
38// Class Driver Configuration
39//--------------------------------------------------------------------+
40
41#if !defined(CFG_TUD_MSC_EP_BUFSIZE) & defined(CFG_TUD_MSC_BUFSIZE)
42 // TODO warn user to use new name later on
43 // #warning CFG_TUD_MSC_BUFSIZE is renamed to CFG_TUD_MSC_EP_BUFSIZE, please update to use the new name
44 #define CFG_TUD_MSC_EP_BUFSIZE CFG_TUD_MSC_BUFSIZE
45#endif
46
47#ifndef CFG_TUD_MSC_EP_BUFSIZE
48 #error CFG_TUD_MSC_EP_BUFSIZE must be defined, value of a block size should work well, the more the better
49#endif
50
51TU_VERIFY_STATIC(CFG_TUD_MSC_EP_BUFSIZE < UINT16_MAX, "Size is not correct");
52
53//--------------------------------------------------------------------+
54// Application API
55//--------------------------------------------------------------------+
56
57// Set SCSI sense response
58bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier);
59
60//--------------------------------------------------------------------+
61// Application Callbacks (WEAK is optional)
62//--------------------------------------------------------------------+
63
64// Invoked when received SCSI READ10 command
65// - Address = lba * BLOCK_SIZE + offset
66// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
67//
68// - Application fill the buffer (up to bufsize) with address contents and return number of read byte. If
69// - read < bufsize : These bytes are transferred first and callback invoked again for remaining data.
70//
71// - read == 0 : Indicate application is not ready yet e.g disk I/O busy.
72// Callback invoked again with the same parameters later on.
73//
74// - read < 0 : Indicate application error e.g invalid address. This request will be STALLed
75// and return failed status in command status wrapper phase.
76int32_t tud_msc_read10_cb (uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize);
77
78// Invoked when received SCSI WRITE10 command
79// - Address = lba * BLOCK_SIZE + offset
80// - offset is only needed if CFG_TUD_MSC_EP_BUFSIZE is smaller than BLOCK_SIZE.
81//
82// - Application write data from buffer to address contents (up to bufsize) and return number of written byte. If
83// - write < bufsize : callback invoked again with remaining data later on.
84//
85// - write == 0 : Indicate application is not ready yet e.g disk I/O busy.
86// Callback invoked again with the same parameters later on.
87//
88// - write < 0 : Indicate application error e.g invalid address. This request will be STALLed
89// and return failed status in command status wrapper phase.
90//
91// TODO change buffer to const uint8_t*
92int32_t tud_msc_write10_cb (uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize);
93
94// Invoked when received SCSI_CMD_INQUIRY
95// Application fill vendor id, product id and revision with string up to 8, 16, 4 characters respectively
96void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4]);
97
98// Invoked when received Test Unit Ready command.
99// return true allowing host to read/write this LUN e.g SD card inserted
101
102// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
103// Application update block count and block size
104void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_size);
105
122int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize);
123
124/*------------- Optional callbacks -------------*/
125
126// Invoked when received GET_MAX_LUN request, required for multiple LUNs implementation
127TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void);
128
129// Invoked when received Start Stop Unit command
130// - Start = 0 : stopped power mode, if load_eject = 1 : unload disk storage
131// - Start = 1 : active mode, if load_eject = 1 : load disk storage
132TU_ATTR_WEAK bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject);
133
134//Invoked when we receive the Prevent / Allow Medium Removal command
135TU_ATTR_WEAK bool tud_msc_prevent_allow_medium_removal_cb(uint8_t lun, uint8_t prohibit_removal, uint8_t control);
136
137// Invoked when received REQUEST_SENSE
138TU_ATTR_WEAK int32_t tud_msc_request_sense_cb(uint8_t lun, void* buffer, uint16_t bufsize);
139
140// Invoked when Read10 command is complete
141TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun);
142
143// Invoke when Write10 command is complete, can be used to flush flash caching
144TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun);
145
146// Invoked when command in tud_msc_scsi_cb is complete
147TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]);
148
149// Invoked to check if device is writable as part of SCSI WRITE10
150TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun);
151
152//--------------------------------------------------------------------+
153// Internal Class Driver API
154//--------------------------------------------------------------------+
155void mscd_init (void);
156bool mscd_deinit (void);
157void mscd_reset (uint8_t rhport);
158uint16_t mscd_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
159bool mscd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * p_request);
160bool mscd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
161
162#ifdef __cplusplus
163 }
164#endif
165
166#endif /* _TUSB_MSC_DEVICE_H_ */
TU_VERIFY_STATIC(sizeof(cdc_acm_capability_t)==1, "mostly problem with compiler")
uint8_t const * buffer
Definition: midi_device.h:100
uint32_t bufsize
Definition: midi_device.h:95
bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes)
Definition: msc_device.c:393
int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize)
void mscd_reset(uint8_t rhport)
Definition: msc_device.c:263
int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize)
bool tud_msc_set_sense(uint8_t lun, uint8_t sense_key, uint8_t add_sense_code, uint8_t add_sense_qualifier)
Definition: msc_device.c:234
TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun)
TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun)
bool mscd_deinit(void)
Definition: msc_device.c:258
TU_ATTR_WEAK int32_t tud_msc_request_sense_cb(uint8_t lun, void *buffer, uint16_t bufsize)
uint16_t mscd_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
Definition: msc_device.c:269
int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize)
TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun)
TU_ATTR_WEAK bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject)
void mscd_init(void)
Definition: msc_device.c:254
TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void)
bool tud_msc_test_unit_ready_cb(uint8_t lun)
void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size)
TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16])
bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const *p_request)
Definition: msc_device.c:308
void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16], uint8_t product_rev[4])
TU_ATTR_WEAK bool tud_msc_prevent_allow_medium_removal_cb(uint8_t lun, uint8_t prohibit_removal, uint8_t control)
AUDIO Channel Cluster Descriptor (4.1)
Definition: audio.h:647
xfer_result_t
Definition: tusb_types.h:236
volatile uint8_t stage
Definition: usbh.c:265