summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-09-27 16:15:04 +0700
committerhathach <[email protected]>2025-09-27 17:08:21 +0700
commitcb21ca1b0cb3221341dca2559109c0bb4dc18e6f (patch)
treeaba4e31d802be53361d16c94150bf4fe110dbb0f /examples
parentf9d4bc798177e63532cd5a2ef058400d6f0ef5e4 (diff)
implement control request
Diffstat (limited to 'examples')
-rw-r--r--examples/device/mtp/src/mtp_fs_example.c41
-rw-r--r--examples/device/mtp/src/tusb_config.h5
-rw-r--r--examples/device/mtp/src/usb_descriptors.c10
3 files changed, 41 insertions, 15 deletions
diff --git a/examples/device/mtp/src/mtp_fs_example.c b/examples/device/mtp/src/mtp_fs_example.c
index a13acfcdd..9d90f7663 100644
--- a/examples/device/mtp/src/mtp_fs_example.c
+++ b/examples/device/mtp/src/mtp_fs_example.c
@@ -23,7 +23,6 @@
*
*/
-#include "class/mtp/mtp_device_storage.h"
#include "tusb.h"
#include "tinyusb_logo_png.h"
@@ -189,6 +188,40 @@ static inline uint8_t* fs_malloc(size_t size) {
}
//--------------------------------------------------------------------+
+// 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
//--------------------------------------------------------------------+
int32_t tud_mtp_command_received_cb(tud_mtp_cb_data_t* cb_data) {
@@ -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) {
-}
diff --git a/examples/device/mtp/src/tusb_config.h b/examples/device/mtp/src/tusb_config.h
index 62a5729bf..4d166aa63 100644
--- a/examples/device/mtp/src/tusb_config.h
+++ b/examples/device/mtp/src/tusb_config.h
@@ -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
diff --git a/examples/device/mtp/src/usb_descriptors.c b/examples/device/mtp/src/usb_descriptors.c
index 4a43a0dcc..810137c46 100644
--- a/examples/device/mtp/src/usb_descriptors.c
+++ b/examples/device/mtp/src/usb_descriptors.c
@@ -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];