diff options
| author | hathach <[email protected]> | 2025-09-27 18:43:46 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2025-09-27 18:43:46 +0700 |
| commit | a09c65c4e4860d215648a3fc2d5f768f292e0e01 (patch) | |
| tree | aa1c8786f332096895daddf7d201d43930647f2a | |
| parent | bc688ccbad78053ee47306307a91e8f2d9d51e38 (diff) | |
make command container more consistent
| -rw-r--r-- | examples/device/mtp/src/mtp_fs_example.c | 6 | ||||
| -rw-r--r-- | src/class/mtp/mtp.h | 5 | ||||
| -rw-r--r-- | src/class/mtp/mtp_device.c | 10 | ||||
| -rw-r--r-- | tools/iar_template.ipcf | 1 |
4 files changed, 9 insertions, 13 deletions
diff --git a/examples/device/mtp/src/mtp_fs_example.c b/examples/device/mtp/src/mtp_fs_example.c index 72fff5402..5b582e7db 100644 --- a/examples/device/mtp/src/mtp_fs_example.c +++ b/examples/device/mtp/src/mtp_fs_example.c @@ -228,7 +228,7 @@ 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; uint16_t resp_code = 0; - switch (command->code) { + switch (command->header.code) { case MTP_OP_GET_DEVICE_INFO: { // Device info is already prepared up to playback formats. Application only need to add string fields mtp_container_add_cstring(io_container, DEV_INFO_MANUFACTURER); @@ -452,7 +452,7 @@ 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; uint16_t resp_code = 0; - switch (command->code) { + switch (command->header.code) { case MTP_OP_GET_OBJECT: { // File contents span over multiple xfers const uint32_t obj_handle = command->params[0]; @@ -540,7 +540,7 @@ int32_t tud_mtp_data_xfer_cb(tud_mtp_cb_data_t* cb_data) { int32_t tud_mtp_data_complete_cb(tud_mtp_cb_data_t* cb_data) { const mtp_container_command_t* command = cb_data->command_container; mtp_container_info_t* resp = &cb_data->io_container; - switch (command->code) { + switch (command->header.code) { case MTP_OP_SEND_OBJECT_INFO: { fs_file_t* f = fs_get_file(send_obj_handle); if (f == NULL) { diff --git a/src/class/mtp/mtp.h b/src/class/mtp/mtp.h index a8123b380..84fd1b429 100644 --- a/src/class/mtp/mtp.h +++ b/src/class/mtp/mtp.h @@ -649,10 +649,7 @@ typedef struct TU_ATTR_PACKED { TU_VERIFY_STATIC(sizeof(mtp_container_header_t) == 12, "size is not correct"); typedef struct TU_ATTR_PACKED { - uint32_t len; - uint16_t type; - uint16_t code; - uint32_t transaction_id; + mtp_container_header_t header; uint32_t params[5]; } mtp_container_command_t; TU_VERIFY_STATIC(sizeof(mtp_container_command_t) == 32, "size is not correct"); diff --git a/src/class/mtp/mtp_device.c b/src/class/mtp/mtp_device.c index 86d18a942..f3f594dcf 100644 --- a/src/class/mtp/mtp_device.c +++ b/src/class/mtp/mtp_device.c @@ -204,7 +204,7 @@ static bool mtpd_data_xfer(mtp_container_info_t* p_container, uint8_t ep_addr) { if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN) { p_mtp->total_len = p_container->header->len; p_container->header->type = MTP_CONTAINER_TYPE_DATA_BLOCK; - p_container->header->transaction_id = p_mtp->command.transaction_id; + p_container->header->transaction_id = p_mtp->command.header.transaction_id; p_mtp->io_header = *p_container->header; // save header for subsequent data } else { // OUT transfer: total length is at least max packet size @@ -236,7 +236,7 @@ bool tud_mtp_response_send(mtp_container_info_t* p_container) { mtpd_interface_t* p_mtp = &_mtpd_itf; p_mtp->phase = MTP_PHASE_RESPONSE; p_container->header->type = MTP_CONTAINER_TYPE_RESPONSE_BLOCK; - p_container->header->transaction_id = p_mtp->command.transaction_id; + p_container->header->transaction_id = p_mtp->command.header.transaction_id; TU_VERIFY(usbd_edpt_claim(p_mtp->rhport, p_mtp->ep_in)); return usbd_edpt_xfer(p_mtp->rhport, p_mtp->ep_in, _mtpd_epbuf.buf, (uint16_t)p_container->header->len); } @@ -376,8 +376,8 @@ bool mtpd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t mtp_generic_container_t* p_container = (mtp_generic_container_t*) _mtpd_epbuf.buf; #if CFG_TUSB_DEBUG >= CFG_TUD_MTP_LOG_LEVEL - tu_lookup_find(&_mtp_op_table, p_mtp->command.code); - TU_LOG_DRV(" MTP %s: %s phase\r\n", (const char *) tu_lookup_find(&_mtp_op_table, p_mtp->command.code), + tu_lookup_find(&_mtp_op_table, p_mtp->command.header.code); + TU_LOG_DRV(" MTP %s: %s phase\r\n", (const char *) tu_lookup_find(&_mtp_op_table, p_mtp->command.header.code), _mtp_phase_str[p_mtp->phase]); #endif @@ -488,7 +488,7 @@ bool mtpd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t // pre-processed commands void preprocess_cmd(mtpd_interface_t* p_mtp, tud_mtp_cb_data_t* cb_data) { - switch (p_mtp->command.code) { + switch (p_mtp->command.header.code) { case MTP_OP_GET_DEVICE_INFO: { tud_mtp_device_info_t dev_info = { .standard_version = 100, diff --git a/tools/iar_template.ipcf b/tools/iar_template.ipcf index c93795b9c..2581a4702 100644 --- a/tools/iar_template.ipcf +++ b/tools/iar_template.ipcf @@ -62,7 +62,6 @@ <path>$TUSB_DIR$/src/class/mtp/mtp_device.c</path> <path>$TUSB_DIR$/src/class/mtp/mtp.h</path> <path>$TUSB_DIR$/src/class/mtp/mtp_device.h</path> - <path>$TUSB_DIR$/src/class/mtp/mtp_device_storage.h</path> </group> <group name="src/class/net"> <path>$TUSB_DIR$/src/class/net/ecm_rndis_device.c</path> |
