add static to embelish request handler
This commit is contained in:
@@ -23,9 +23,15 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_audio.h"
|
||||
|
||||
struct usbd_audio_control_info audio_control_info = { 0xdb00, 0x0000, 0x0100, 0xf600, 0 };
|
||||
struct usbd_audio_control_info {
|
||||
uint16_t vol_min;
|
||||
uint16_t vol_max;
|
||||
uint16_t vol_res;
|
||||
uint16_t vol_current;
|
||||
uint8_t mute;
|
||||
} audio_control_info = { 0xdb00, 0x0000, 0x0100, 0xf600, 0 };
|
||||
|
||||
int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("AUDIO Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -37,6 +43,7 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data,
|
||||
if (LO_BYTE(setup->wValue) == 0x01) {
|
||||
if (HI_BYTE(setup->wValue) == AUDIO_FU_CONTROL_MUTE) {
|
||||
memcpy(&audio_control_info.mute, *data, *len);
|
||||
usbd_audio_set_mute(audio_control_info.mute);
|
||||
} else if (HI_BYTE(setup->wValue) == AUDIO_FU_CONTROL_VOLUME) {
|
||||
memcpy(&audio_control_info.vol_current, *data, *len);
|
||||
int vol;
|
||||
@@ -96,7 +103,7 @@ int audio_class_request_handler(struct usb_setup_packet *setup, uint8_t **data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void audio_notify_handler(uint8_t event, void *arg)
|
||||
static void audio_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
@@ -104,10 +111,12 @@ void audio_notify_handler(uint8_t event, void *arg)
|
||||
break;
|
||||
|
||||
case USBD_EVENT_SOF:
|
||||
usbd_audio_sof_callback();
|
||||
break;
|
||||
|
||||
case USBD_EVENT_SET_INTERFACE:
|
||||
usbd_audio_set_interface_callback(((uint8_t *)arg)[3]);
|
||||
struct usb_interface_descriptor *intf = (struct usb_interface_descriptor *)arg;
|
||||
usbd_audio_set_interface_callback(intf->bAlternateSetting);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -134,3 +143,11 @@ void usbd_audio_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
__WEAK void usbd_audio_set_volume(uint8_t vol)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_set_mute(uint8_t mute)
|
||||
{
|
||||
}
|
||||
|
||||
__WEAK void usbd_audio_sof_callback(void)
|
||||
{
|
||||
}
|
||||
@@ -29,17 +29,13 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct usbd_audio_control_info {
|
||||
uint16_t vol_min;
|
||||
uint16_t vol_max;
|
||||
uint16_t vol_res;
|
||||
uint16_t vol_current;
|
||||
uint8_t mute;
|
||||
};
|
||||
|
||||
void usbd_audio_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
void usbd_audio_set_interface_callback(uint8_t value);
|
||||
|
||||
void usbd_audio_set_mute(uint8_t mute);
|
||||
void usbd_audio_set_volume(uint8_t vol);
|
||||
void usbd_audio_sof_callback(void);
|
||||
void usbd_audio_set_interface_callback(uint8_t value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -27,7 +27,7 @@ const char *stop_name[] = { "1", "1.5", "2" };
|
||||
const char *parity_name[] = { "N", "O", "E", "M", "S" };
|
||||
|
||||
/* Device data structure */
|
||||
struct cdc_acm_cfg_private {
|
||||
struct cdc_acm_cfg_priv {
|
||||
/* CDC ACM line coding properties. LE order */
|
||||
struct cdc_line_coding line_coding;
|
||||
/* CDC ACM line state bitmap, DTE side */
|
||||
@@ -144,16 +144,6 @@ static void cdc_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_line_coding(uint32_t baudrate, uint8_t databits, uint8_t parity, uint8_t stopbits)
|
||||
{
|
||||
}
|
||||
__WEAK void usbd_cdc_acm_set_dtr(bool dtr)
|
||||
{
|
||||
}
|
||||
__WEAK void usbd_cdc_acm_set_rts(bool rts)
|
||||
{
|
||||
}
|
||||
|
||||
void usbd_cdc_add_acm_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
static usbd_class_t *last_class = NULL;
|
||||
@@ -169,3 +159,13 @@ void usbd_cdc_add_acm_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
intf->notify_handler = cdc_notify_handler;
|
||||
usbd_class_add_interface(devclass, intf);
|
||||
}
|
||||
|
||||
__WEAK void usbd_cdc_acm_set_line_coding(uint32_t baudrate, uint8_t databits, uint8_t parity, uint8_t stopbits)
|
||||
{
|
||||
}
|
||||
__WEAK void usbd_cdc_acm_set_dtr(bool dtr)
|
||||
{
|
||||
}
|
||||
__WEAK void usbd_cdc_acm_set_rts(bool rts)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
#include "usbd_dfu.h"
|
||||
|
||||
/* Device data structure */
|
||||
struct dfu_cfg_private {
|
||||
struct dfu_cfg_priv {
|
||||
struct dfu_info info;
|
||||
} usbd_dfu_cfg;
|
||||
|
||||
int dfu_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int dfu_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_WRN("DFU Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -57,7 +57,7 @@ int dfu_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, ui
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dfu_notify_handler(uint8_t event, void *arg)
|
||||
static void dfu_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#define HID_STATE_IDLE 0
|
||||
#define HID_STATE_BUSY 1
|
||||
|
||||
struct usbd_hid_cfg_private {
|
||||
struct usbd_hid_cfg_priv {
|
||||
const uint8_t *hid_descriptor;
|
||||
const uint8_t *hid_report_descriptor;
|
||||
uint32_t hid_report_descriptor_len;
|
||||
@@ -53,7 +53,7 @@ static void usbd_hid_reset(void)
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
struct usbd_hid_cfg_priv *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_priv, list);
|
||||
hid_intf->hid_state = HID_STATE_IDLE;
|
||||
hid_intf->report = 0;
|
||||
hid_intf->idle_state = 0;
|
||||
@@ -61,7 +61,7 @@ static void usbd_hid_reset(void)
|
||||
}
|
||||
}
|
||||
|
||||
int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Custom request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -72,11 +72,11 @@ int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, u
|
||||
uint8_t value = (uint8_t)(setup->wValue >> 8);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
|
||||
struct usbd_hid_cfg_private *current_hid_intf = NULL;
|
||||
struct usbd_hid_cfg_priv *current_hid_intf = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
struct usbd_hid_cfg_priv *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_priv, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
current_hid_intf = hid_intf;
|
||||
@@ -116,17 +116,17 @@ int hid_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, u
|
||||
return -1;
|
||||
}
|
||||
|
||||
int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int hid_class_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USB_LOG_DBG("HID Class request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
setup->bRequest);
|
||||
|
||||
struct usbd_hid_cfg_private *current_hid_intf = NULL;
|
||||
struct usbd_hid_cfg_priv *current_hid_intf = NULL;
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
struct usbd_hid_cfg_priv *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_priv, list);
|
||||
uint8_t intf_num = (uint8_t)setup->wIndex;
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
current_hid_intf = hid_intf;
|
||||
@@ -199,72 +199,6 @@ static void hid_notify_handler(uint8_t event, void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_reset_state(void)
|
||||
{
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
|
||||
void usbd_hid_send_report(uint8_t ep, uint8_t *data, uint8_t len)
|
||||
{
|
||||
// if(usbd_hid_cfg.hid_state == HID_STATE_IDLE)
|
||||
// {
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_BUSY;
|
||||
// usbd_ep_write(ep, data, len, NULL);
|
||||
// }
|
||||
}
|
||||
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc)
|
||||
{
|
||||
// usbd_hid_cfg.hid_descriptor = desc;
|
||||
}
|
||||
|
||||
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
hid_intf->hid_report_descriptor = desc;
|
||||
hid_intf->hid_report_descriptor_len = desc_len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// clang-format off
|
||||
void usbd_hid_set_request_callback( uint8_t intf_num,
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id),
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
|
||||
void (*set_protocol_callback)(uint8_t protocol),
|
||||
uint8_t (*get_protocol_callback)(void))
|
||||
// clang-format on
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_private *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_private, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
if (get_report_callback)
|
||||
hid_intf->get_report_callback = get_report_callback;
|
||||
if (set_report_callback)
|
||||
hid_intf->set_report_callback = set_report_callback;
|
||||
if (get_idle_callback)
|
||||
hid_intf->get_idle_callback = get_idle_callback;
|
||||
if (set_idle_callback)
|
||||
hid_intf->set_idle_callback = set_idle_callback;
|
||||
if (set_protocol_callback)
|
||||
hid_intf->set_protocol_callback = set_protocol_callback;
|
||||
if (get_protocol_callback)
|
||||
hid_intf->get_protocol_callback = get_protocol_callback;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
{
|
||||
static usbd_class_t *last_class = NULL;
|
||||
@@ -284,3 +218,68 @@ void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf)
|
||||
usb_slist_add_tail(&usbd_hid_class_head, &usbd_hid_cfg[hid_num].list);
|
||||
hid_num++;
|
||||
}
|
||||
|
||||
void usbd_hid_descriptor_register(uint8_t intf_num, const uint8_t *desc)
|
||||
{
|
||||
// usbd_hid_cfg.hid_descriptor = desc;
|
||||
}
|
||||
|
||||
void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc, uint32_t desc_len)
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_priv *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_priv, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
hid_intf->hid_report_descriptor = desc;
|
||||
hid_intf->hid_report_descriptor_len = desc_len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_set_request_callback(uint8_t intf_num,
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id),
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
|
||||
void (*set_protocol_callback)(uint8_t protocol),
|
||||
uint8_t (*get_protocol_callback)(void))
|
||||
{
|
||||
usb_slist_t *i;
|
||||
usb_slist_for_each(i, &usbd_hid_class_head)
|
||||
{
|
||||
struct usbd_hid_cfg_priv *hid_intf = usb_slist_entry(i, struct usbd_hid_cfg_priv, list);
|
||||
|
||||
if (hid_intf->current_intf_num == intf_num) {
|
||||
if (get_report_callback)
|
||||
hid_intf->get_report_callback = get_report_callback;
|
||||
if (set_report_callback)
|
||||
hid_intf->set_report_callback = set_report_callback;
|
||||
if (get_idle_callback)
|
||||
hid_intf->get_idle_callback = get_idle_callback;
|
||||
if (set_idle_callback)
|
||||
hid_intf->set_idle_callback = set_idle_callback;
|
||||
if (set_protocol_callback)
|
||||
hid_intf->set_protocol_callback = set_protocol_callback;
|
||||
if (get_protocol_callback)
|
||||
hid_intf->get_protocol_callback = get_protocol_callback;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usbd_hid_reset_state(void)
|
||||
{
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_IDLE;
|
||||
}
|
||||
|
||||
void usbd_hid_send_report(uint8_t ep, uint8_t *data, uint8_t len)
|
||||
{
|
||||
// if(usbd_hid_cfg.hid_state == HID_STATE_IDLE)
|
||||
// {
|
||||
// usbd_hid_cfg.hid_state = HID_STATE_BUSY;
|
||||
// usbd_ep_write(ep, data, len, NULL);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -34,15 +34,15 @@ void usbd_hid_report_descriptor_register(uint8_t intf_num, const uint8_t *desc,
|
||||
void usbd_hid_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
|
||||
void usbd_hid_reset_state(void);
|
||||
void usbd_hid_send_report(uint8_t ep, uint8_t *data, uint8_t len);
|
||||
// clang-format off
|
||||
void usbd_hid_set_request_callback( uint8_t intf_num,
|
||||
|
||||
void usbd_hid_set_request_callback(uint8_t intf_num,
|
||||
uint8_t (*get_report_callback)(uint8_t report_id, uint8_t report_type),
|
||||
void (*set_report_callback)(uint8_t report_id, uint8_t report_type, uint8_t *report, uint8_t report_len),
|
||||
uint8_t (*get_idle_callback)(uint8_t report_id),
|
||||
void (*set_idle_callback)(uint8_t report_id, uint8_t duration),
|
||||
void (*set_protocol_callback)(uint8_t protocol),
|
||||
uint8_t (*get_protocol_callback)(void));
|
||||
// clang-format on
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -34,7 +34,7 @@ static struct usb_hub_descriptor hub_desc = {
|
||||
.PortPwrCtrlMask = 0xff
|
||||
};
|
||||
|
||||
int hub_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
static int hub_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, uint32_t *len)
|
||||
{
|
||||
USBD_LOG_DBG("HUB Class Custom request: "
|
||||
"bRequest 0x%02x\r\n",
|
||||
@@ -78,7 +78,7 @@ int hub_custom_request_handler(struct usb_setup_packet *setup, uint8_t **data, u
|
||||
return -1;
|
||||
}
|
||||
|
||||
void hub_notify_handler(uint8_t event, void *arg)
|
||||
static void hub_notify_handler(uint8_t event, void *arg)
|
||||
{
|
||||
switch (event) {
|
||||
case USBD_EVENT_RESET:
|
||||
|
||||
@@ -47,7 +47,7 @@ enum Stage {
|
||||
};
|
||||
|
||||
/* Device data structure */
|
||||
struct usbd_msc_cfg_private {
|
||||
struct usbd_msc_cfg_priv {
|
||||
/* state of the bulk-only state machine */
|
||||
enum Stage stage;
|
||||
struct CBW cbw;
|
||||
|
||||
Reference in New Issue
Block a user