-
Notifications
You must be signed in to change notification settings - Fork 26
esp_tinyusb: Adding bvalid_signal test #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
idf_component_register(SRCS "test_esp_tinyusb.c" | ||
idf_component_register(SRCS "test_esp_tinyusb.c" "test_bvalid_sig.c" | ||
INCLUDE_DIRS "." | ||
REQUIRES unity esp_tinyusb | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
#include "soc/soc_caps.h" | ||
|
||
#if SOC_USB_OTG_SUPPORTED | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include "esp_system.h" | ||
#include "freertos/FreeRTOS.h" | ||
#include "freertos/task.h" | ||
#include "esp_log.h" | ||
#include "esp_err.h" | ||
#include "driver/gpio.h" | ||
#include "esp_rom_gpio.h" | ||
#include "soc/gpio_sig_map.h" | ||
#include "unity.h" | ||
#include "tinyusb.h" | ||
#include "class/msc/msc_device.h" | ||
|
||
#define DEVICE_DETACH_TEST_ROUNDS 10 | ||
#define DEVICE_DETACH_ROUND_DELAY_MS 1000 | ||
|
||
/* TinyUSB descriptors | ||
********************************************************************* */ | ||
#define TUSB_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN) | ||
|
||
static unsigned int dev_mounted = 0; | ||
static unsigned int dev_umounted = 0; | ||
|
||
static uint8_t const test_configuration_descriptor[] = { | ||
// Config number, interface count, string index, total length, attribute, power in mA | ||
TUD_CONFIG_DESCRIPTOR(1, 0, 0, TUSB_DESC_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_SELF_POWERED | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), | ||
}; | ||
|
||
static const tusb_desc_device_t test_device_descriptor = { | ||
.bLength = sizeof(test_device_descriptor), | ||
.bDescriptorType = TUSB_DESC_DEVICE, | ||
.bcdUSB = 0x0200, | ||
.bDeviceClass = TUSB_CLASS_MISC, | ||
.bDeviceSubClass = MISC_SUBCLASS_COMMON, | ||
.bDeviceProtocol = MISC_PROTOCOL_IAD, | ||
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE, | ||
.idVendor = 0x303A, // This is Espressif VID. This needs to be changed according to Users / Customers | ||
.idProduct = 0x4002, | ||
.bcdDevice = 0x100, | ||
.iManufacturer = 0x01, | ||
.iProduct = 0x02, | ||
.iSerialNumber = 0x03, | ||
.bNumConfigurations = 0x01 | ||
}; | ||
|
||
// Invoked when device is mounted | ||
void tud_mount_cb(void) | ||
{ | ||
dev_mounted++; | ||
} | ||
|
||
// Invoked when device is unmounted | ||
void tud_umount_cb(void) | ||
{ | ||
dev_umounted++; | ||
} | ||
|
||
TEST_CASE("bvalid_signal", "[esp_tinyusb]") | ||
{ | ||
unsigned int rounds = DEVICE_DETACH_TEST_ROUNDS; | ||
|
||
// Install TinyUSB driver | ||
const tinyusb_config_t tusb_cfg = { | ||
.external_phy = false, | ||
.device_descriptor = &test_device_descriptor, | ||
.configuration_descriptor = test_configuration_descriptor, | ||
}; | ||
TEST_ASSERT_EQUAL(ESP_OK, tinyusb_driver_install(&tusb_cfg)); | ||
|
||
while (rounds--) { | ||
// LOW to emulate disconnect USB device | ||
esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ZERO_INPUT, USB_SRP_BVALID_IN_IDX, false); | ||
vTaskDelay(pdMS_TO_TICKS(DEVICE_DETACH_ROUND_DELAY_MS)); | ||
// HIGH to emulate connect USB device | ||
esp_rom_gpio_connect_in_signal(GPIO_MATRIX_CONST_ONE_INPUT, USB_SRP_BVALID_IN_IDX, false); | ||
vTaskDelay(pdMS_TO_TICKS(DEVICE_DETACH_ROUND_DELAY_MS)); | ||
} | ||
|
||
// Verify | ||
TEST_ASSERT_EQUAL(dev_umounted, dev_mounted); | ||
TEST_ASSERT_EQUAL(DEVICE_DETACH_TEST_ROUNDS, dev_mounted); | ||
|
||
tinyusb_driver_uninstall(); | ||
} | ||
#endif // SOC_USB_OTG_SUPPORTED |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.