From e4f7fcf7ec4239aff6193a8d71cd0e8ce94024dd Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 26 Sep 2025 10:06:32 +0700 Subject: [PATCH] fix compile warnings --- examples/device/mtp/src/mtp_fs_example.c | 15 +++++++++------ src/class/mtp/mtp.h | 11 ++++------- src/class/mtp/mtp_device.c | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/examples/device/mtp/src/mtp_fs_example.c b/examples/device/mtp/src/mtp_fs_example.c index a06fcb8db..2feb69758 100644 --- a/examples/device/mtp/src/mtp_fs_example.c +++ b/examples/device/mtp/src/mtp_fs_example.c @@ -66,7 +66,7 @@ typedef struct { uint32_t image_bit_depth; uint32_t parent; - uint8_t association_type; + uint16_t association_type; uint32_t size; uint8_t* data; @@ -74,8 +74,9 @@ typedef struct { } fs_file_t; // object data buffer (excluding 2 predefined files) +// with simple allocation pointer uint8_t fs_buf[FS_MAX_CAPACITY_BYTES]; -uint8_t fs_buf_head = 0; // simple allocation pointer +size_t fs_buf_head = 0; // Files system, handle is index + 1 static fs_file_t fs_objects[FS_MAX_FILE_COUNT] = { @@ -88,7 +89,7 @@ static fs_file_t fs_objects[FS_MAX_FILE_COUNT] = { .image_bit_depth = 0, .parent = 0, .association_type = MTP_ASSOCIATION_UNDEFINED, - .data = (uint8_t*) README_TXT_CONTENT, + .data = (uint8_t*) (uintptr_t) README_TXT_CONTENT, .size = sizeof(README_TXT_CONTENT) }, { @@ -100,7 +101,7 @@ static fs_file_t fs_objects[FS_MAX_FILE_COUNT] = { .image_bit_depth = 32, .parent = 0, .association_type = MTP_ASSOCIATION_UNDEFINED, - .data = logo_bin, + .data = (uint8_t*) (uintptr_t) logo_bin, .size = logo_len, } }; @@ -161,6 +162,7 @@ static inline fs_file_t* fs_create_file(void) { return f; } } + return NULL; } // simple malloc @@ -179,7 +181,7 @@ static inline uint8_t* fs_malloc(size_t size) { int32_t tud_mtp_command_received_cb(tud_mtp_cb_data_t* cb_data) { const mtp_container_command_t* command = cb_data->command_container; mtp_container_info_t* io_container = &cb_data->io_container; - uint32_t resp_code = 0; + uint16_t resp_code = 0; switch (command->code) { case MTP_OP_GET_DEVICE_INFO: { // Device info is already prepared up to playback formats. Application only need to add string fields @@ -339,6 +341,7 @@ int32_t tud_mtp_command_received_cb(tud_mtp_cb_data_t* cb_data) { case MTP_OP_SEND_OBJECT_INFO: { const uint32_t storage_id = command->params[0]; const uint32_t parent_handle = command->params[1]; // folder handle, 0xFFFFFFFF is root + (void) parent_handle; if (!is_session_opened) { resp_code = MTP_RESP_SESSION_NOT_OPEN; } else if (storage_id != 0xFFFFFFFF && storage_id != SUPPORTED_STORAGE_ID) { @@ -397,7 +400,7 @@ int32_t tud_mtp_command_received_cb(tud_mtp_cb_data_t* cb_data) { int32_t tud_mtp_data_xfer_cb(tud_mtp_cb_data_t* cb_data) { const mtp_container_command_t* command = cb_data->command_container; mtp_container_info_t* io_container = &cb_data->io_container; - uint32_t resp_code = 0; + uint16_t resp_code = 0; switch (command->code) { case MTP_OP_GET_OBJECT: { // File contents span over multiple xfers diff --git a/src/class/mtp/mtp.h b/src/class/mtp/mtp.h index 15cf1bfc6..073e6c470 100644 --- a/src/class/mtp/mtp.h +++ b/src/class/mtp/mtp.h @@ -675,10 +675,7 @@ TU_VERIFY_STATIC(sizeof(mtp_container_command_t) == 32, "size is not correct"); // PTP/MTP Generic container typedef struct TU_ATTR_PACKED { mtp_container_header_t header; - // union { - uint32_t data[(CFG_TUD_MTP_EP_BUFSIZE - sizeof(mtp_container_header_t)) / sizeof(uint32_t)]; - // uint8_t data[CFG_TUD_MTP_EP_BUFSIZE - sizeof(mtp_container_header_t)]; - // }; + uint8_t payload[(CFG_TUD_MTP_EP_BUFSIZE - sizeof(mtp_container_header_t))]; } mtp_generic_container_t; typedef struct { @@ -823,7 +820,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_string(mtp_contai while (utf16[count]) { count++; } - const uint32_t added_len = 1 + 2 * count; + const uint32_t added_len = 1u + 2u * count; TU_ASSERT(p_container->header->len + added_len < CFG_TUD_MTP_EP_BUFSIZE, 0); uint8_t* buf = p_container->payload + p_container->header->len - sizeof(mtp_container_header_t); @@ -856,7 +853,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_cstring(mtp_conta buf += 2; p_container->header->len += 2; } - return 1 + 2 * len; + return 1u + 2u * len; } } @@ -898,7 +895,7 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_add_auint32(mtp_conta TU_ATTR_ALWAYS_INLINE static inline uint32_t mtp_container_get_string(uint8_t* buf, uint16_t utf16[]) { uint8_t nchars = *buf++; memcpy(utf16, buf, 2 * nchars); - return 1 + nchars * 2; + return 1u + 2u * nchars; } #ifdef __cplusplus diff --git a/src/class/mtp/mtp_device.c b/src/class/mtp/mtp_device.c index 6438fd2d6..61b1c9613 100644 --- a/src/class/mtp/mtp_device.c +++ b/src/class/mtp/mtp_device.c @@ -267,7 +267,7 @@ static bool mtpd_data_xfer(mtp_container_info_t* p_container, uint8_t ep_addr) { TU_ASSERT(p_mtp->phase == MTP_PHASE_DATA); } - const uint16_t xact_len = tu_min32(p_mtp->total_len - p_mtp->xferred_len, CFG_TUD_MTP_EP_BUFSIZE); + const uint16_t xact_len = tu_min16((uint16_t) (p_mtp->total_len - p_mtp->xferred_len), CFG_TUD_MTP_EP_BUFSIZE); if (xact_len) { // already transferred all bytes in header's length. Application make an unnecessary extra call TU_ASSERT(usbd_edpt_xfer(p_mtp->rhport, ep_addr, _mtpd_epbuf.buf, xact_len)); @@ -309,7 +309,7 @@ bool mtpd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t const mtp_container_info_t headered_packet = { .header = &p_container->header, - .payload32 = p_container->data, + .payload = p_container->payload, .payload_bytes = CFG_TUD_MTP_EP_BUFSIZE - sizeof(mtp_container_header_t) };