forked from hathach/tinyusb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hathach#2328 from HiFiPhile/rx_fb
UAC2: Implement feedback by fifo counting.
- Loading branch information
Showing
17 changed files
with
1,868 additions
and
284 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,33 @@ | ||
cmake_minimum_required(VERSION 3.17) | ||
|
||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) | ||
|
||
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>) | ||
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
project(${PROJECT} C CXX ASM) | ||
|
||
# Checks this example is valid for the family and initializes the project | ||
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Espressif has its own cmake build system | ||
if(FAMILY STREQUAL "espressif") | ||
return() | ||
endif() | ||
|
||
add_executable(${PROJECT}) | ||
|
||
# Example source | ||
target_sources(${PROJECT} PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c | ||
) | ||
|
||
# Example include | ||
target_include_directories(${PROJECT} PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/src | ||
) | ||
|
||
# Configure compilation flags and libraries for the example without RTOS. | ||
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details. | ||
family_configure_device_example(${PROJECT} noos) |
This file contains 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,11 @@ | ||
include ../../build_system/make/make.mk | ||
|
||
INC += \ | ||
src \ | ||
$(TOP)/hw \ | ||
|
||
# Example source | ||
EXAMPLE_SOURCE += $(wildcard src/*.c) | ||
SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) | ||
|
||
include ../../build_system/make/rules.mk |
This file contains 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,8 @@ | ||
mcu:LPC11UXX | ||
mcu:LPC13XX | ||
mcu:NUC121 | ||
mcu:SAMD11 | ||
mcu:SAME5X | ||
mcu:SAMG | ||
board:stm32l052dap52 | ||
family:broadcom_64bit |
This file contains 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,69 @@ | ||
# Install python3 HID package https://pypi.org/project/hid/ | ||
# Install python3 matplotlib package https://pypi.org/project/matplotlib/ | ||
|
||
from ctypes import * | ||
try: | ||
import hid | ||
import matplotlib.pyplot as plt | ||
import matplotlib.animation as animation | ||
except: | ||
print("Missing import, please try 'pip install hid matplotlib' or consult your OS's python package manager.") | ||
|
||
# Example must be compiled with CFG_AUDIO_DEBUG=1 | ||
VID = 0xcafe | ||
PID = 0x4014 | ||
|
||
CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX = 2 | ||
|
||
class audio_debug_info_t (Structure): | ||
_fields_ = [("sample_rate", c_uint32), | ||
("alt_settings", c_uint8), | ||
("mute", (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1) * c_int8), | ||
("volume", (CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1) * c_int16), | ||
("fifo_size", c_uint16), | ||
("fifo_count", c_uint16), | ||
("fifo_count_avg", c_uint16) | ||
] | ||
|
||
dev = hid.Device(VID, PID) | ||
|
||
if dev: | ||
# Create figure for plotting | ||
fig = plt.figure() | ||
ax = fig.add_subplot(1, 1, 1) | ||
fifo_avg = [] | ||
fifo_cnt = [] | ||
# This function is called periodically from FuncAnimation | ||
def animate(i): | ||
info = None | ||
for i in range(30): | ||
try: | ||
str_in = dev.read(64, 50) | ||
info = audio_debug_info_t.from_buffer_copy(str_in) | ||
|
||
global fifo_avg | ||
global fifo_cnt | ||
fifo_avg.append(info.fifo_count_avg) | ||
fifo_cnt.append(info.fifo_count) | ||
except: | ||
exit(1) | ||
# Limit to 1000 items | ||
fifo_avg = fifo_avg[-1000:] | ||
fifo_cnt = fifo_cnt[-1000:] | ||
|
||
if info is not None: | ||
# Draw x and y lists | ||
ax.clear() | ||
ax.plot(fifo_cnt, label='FIFO count') | ||
ax.plot(fifo_avg, label='FIFO average') | ||
ax.legend() | ||
ax.set_ylim(bottom=0, top=info.fifo_size) | ||
|
||
# Format plot | ||
plt.title('FIFO information') | ||
plt.grid() | ||
|
||
print(f'Sample rate:{info.sample_rate} | Alt settings:{info.alt_settings} | Volume:{info.volume[:]}') | ||
|
||
ani = animation.FuncAnimation(fig, animate, interval=10) | ||
plt.show() |
This file contains 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,52 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2023 HiFiPhile | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
#ifndef _COMMON_TYPES_H_ | ||
#define _COMMON_TYPES_H_ | ||
|
||
enum | ||
{ | ||
ITF_NUM_AUDIO_CONTROL = 0, | ||
ITF_NUM_AUDIO_STREAMING, | ||
#if CFG_AUDIO_DEBUG | ||
ITF_NUM_DEBUG, | ||
#endif | ||
ITF_NUM_TOTAL | ||
}; | ||
|
||
#if CFG_AUDIO_DEBUG | ||
typedef struct | ||
{ | ||
uint32_t sample_rate; | ||
uint8_t alt_settings; | ||
int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; | ||
int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; | ||
uint16_t fifo_size; | ||
uint16_t fifo_count; | ||
uint16_t fifo_count_avg; | ||
} audio_debug_info_t; | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.