enable volume

This commit is contained in:
Steven Dan
2026-01-14 22:33:51 +08:00
parent 1d486ad075
commit f1e57e307c
8 changed files with 339 additions and 1224 deletions

View File

@@ -14,12 +14,22 @@
#include "xua_hid_report.h"
#include "user_hid.h"
#include "xua_hid.h"
unsigned char g_hidData[HID_MAX_DATA_BYTES] = {0U};
// DFU_CONTROL_USB_HID related
#define HID_BUTTON_REPORT_ID 0x02
#define HID_BUTTON_REPORT_BYTES 2
#define HID_PASS_REPORT_ID 0x01
#define HID_PASS_REPORT_BYTES 64 // 改动原因修改为64字节1字节Report ID + 63字节数据以支持音量和LED状态上报
unsigned char g_hidData[HID_BUTTON_REPORT_BYTES] = {HID_BUTTON_REPORT_ID, 0x0};
unsigned char g_hidPassData[HID_PASS_REPORT_BYTES] = {HID_PASS_REPORT_ID, 0x0};
unsigned char g_hidData_Down[HID_MAX_OUT_BYTES] = {0U};
unsigned char last_hidData = 0;
unsigned char last_hidPassData = 0;
#endif
void GetADCCounts(unsigned samFreq, int &min, int &mid, int &max);
#define BUFFER_SIZE_OUT (1028 >> 2)
#define BUFFER_SIZE_IN (1028 >> 2)
unsigned long get_reference_time();
extern unsigned int g_curSamFreqMultiplier;
@@ -364,9 +374,10 @@ void XUA_Buffer_Ep(
while (!hidIsReportDescriptorPrepared())
;
UserHIDInit();
unsigned hid_ready_flag = 0U;
unsigned hid_ready_id = 0U;
unsigned hid_ready_id = 1U;
XUD_SetReady_In(ep_hid, g_hidData, HID_BUTTON_REPORT_BYTES); // DFU_CONTROL_USB_HID related
#endif
@@ -1207,30 +1218,51 @@ void XUA_Buffer_Ep(
#endif // ifdef IAP
#if (0 < HID_CONTROLS)
default:
#if ( 0 < HID_CONTROLS )
if (!hid_ready_flag)
{
static unsigned long btn_start_time = 0, pass_start_time = 0;
for (unsigned id = hidIsReportIdInUse(); id < hidGetReportIdLimit(); id++)
{
#if (USE_EX3D == 1)
if (hidIsChangePending(id))
#else
if ( hidIsChangePending(id) || !HidIsSetIdleSilenced(id) )
#endif
{
int hidDataLength = (int) UserHIDGetData(id, g_hidData);
XUD_SetReady_In(ep_hid, g_hidData, hidDataLength);
unsigned long now = get_reference_time();
if (id == 2)
{
if (btn_start_time == 0)
{
UserReadHIDButtons(&g_hidData[1]);
btn_start_time = now;
XUD_SetReady_In(ep_hid, g_hidData, HID_BUTTON_REPORT_BYTES);
}
if (timeafter(now, btn_start_time + 2000000))
{
g_hidData[1] = 0;
XUD_SetReady_In(ep_hid, g_hidData, HID_BUTTON_REPORT_BYTES);
hidClearChangePending(id);
btn_start_time = 0;
}
}
if (id == 1)
{
int hidDataLength = (int) UserHIDGetData(id, g_hidPassData);
XUD_SetReady_In(ep_hid, g_hidPassData, hidDataLength);
// printf("hidDataLength: %d\n", hidDataLength);
hid_ready_id = id;
hid_ready_flag = 1U;
break;
}
hidClearChangePending(id);
}
}
}
}
break;
//::
#endif
break;
}
}
}

View File

@@ -31,14 +31,11 @@ typedef struct hidEvent_t {
unsigned value;
} hidEvent_t;
#if defined(USE_EX3D)
#define HID_MAX_DATA_BYTES ( 64 )
#else
#define HID_MAX_DATA_BYTES ( 4 )
#endif
#define HID_MAX_OUT_BYTES ( 65 )
#define HID_EVENT_INVALID_ID ( 0x100 )
#define HID_MAX_OUT_BYTES ( 65 )
/**
* \brief Get the data for the next HID Report
@@ -56,6 +53,19 @@ typedef struct hidEvent_t {
*/
size_t UserHIDGetData( const unsigned id, unsigned char hidData[ HID_MAX_DATA_BYTES ]);
/* These defines relate to the HID report desc - do not mod */
#define HID_CONTROL_PLAYPAUSE_SHIFT 0x00
#define HID_CONTROL_NEXT_SHIFT 0x01
#define HID_CONTROL_PREV_SHIFT 0x02
#define HID_CONTROL_VOLUP_SHIFT 0x03
#define HID_CONTROL_VOLDN_SHIFT 0x04
#define HID_CONTROL_MUTE_SHIFT 0x05
void UserReadHIDButtons(unsigned char hidData[]);
void UserReadHIDPass(unsigned char hidPassData[]);
void UserReadHIDLog(unsigned char hidLogData[]);
void user_read_hid_status(unsigned char hidPassData[]);
/**
* \brief Initialize HID processing
*/