forked from espressif/esp-idf
Merge branch 'mock/usb_dev_info' into 'master'
mock(usb): Extend USB mock with usb_host_device_info() See merge request espressif/esp-idf!37952
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -289,6 +289,68 @@ esp_err_t usb_host_transfer_submit_invalid_response_mock_callback(usb_transfer_t
|
|||||||
*/
|
*/
|
||||||
esp_err_t usb_host_transfer_submit_timeout_mock_callback(usb_transfer_t *transfer, int call_count);
|
esp_err_t usb_host_transfer_submit_timeout_mock_callback(usb_transfer_t *transfer, int call_count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Submit CTRL transfer, success
|
||||||
|
* @note CMock callback function, registered to usb_host_transfer_submit_control()
|
||||||
|
*
|
||||||
|
* Transfer callback is called, transfer status marked as completed, correct number of transferred bytes
|
||||||
|
*
|
||||||
|
* @param[in] client_hdl Client handle
|
||||||
|
* @param[in] transfer Pointer to USB transfer
|
||||||
|
* @param[out] call_count Call count of the callback function (CMock mandatory argument)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: Transfer submitted
|
||||||
|
* - ESP_ERR_INVALID_ARG: Invalid input argument
|
||||||
|
*/
|
||||||
|
esp_err_t usb_host_transfer_submit_control_success_mock_callback(usb_host_client_handle_t client_hdl, usb_transfer_t *transfer, int call_count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Submit CTRL transfer, error
|
||||||
|
* @note CMock callback function, registered to usb_host_transfer_submit_control()
|
||||||
|
*
|
||||||
|
* Transfer callback is called, transfer status marked as error, incorrect number of transferred bytes
|
||||||
|
*
|
||||||
|
* @param[in] client_hdl Client handle
|
||||||
|
* @param[in] transfer Pointer to USB transfer
|
||||||
|
* @param[out] call_count Call count of the callback function (CMock mandatory argument)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: Transfer submitted
|
||||||
|
* - ESP_ERR_INVALID_ARG: Invalid input argument
|
||||||
|
*/
|
||||||
|
esp_err_t usb_host_transfer_submit_control_invalid_response_mock_callback(usb_host_client_handle_t client_hdl, usb_transfer_t *transfer, int call_count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Submit CTRL transfer, time the transfer out
|
||||||
|
* @note CMock callback function, registered to usb_host_transfer_submit_control()
|
||||||
|
*
|
||||||
|
* Transfer callback is not called, because transfer timeout is not implemented in the USB Host Library
|
||||||
|
*
|
||||||
|
* @param[in] client_hdl Client handle
|
||||||
|
* @param[in] transfer Pointer to USB transfer
|
||||||
|
* @param[out] call_count Call count of the callback function (CMock mandatory argument)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: Transfer submitted
|
||||||
|
* - ESP_ERR_INVALID_ARG: Invalid input argument
|
||||||
|
*/
|
||||||
|
esp_err_t usb_host_transfer_submit_control_timeout_mock_callback(usb_host_client_handle_t client_hdl, usb_transfer_t *transfer, int call_count);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief USB Host device info mock callback
|
||||||
|
* @note CMock callback function registered to usb_host_device_info()
|
||||||
|
*
|
||||||
|
* @param[in] dev_hdl Device handle
|
||||||
|
* @param[out] dev_info Device information
|
||||||
|
* @param[out] call_count Call count of the callback function (CMock mandatory argument)
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK: Device information obtained successfully
|
||||||
|
* - ESP_ERR_INVALID_ARG: Invalid argument
|
||||||
|
*/
|
||||||
|
esp_err_t usb_host_device_info_mock_callback(usb_device_handle_t dev_hdl, usb_device_info_t *dev_info, int call_count);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "usb_private.h"
|
#include "usb_private.h"
|
||||||
#include "usb/usb_types_ch9.h"
|
#include "usb/usb_types_ch9.h"
|
||||||
@@ -374,3 +375,56 @@ esp_err_t usb_host_transfer_submit_timeout_mock_callback(usb_transfer_t *transfe
|
|||||||
MOCK_CHECK((transfer->bEndpointAddress & USB_B_ENDPOINT_ADDRESS_EP_NUM_MASK) != 0, ESP_ERR_INVALID_ARG);
|
MOCK_CHECK((transfer->bEndpointAddress & USB_B_ENDPOINT_ADDRESS_EP_NUM_MASK) != 0, ESP_ERR_INVALID_ARG);
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t usb_host_transfer_submit_control_success_mock_callback(usb_host_client_handle_t client_hdl, usb_transfer_t *transfer, int call_count)
|
||||||
|
{
|
||||||
|
MOCK_CHECK(client_hdl != NULL && transfer != NULL, ESP_ERR_INVALID_ARG);
|
||||||
|
// Check that control transfer is valid
|
||||||
|
MOCK_CHECK(transfer->device_handle != NULL, ESP_ERR_INVALID_ARG); // Target device must be set
|
||||||
|
// Control transfers must be targeted at EP 0
|
||||||
|
MOCK_CHECK((transfer->bEndpointAddress & USB_B_ENDPOINT_ADDRESS_EP_NUM_MASK) == 0, ESP_ERR_INVALID_ARG);
|
||||||
|
|
||||||
|
transfer->status = USB_TRANSFER_STATUS_COMPLETED;
|
||||||
|
transfer->actual_num_bytes = transfer->num_bytes;
|
||||||
|
transfer->callback(transfer);
|
||||||
|
ESP_LOGD(MOCK_TAG_CB, "CTRL mocked transfer submitted, buff len: %d, buff: %s", transfer->num_bytes, transfer->data_buffer);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t usb_host_transfer_submit_control_invalid_response_mock_callback(usb_host_client_handle_t client_hdl, usb_transfer_t *transfer, int call_count)
|
||||||
|
{
|
||||||
|
MOCK_CHECK(client_hdl != NULL && transfer != NULL, ESP_ERR_INVALID_ARG);
|
||||||
|
// Check that control transfer is valid
|
||||||
|
MOCK_CHECK(transfer->device_handle != NULL, ESP_ERR_INVALID_ARG); // Target device must be set
|
||||||
|
// Control transfers must be targeted at EP 0
|
||||||
|
MOCK_CHECK((transfer->bEndpointAddress & USB_B_ENDPOINT_ADDRESS_EP_NUM_MASK) == 0, ESP_ERR_INVALID_ARG);
|
||||||
|
|
||||||
|
transfer->status = USB_TRANSFER_STATUS_ERROR;
|
||||||
|
transfer->actual_num_bytes = 0;
|
||||||
|
transfer->callback(transfer);
|
||||||
|
ESP_LOGD(MOCK_TAG_CB, "CTRL mocked transfer submitted, buff len: %d, buff: %s", transfer->num_bytes, transfer->data_buffer);
|
||||||
|
ESP_LOGW(MOCK_TAG_CB, "CTRL mocked transfer error");
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t usb_host_transfer_submit_control_timeout_mock_callback(usb_host_client_handle_t client_hdl, usb_transfer_t *transfer, int call_count)
|
||||||
|
{
|
||||||
|
MOCK_CHECK(client_hdl != NULL && transfer != NULL, ESP_ERR_INVALID_ARG);
|
||||||
|
// Check that control transfer is valid
|
||||||
|
MOCK_CHECK(transfer->device_handle != NULL, ESP_ERR_INVALID_ARG); // Target device must be set
|
||||||
|
// Control transfers must be targeted at EP 0
|
||||||
|
MOCK_CHECK((transfer->bEndpointAddress & USB_B_ENDPOINT_ADDRESS_EP_NUM_MASK) == 0, ESP_ERR_INVALID_ARG);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t usb_host_device_info_mock_callback(usb_device_handle_t dev_hdl, usb_device_info_t *dev_info, int call_count)
|
||||||
|
{
|
||||||
|
MOCK_CHECK(dev_hdl != NULL && dev_info != NULL, ESP_ERR_INVALID_ARG);
|
||||||
|
|
||||||
|
const device_list_t *current_device = (const device_list_t *) dev_hdl;
|
||||||
|
memset(dev_info, 0, sizeof(usb_device_info_t));
|
||||||
|
dev_info->dev_addr = current_device->address;
|
||||||
|
dev_info->bMaxPacketSize0 = current_device->dev_desc->bMaxPacketSize0;
|
||||||
|
dev_info->bConfigurationValue = 1;
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user