usb_host: Add Mock device to CDC tests

pull/11508/head
Tomas Rezucha 2022-02-10 10:57:20 +01:00
rodzic 913d53384f
commit 7d950a63cc
3 zmienionych plików z 53 dodań i 2 usunięć

Wyświetl plik

@ -1,3 +1,3 @@
idf_component_register(SRCS "test_cdc_acm_host.c"
idf_component_register(SRCS "test_cdc_acm_host.c" "usb_device.c"
INCLUDE_DIRS "."
REQUIRES cdc_acm_host unity)
REQUIRES cdc_acm_host tinyusb unity)

Wyświetl plik

@ -373,4 +373,11 @@ TEST_CASE("USB Host CDC-ACM driver: Error handling", "[cdc_acm][ignore]")
vTaskDelay(20);
}
/* Following test case implements dual CDC-ACM USB device that can be used as mock device for CDC-ACM Host tests */
void run_usb_dual_cdc_device(void);
TEST_CASE("USB_CDC_Mock_Device_App", "[cdc_acm_device][ignore]")
{
run_usb_dual_cdc_device();
}
#endif

Wyświetl plik

@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include "sdkconfig.h"
#include "tinyusb.h"
#include "tusb_cdc_acm.h"
static uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE + 1];
void tinyusb_cdc_rx_callback(int itf, cdcacm_event_t *event)
{
size_t rx_size = 0;
/* read and write back */
ESP_ERROR_CHECK(tinyusb_cdcacm_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE, &rx_size));
tinyusb_cdcacm_write_queue(itf, buf, rx_size);
tinyusb_cdcacm_write_flush(itf, 0);
}
void run_usb_dual_cdc_device(void)
{
const tinyusb_config_t tusb_cfg = {}; // the configuration using default values
ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
tinyusb_config_cdcacm_t amc_cfg = {
.usb_dev = TINYUSB_USBDEV_0,
.cdc_port = TINYUSB_CDC_ACM_0,
.rx_unread_buf_sz = 64,
.callback_rx = &tinyusb_cdc_rx_callback, // the first way to register a callback
.callback_rx_wanted_char = NULL,
.callback_line_state_changed = NULL,
.callback_line_coding_changed = NULL
};
ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg));
#if (CONFIG_TINYUSB_CDC_COUNT > 1)
amc_cfg.cdc_port = TINYUSB_CDC_ACM_1;
ESP_ERROR_CHECK(tusb_cdc_acm_init(&amc_cfg));
#endif
printf("USB initialization DONE\n");
}