implement control request

This commit is contained in:
hathach
2025-09-27 16:15:04 +07:00
parent f9d4bc7981
commit cb21ca1b0c
7 changed files with 169 additions and 157 deletions

View File

@ -23,7 +23,6 @@
*
*/
#include "class/mtp/mtp_device_storage.h"
#include "tusb.h"
#include "tinyusb_logo_png.h"
@ -188,6 +187,40 @@ static inline uint8_t* fs_malloc(size_t size) {
#endif
}
//--------------------------------------------------------------------+
// Control Request callback
//--------------------------------------------------------------------+
bool tud_mtp_request_cancel_cb(tud_mtp_request_cb_data_t* cb_data) {
mtp_request_reset_cancel_data_t cancel_data;
memcpy(&cancel_data, cb_data->buf, sizeof(cancel_data));
(void) cancel_data.code;
(void ) cancel_data.transaction_id;
return true;
}
// Invoked when received Device Reset request
// return false to stall the request
bool tud_mtp_request_device_reset_cb(tud_mtp_request_cb_data_t* cb_data) {
(void) cb_data;
return true;
}
// Invoked when received Get Extended Event request. Application fill callback data's buffer for response
// return negative to stall the request
int32_t tud_mtp_request_get_extended_event_cb(tud_mtp_request_cb_data_t* cb_data) {
(void) cb_data;
return false; // not implemented yet
}
// Invoked when received Get DeviceStatus request. Application fill callback data's buffer for response
// return negative to stall the request
int32_t tud_mtp_request_get_device_status_cb(tud_mtp_request_cb_data_t* cb_data) {
uint16_t* buf16 = (uint16_t*)(uintptr_t) cb_data->buf;
buf16[0] = 4; // length
buf16[1] = MTP_RESP_OK; // status
return 4;
}
//--------------------------------------------------------------------+
// Bulk Only Protocol
//--------------------------------------------------------------------+
@ -531,9 +564,3 @@ int32_t tud_mtp_response_complete_cb(tud_mtp_cb_data_t* cb_data) {
(void) cb_data;
return 0; // nothing to do
}
void tud_mtp_storage_cancel(void) {
}
void tud_mtp_storage_reset(void) {
}

View File

@ -93,6 +93,7 @@
//------------- CLASS -------------//
#define CFG_TUD_MTP 1
#define CFG_TUD_MTP_EP_BUFSIZE 512
#define CFG_TUD_MTP_EP_CONTROL_BUFSIZE 16 // should be enough to hold data in MTP control request
//------------- MTP device info -------------//
#define CFG_TUD_MTP_DEVICEINFO_EXTENSIONS "microsoft.com: 1.0; "
@ -131,10 +132,6 @@
MTP_OBJ_FORMAT_TEXT, \
MTP_OBJ_FORMAT_PNG
#define CFG_TUD_MANUFACTURER "TinyUsb Manufacturer"
#define CFG_TUD_MODEL "TinyUsb Device"
#define CFG_MTP_INTERFACE (CFG_TUD_MODEL " MTP")
#ifdef __cplusplus
}
#endif

View File

@ -140,10 +140,10 @@ enum {
char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
CFG_TUD_MANUFACTURER, // 1: Manufacturer
CFG_TUD_MODEL, // 2: Product
"TinyUsb", // 1: Manufacturer
"TinyUsb Device", // 2: Product
NULL, // 3: Serials will use unique ID if possible
CFG_MTP_INTERFACE, // 4: MTP Interface
"TinyUSBB MTP", // 4: MTP Interface
};
static uint16_t _desc_str[32 + 1];
@ -168,7 +168,9 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) {
return NULL;
}
const char *str = string_desc_arr[index];