implement serial for MTP

This commit is contained in:
hathach
2025-09-27 17:30:27 +07:00
parent cb21ca1b0c
commit adce3bbac0
3 changed files with 11 additions and 6 deletions

View File

@ -60,6 +60,7 @@ Supports multiple device configurations by dynamically changing USB descriptors,
- Human Interface Device (HID): Generic (In & Out), Keyboard, Mouse, Gamepad etc ...
- Mass Storage Class (MSC): with multiple LUNs
- Musical Instrument Digital Interface (MIDI)
- Media Transfer Protocol (MTP/PTP)
- Network with RNDIS, Ethernet Control Model (ECM), Network Control Model (NCM)
- Test and Measurement Class (USBTMC)
- Video class 1.5 (UVC): work in progress

View File

@ -23,7 +23,9 @@
*
*/
#include "bsp/board_api.h"
#include "tusb.h"
#include "tinyusb_logo_png.h"
//--------------------------------------------------------------------+
@ -68,7 +70,6 @@ storage_info_t storage_info = {
}
};
//--------------------------------------------------------------------+
// MTP FILESYSTEM
//--------------------------------------------------------------------+
@ -80,8 +81,7 @@ storage_info_t storage_info = {
#else
#define FS_MAX_CAPACITY_BYTES (4 * 1024UL)
// object data buffer (excluding 2 predefined files)
// with simple allocation pointer
// object data buffer (excluding 2 predefined files) with simple allocation pointer
uint8_t fs_buf[FS_MAX_CAPACITY_BYTES];
#endif
size_t fs_buf_head = 0;
@ -234,7 +234,11 @@ int32_t tud_mtp_command_received_cb(tud_mtp_cb_data_t* cb_data) {
mtp_container_add_cstring(io_container, DEV_INFO_MANUFACTURER);
mtp_container_add_cstring(io_container, DEV_INFO_MODEL);
mtp_container_add_cstring(io_container, DEV_INFO_VERSION);
mtp_container_add_cstring(io_container, DEV_INFO_SERIAL);
uint16_t serial_utf16[32];
board_usb_get_serial(serial_utf16, 32);
serial_utf16[31] = 0; // ensure null termination
mtp_container_add_string(io_container, serial_utf16);
tud_mtp_data_send(io_container);
break;

View File

@ -768,7 +768,7 @@ TU_VERIFY_STATIC(sizeof(mtp_request_reset_cancel_data_t) == 6, "size is not corr
//--------------------------------------------------------------------+
// return payload buffer for next write
TU_ATTR_ALWAYS_INLINE static inline uint8_t* mtp_container_payload_next(mtp_container_info_t* p_container) {
TU_ATTR_ALWAYS_INLINE static inline uint8_t* mtp_container_payload_ptr(mtp_container_info_t* p_container) {
// only 1st packet include header
uint32_t pos = p_container->header->len - sizeof(mtp_container_header_t);
while (pos > CFG_TUD_MTP_EP_BUFSIZE) {
@ -779,7 +779,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint8_t* mtp_container_payload_next(mtp_cont
// only add_raw does partial copy
TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_raw(mtp_container_info_t* p_container, const void* data, uint32_t len) {
uint8_t* buf = mtp_container_payload_next(p_container);
uint8_t* buf = mtp_container_payload_ptr(p_container);
const uint32_t added_len = tu_min32(len, CFG_TUD_MTP_EP_BUFSIZE - p_container->header->len);
if (added_len > 0) {
memcpy(buf, data, added_len);