This commit is contained in:
Steven Dan
2026-04-14 21:17:56 +08:00
parent b0e1ef869e
commit 6d554c5089
6 changed files with 76 additions and 26 deletions

View File

@@ -9,12 +9,15 @@
#include "xua_hid.h"
#include "xua_hid_report.h"
#include "user_hid.h"
#include "xc_ptr.h"
#define DEBUG_UNIT HID_XC
#define DEBUG_PRINT_ENABLE_HID_XC 0
#include "debug_print.h"
#if XUA_HID_ENABLED
extern unsigned g_log_switch;
static unsigned HidCalcNewReportTime( const unsigned currentPeriod, const unsigned reportTime, const unsigned reportToSetIdleInterval, const unsigned newPeriod );
static unsigned HidCalcReportToSetIdleInterval( const unsigned reportTime );
static unsigned HidFindSetIdleActivationPoint( const unsigned currentPeriod, const unsigned timeWithinPeriod );
@@ -46,8 +49,13 @@ XUD_Result_t HidInterfaceClassRequests(
process_read_params(&buffer[1]);
#endif
#if DEBUG_MEMORY_LOG_ENABLED
ret_len = 65;
unsigned log_switch;
GET_SHARED_GLOBAL(log_switch, g_log_switch);
if (log_switch) {
ret_len = 65;
UserReadHIDLog(&buffer[1]);
}
#endif
#if 0
debug_printf("%d:\n", ret_len);
@@ -84,7 +92,7 @@ XUD_Result_t HidInterfaceClassRequests(
}
if (buffer[1] == 0x77 && ((buffer[2] >= 0x82) || (buffer[2] == 0x5b)))
if (buffer[1] == 0x77 && ((buffer[2] >= 0x70) || (buffer[2] == 0x5b)))
{
process_send_params(&buffer[1], datalength - 1);
}

View File

@@ -104,6 +104,7 @@ set(APP_COMPILER_FLAGS_f5_music_uac1 ${SW_USB_AUDIO_FLAGS} -DI2S_CHANS_DAC
-DOUTPUT_VOLUME_CONTROL=0
#-DDEBUG_MEMORY_LOG_ENABLED=1
-DXUA_DFU_EN=0
-DHID_DFU_EN=1
-DHID_CONTROLS_UAC1=1
#-DIR_SWITCHING_MODE
-DHID_CONTROLS=1)
@@ -220,6 +221,7 @@ set(APP_COMPILER_FLAGS_f6_f7_fps_uac1 ${SW_USB_AUDIO_FLAGS} -DI2S_CHANS_DAC=2
#-DDEBUG_MEMORY_LOG_ENABLED=1
-DXUA_DFU_EN=1
-DHID_DFU_EN=1
-DHID_CONTROLS_UAC1=1
-DIR_SWITCHING_MODE
-DHID_CONTROLS=1)

View File

@@ -27,28 +27,6 @@ static int dfu_upgrade_image_valid = 0;
static int dfu_current_flash_subpage_index = 0;
static unsigned char dfu_current_flash_page_data[256];
int dfu_flash_cmd_enable_ports() __attribute__ ((weak));
int dfu_flash_cmd_enable_ports() {
return 0;
}
int dfu_flash_cmd_disable_ports() __attribute__ ((weak));
int dfu_flash_cmd_disable_ports() {
return 0;
}
void DFUCustomFlashEnable() __attribute__ ((weak));
void DFUCustomFlashEnable()
{
return;
}
void DFUCustomFlashDisable() __attribute__ ((weak));
void DFUCustomFlashDisable()
{
return;
}
/* Returns non-zero for error */
int dfu_flash_cmd_init(void)
{
@@ -270,4 +248,3 @@ int dfu_flash_cmd_erase_all(void)
return 0;
}
#endif

View File

@@ -1,7 +1,7 @@
// Copyright 2012-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#include "xua.h"
#if (XUA_DFU_EN == 1 || UAC1 == 1)
#if (HID_DFU_EN == 1)
#include "uac_hwresources.h"
#include <xs1.h>
#include <xclib.h>

View File

@@ -15,6 +15,7 @@ extern void device_reboot(void);
// 常量定义
#define EQ_DISABLED_MODE 10 // 禁用EQ的模式编号
unsigned g_log_switch = 0;
#include "xmath/filter.h"
#include "eq.h"
@@ -62,6 +63,7 @@ static struct {
} read_request = {0};
// Optimized: 51 entries for integer dB values 0 to -50 (was 183 entries at 0.5dB steps)
// 改动原因log打印开关全局变量0=关闭 1=开启由0x70 SET_LOG_SWITCH 设置debug_printf 宏在输出前检查该变量
static const int32_t attenuation_table[51] = {
0x01000000, // 0dB
0x00E42905, // -1dB
@@ -773,6 +775,21 @@ unsigned char process_send_params(uint8_t data[], uint16_t len) {
return true;
}
// 处理设置log打印开关命令 (0x70) - SET_LOG_SWITCH
// 改动原因添加0x70命令用全局变量g_log_switch记录开关状态0=关闭 1=开启debug_printf 据此决定是否输出
if (data[1] == 0x70) {
uint8_t on = data[2];
if (on > 1) {
debug_printf("Error: Invalid log switch %d (must be 0 or 1)\n", on);
return false;
}
g_log_switch = on;
debug_printf("Log switch set to %d (0=off, 1=on)\n", on);
return true;
}
// 处理恢复出厂默认命令 (0x84) - FACTORY_RESET
if (data[1] == 0x84) {
// 通知button_task在合适时机删除其他文件并重启

View File

@@ -746,6 +746,21 @@ class EQDesigner(QMainWindow):
left_content_layout.addWidget(device_mode_group)
# Log控制组0x70 SET_LOG_SWITCH0=关闭 1=开启),便于在视图菜单中显示/隐藏
log_group = QGroupBox("Log控制")
self.ui_groups['log_switch'] = log_group
log_layout = QFormLayout(log_group)
log_control_layout = QHBoxLayout()
self.log_switch_combo = QComboBox()
self.log_switch_combo.addItem("关闭log (0)", 0)
self.log_switch_combo.addItem("开启log (1)", 1)
log_control_layout.addWidget(QLabel("Log打印:"))
log_control_layout.addWidget(self.log_switch_combo)
log_layout.addRow(log_control_layout)
self.set_log_switch_btn = QPushButton("设置log开关")
self.set_log_switch_btn.clicked.connect(self.on_set_log_switch)
log_layout.addRow(self.set_log_switch_btn)
left_content_layout.addWidget(log_group)
# 添加EQ使能控制组
eq_enable_group = QGroupBox("EQ使能控制")
self.ui_groups['eq_enable'] = eq_enable_group # 保存引用
@@ -988,6 +1003,7 @@ class EQDesigner(QMainWindow):
'param': 'EQ参数配置',
'volume': '音量控制',
'device_mode': '音效模式控制',
'log_switch': 'Log控制',
'eq_enable': 'EQ使能控制',
'ex3d': 'EX3D控制',
'firmware': '固件升级'
@@ -1016,6 +1032,7 @@ class EQDesigner(QMainWindow):
'param': 'EQ参数配置',
'volume': '音量控制',
'device_mode': '音效模式控制',
'log_switch': 'Log控制',
'eq_enable': 'EQ使能控制',
'ex3d': 'EX3D控制',
'firmware': '固件升级'
@@ -3641,6 +3658,35 @@ eq_mode_data_t sEQ_data_{int(fs)}HZ[NUM_EQ_MODES][NUM_EQ_CHANS] = {{
except Exception as e:
log_message(LOG_LEVEL_ERROR, f"读取音效模式时出错: {str(e)}", self.log_level)
def on_set_log_switch(self):
"""设置log打印开关发送0x70命令0=关闭 1=开启"""
if self.device_combo.currentData() is None:
log_message(LOG_LEVEL_ERROR, "请先选择设备", self.log_level)
return
value = self.log_switch_combo.currentData()
try:
device_info = self.device_combo.currentData()
h = hid.device()
h.open(device_info['vendor_id'], device_info['product_id'])
h.set_nonblocking(1)
data = bytearray(63)
data[0] = 0x77
data[1] = 0x70 # SET_LOG_SWITCH
data[2] = value # 0=关闭 1=开启
log_message(LOG_LEVEL_INFO, f"正在设置log开关为 {value} (0=关闭 1=开启)...", self.log_level)
h.write([0x01] + list(data))
h.close()
state_name = "关闭" if value == 0 else "开启"
log_message(LOG_LEVEL_INFO, f"log开关已设置为 {state_name}", self.log_level)
QMessageBox.information(
self,
"Log控制",
f"log打印已设置为: {self.log_switch_combo.currentText()}\n\n{state_name}"
)
except Exception as e:
log_message(LOG_LEVEL_ERROR, f"设置log开关时出错: {str(e)}", self.log_level)
def on_get_firmware_version(self):
"""读取固件版本发送0xA6命令"""