summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2022-03-26 16:07:28 +0800
committersakumisu <[email protected]>2022-03-26 16:07:28 +0800
commit5d78031bb28a2d367d89b9ed66c334e9f37adaf3 (patch)
tree00ce88ea68dd93f5d1ec2306a561b30d7c76f3c1
parentceeb951a00b4d01860b8dbd146e99c46e211923f (diff)
update audio and video macros,add xxx_open and xxx_close function
-rw-r--r--class/audio/usb_audio.h218
-rw-r--r--class/audio/usbd_audio.c6
-rw-r--r--class/audio/usbd_audio.h4
-rw-r--r--class/video/usb_video.h45
-rw-r--r--class/video/usbd_video.c6
-rw-r--r--class/video/usbd_video.h5
6 files changed, 182 insertions, 102 deletions
diff --git a/class/audio/usb_audio.h b/class/audio/usb_audio.h
index 9b7a6c10..a0c4544b 100644
--- a/class/audio/usb_audio.h
+++ b/class/audio/usb_audio.h
@@ -491,6 +491,10 @@
#define AUDIO_SIDEBAND_PROTOCOL_UNDEF 0x00
#define AUDIO_PRES_TIMESTAMP_PROTOCOL 0x01
+/** USB Terminal Types
+ * Refer to Table 2-1 - Table 2-4 from termt10.pdf
+ */
+
/* USB Terminal Types */
#define AUDIO_TERMINAL_UNDEF 0x0100
#define AUDIO_TERMINAL_STREAMING 0x0101
@@ -573,69 +577,19 @@
#define AUDIO_FORMAT_TYPE_II 0x02
#define AUDIO_FORMAT_TYPE_III 0x03
-/** USB Terminal Types
- * Refer to Table 2-1 - Table 2-4 from termt10.pdf
- */
-enum usb_audio_terminal_types {
- /* USB Terminal Types */
- USB_AUDIO_USB_UNDEFINED = 0x0100,
- USB_AUDIO_USB_STREAMING = 0x0101,
- USB_AUDIO_USB_VENDOR_SPEC = 0x01FF,
-
- /* Input Terminal Types */
- USB_AUDIO_IN_UNDEFINED = 0x0200,
- USB_AUDIO_IN_MICROPHONE = 0x0201,
- USB_AUDIO_IN_DESKTOP_MIC = 0x0202,
- USB_AUDIO_IN_PERSONAL_MIC = 0x0203,
- USB_AUDIO_IN_OM_DIR_MIC = 0x0204,
- USB_AUDIO_IN_MIC_ARRAY = 0x0205,
- USB_AUDIO_IN_PROC_MIC_ARRAY = 0x0205,
-
- /* Output Terminal Types */
- USB_AUDIO_OUT_UNDEFINED = 0x0300,
- USB_AUDIO_OUT_SPEAKER = 0x0301,
- USB_AUDIO_OUT_HEADPHONES = 0x0302,
- USB_AUDIO_OUT_HEAD_AUDIO = 0x0303,
- USB_AUDIO_OUT_DESKTOP_SPEAKER = 0x0304,
- USB_AUDIO_OUT_ROOM_SPEAKER = 0x0305,
- USB_AUDIO_OUT_COMM_SPEAKER = 0x0306,
- USB_AUDIO_OUT_LOW_FREQ_SPEAKER = 0x0307,
-
- /* Bi-directional Terminal Types */
- USB_AUDIO_IO_UNDEFINED = 0x0400,
- USB_AUDIO_IO_HANDSET = 0x0401,
- USB_AUDIO_IO_HEADSET = 0x0402,
- USB_AUDIO_IO_SPEAKERPHONE_ECHO_NONE = 0x0403,
- USB_AUDIO_IO_SPEAKERPHONE_ECHO_SUP = 0x0404,
- USB_AUDIO_IO_SPEAKERPHONE_ECHO_CAN = 0x0405,
-};
-
-/**
- * @warning Size of baInterface is 2 just to make it useable
- * for all kind of devices: headphones, microphone and headset.
- * Actual size of the struct should be checked by reading
- * .bLength.
- */
-struct adc_ac_if_descriptor {
+struct audio_cs_if_ac_header_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint16_t bcdAUDIO;
uint16_t wTotalLength;
uint8_t bInCollection;
- uint8_t baInterfaceNr[2];
+ uint8_t baInterfaceNr[];
} __PACKED;
-struct adc_as_if_descriptor {
- uint8_t bLength;
- uint8_t bDescriptorType;
- uint8_t bDescriptorSubtype;
- uint8_t bTerminalLink;
- uint8_t bDelay;
- uint16_t wFormatTag;
-} __PACKED;
+#define AUDIO_SIZEOF_AC_HEADER_DESC(n) (8 + n)
-struct adc_input_terminal_descriptor {
+struct audio_cs_if_ac_input_terminal_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
@@ -648,7 +602,9 @@ struct adc_input_terminal_descriptor {
uint8_t iTerminal;
} __PACKED;
-struct adc_output_terminal_descriptor {
+#define AUDIO_SIZEOF_AC_INPUT_TERMINAL_DESC (12)
+
+struct audio_cs_if_ac_output_terminal_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
@@ -659,21 +615,33 @@ struct adc_output_terminal_descriptor {
uint8_t iTerminal;
} __PACKED;
-/**
- * @note Size of Feature unit descriptor is not fixed.
- * This structure is just a helper not a common type.
- */
-struct adc_feature_unit_descriptor {
+#define AUDIO_SIZEOF_AC_OUTPUT_TERMINAL_DESC (9)
+
+struct audio_cs_if_ac_feature_unit_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
uint8_t bUnitID;
uint8_t bSourceID;
uint8_t bControlSize;
- uint16_t bmaControls[1];
+ // uint8_t bmaControls[];
+ uint8_t iFeature;
} __PACKED;
-struct adc_format_type_i_descriptor {
+#define AUDIO_SIZEOF_AC_FEATURE_UNIT_DESC(n) (7 + n)
+
+struct audio_cs_if_as_general_descriptor {
+ uint8_t bLength;
+ uint8_t bDescriptorType;
+ uint8_t bDescriptorSubtype;
+ uint8_t bTerminalLink;
+ uint8_t bDelay;
+ uint16_t wFormatTag;
+} __PACKED;
+
+#define AUDIO_SIZEOF_AS_GENERAL_DESC (7)
+
+struct audio_cs_if_as_format_type_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
@@ -685,7 +653,9 @@ struct adc_format_type_i_descriptor {
uint8_t tSamFreq[3];
} __PACKED;
-struct adc_as_std_ep_descriptor {
+#define AUDIO_SIZEOF_FORMAT_TYPE_DESC(n) (8 + 3 * n)
+
+struct audio_ep_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bEndpointAddress;
@@ -696,7 +666,9 @@ struct adc_as_std_ep_descriptor {
uint8_t bSynchAddress;
} __PACKED;
-struct adc_as_cs_ep_descriptor {
+#define AUDIO_SIZEOF_EP_DESC (9)
+
+struct audio_cs_ep_ep_general_descriptor {
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDescriptorSubtype;
@@ -705,4 +677,122 @@ struct adc_as_cs_ep_descriptor {
uint16_t wLockDelay;
} __PACKED;
+#define AUDIO_SIZEOF_CS_EP_GENERAL_DESC (7)
+
+// clang-format off
+#define AUDIO_AC_DESCRIPTOR_INIT(bFirstInterface, bInterfaceCount, bcdADC, wTotalLength, stridx, bInCollection, ...) \
+ /* Interface Association Descriptor */ \
+ 0x08, \
+ USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION, \
+ bFirstInterface, \
+ bInterfaceCount, \
+ USB_DEVICE_CLASS_AUDIO, \
+ AUDIO_SUBCLASS_AUDIOCONTROL, \
+ AUDIO_PROTOCOL_UNDEFINED, \
+ 0x00, \
+ /* ------------------ AudioControl Interface ------------------ */\
+ 0x09, /* bLength */ \
+ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
+ bFirstInterface, /* bInterfaceNumber */ \
+ 0x00, /* bAlternateSetting */ \
+ 0x00, /* bNumEndpoints */ \
+ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
+ AUDIO_SUBCLASS_AUDIOCONTROL, /* bInterfaceSubClass */ \
+ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
+ stridx, /* iInterface */ \
+ 0x08 + PP_NARG(__VA_ARGS__), /* bLength */ \
+ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_CONTROL_HEADER, /* bDescriptorSubtype */ \
+ WBVAL(bcdADC), /* bcdADC */ \
+ WBVAL(wTotalLength), /* wTotalLength */ \
+ bInCollection, /* bInCollection */ \
+ __VA_ARGS__ /* baInterfaceNr */
+
+#define AUDIO_AC_DESCRIPTOR_INIT_LEN(n) (0x08 + 0x09 + 0x08 + n)
+
+#define AUDIO_AC_INPUT_TERMINAL_DESCRIPTOR_INIT(bTerminalID, wTerminalType, bNrChannels, wChannelConfig) \
+ 0x0C, /* bLength */ \
+ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_CONTROL_INPUT_TERMINAL, /* bDescriptorSubtype */ \
+ bTerminalID, /* bTerminalID */ \
+ WBVAL(wTerminalType), /* wTerminalType : Microphone 0x0201 */ \
+ 0x00, /* bAssocTerminal */ \
+ bNrChannels, /* bNrChannels */ \
+ WBVAL(wChannelConfig), /* wChannelConfig : Mono sets no position bits */ \
+ 0x00, /* iChannelNames */ \
+ 0x00 /* iTerminal */
+
+#define AUDIO_AC_OUTPUT_TERMINAL_DESCRIPTOR_INIT(bTerminalID, wTerminalType, bSourceID) \
+ 0x09, /* bLength */ \
+ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_CONTROL_OUTPUT_TERMINAL, /* bDescriptorSubtype */ \
+ bTerminalID, /* bTerminalID */ \
+ WBVAL(wTerminalType), /* wTerminalType : USB Streaming */ \
+ 0x00, /* bAssocTerminal */ \
+ bSourceID, /* bSourceID */ \
+ 0x00 /* iTerminal */
+
+#define AUDIO_AC_FEATURE_UNIT_DESCRIPTOR_INIT(bUnitID, bSourceID, bControlSize, ...) \
+ 0x07 + PP_NARG(__VA_ARGS__), /* bLength */ \
+ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_CONTROL_FEATURE_UNIT, /* bDescriptorSubtype */ \
+ bUnitID, /* bUnitID */ \
+ bSourceID, /* bSourceID */ \
+ bControlSize, /* bControlSize */ \
+ __VA_ARGS__, /* bmaControls(0) Mute */ \
+ 0x00 /* iTerminal */
+
+#define AUDIO_AS_DESCRIPTOR_INIT(bInterfaceNumber, bTerminalLink, bNrChannels, bEndpointAddress, wMaxPacketSize, bInterval, bSamFreqType, ...) \
+ 0x09, /* bLength */ \
+ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
+ bInterfaceNumber, /* bInterfaceNumber */ \
+ 0x00, /* bAlternateSetting */ \
+ 0x00, /* bNumEndpoints */ \
+ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
+ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
+ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
+ 0x00, /* iInterface */ \
+ 0x09, /* bLength */ \
+ USB_DESCRIPTOR_TYPE_INTERFACE, /* bDescriptorType */ \
+ bInterfaceNumber, /* bInterfaceNumber */ \
+ 0x01, /* bAlternateSetting */ \
+ 0x01, /* bNumEndpoints */ \
+ USB_DEVICE_CLASS_AUDIO, /* bInterfaceClass */ \
+ AUDIO_SUBCLASS_AUDIOSTREAMING, /* bInterfaceSubClass */ \
+ AUDIO_PROTOCOL_UNDEFINED, /* bInterfaceProtocol */ \
+ 0x00, /* iInterface */ \
+ 0x07, /* bLength */ \
+ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_STREAMING_GENERAL, /* bDescriptorSubtype */ \
+ bTerminalLink, /* bTerminalLink : Unit ID of the Output Terminal*/ \
+ 0x01, /* bDelay */ \
+ 0x01, /* wFormatTag : AUDIO_FORMAT_PCM */ \
+ 0x00, \
+ 0x08 + PP_NARG(__VA_ARGS__), /* bLength */ \
+ AUDIO_INTERFACE_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_STREAMING_FORMAT_TYPE, /* bDescriptorSubtype */ \
+ AUDIO_FORMAT_TYPE_I, /* bFormatType */ \
+ bNrChannels, /* bNrChannels */ \
+ 0x02, /* bSubFrameSize : 2 Bytes per audio subframe */ \
+ 0x10, /* bBitResolution : 16 bits per sample */ \
+ bSamFreqType, /* bSamFreqType : only one frequency supported */ \
+ __VA_ARGS__, /* tSamFreq : Audio sampling frequency coded on 3 bytes */ \
+ 0x09, /* bLength */ \
+ USB_DESCRIPTOR_TYPE_ENDPOINT, /* bDescriptorType */ \
+ bEndpointAddress, /* bEndpointAddress : IN endpoint 1 */ \
+ 0x01, /* bmAttributes */ \
+ WBVAL(wMaxPacketSize), /* wMaxPacketSize */ \
+ 0x04, /* bInterval : one packet per frame */ \
+ 0x00, /* bRefresh */ \
+ 0x00, /* bSynchAddress */ \
+ 0x07, /* bLength */ \
+ AUDIO_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType */ \
+ AUDIO_ENDPOINT_GENERAL, /* bDescriptor */ \
+ 0x00, /* bmAttributes AUDIO_SAMPLING_FREQ_CONTROL */ \
+ 0x00, /* bLockDelayUnits */ \
+ 0x00, /* wLockDelay */ \
+ 0x00
+// clang-format on
+#define AUDIO_AS_DESCRIPTOR_INIT_LEN(n) (0x09 + 0x09 + 0x07 + 0x08 + 3 * n + 0x09 + 0x07)
+
#endif /* _USB_AUDIO_H_ */
diff --git a/class/audio/usbd_audio.c b/class/audio/usbd_audio.c
index 92c9a4c2..cdf0c212 100644
--- a/class/audio/usbd_audio.c
+++ b/class/audio/usbd_audio.c
@@ -116,7 +116,11 @@ static void audio_notify_handler(uint8_t event, void *arg)
case USBD_EVENT_SET_INTERFACE:
struct usb_interface_descriptor *intf = (struct usb_interface_descriptor *)arg;
- usbd_audio_set_interface_callback(intf->bAlternateSetting);
+ if (intf->bAlternateSetting == 1) {
+ usbd_audio_open(intf->bInterfaceNumber);
+ } else {
+ usbd_audio_close(intf->bInterfaceNumber);
+ }
break;
default:
diff --git a/class/audio/usbd_audio.h b/class/audio/usbd_audio.h
index 5eb32a79..04cb27c7 100644
--- a/class/audio/usbd_audio.h
+++ b/class/audio/usbd_audio.h
@@ -31,10 +31,10 @@ extern "C" {
void usbd_audio_add_interface(usbd_class_t *devclass, usbd_interface_t *intf);
+void usbd_audio_open(uint8_t intf);
+void usbd_audio_close(uint8_t intf);
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
}
diff --git a/class/video/usb_video.h b/class/video/usb_video.h
index 917149f8..0fc91e34 100644
--- a/class/video/usb_video.h
+++ b/class/video/usb_video.h
@@ -816,7 +816,7 @@ struct video_cs_if_vc_header_descriptor {
uint8_t baInterfaceNr[];
} __PACKED;
-#define VIDEO_SIZEOF_VC_HEADER_DESC(n) (12 + n)
+#define VIDEO_SIZEOF_VC_HEADER_DESC(n) (11 + n)
struct video_cs_if_vc_input_terminal_descriptor {
uint8_t bLength;
@@ -843,7 +843,7 @@ struct video_cs_if_vc_processing_unit_descriptor {
uint8_t bSourceID;
uint16_t wMaxMultiplier;
uint8_t bControlSize;
- uint8_t bmaControls[2];
+ // uint8_t bmaControls[];
uint8_t iProcessing;
uint8_t bmVideoStandards;
} __PACKED;
@@ -919,7 +919,7 @@ struct video_cs_if_vs_format_uncompressed_descriptor {
uint8_t bCopyProtect;
} __PACKED;
-#define VIDEO_SIZEOF_VS_FORMAT_UNCOMPRESSED_DESC(n) (27)
+#define VIDEO_SIZEOF_VS_FORMAT_UNCOMPRESSED_DESC (27)
struct video_cs_if_vs_frame_uncompressed_descriptor {
uint8_t bLength;
@@ -972,7 +972,7 @@ struct video_cs_if_vs_frame_mjpeg_descriptor {
uint32_t dwFrameInterval2;
} __PACKED;
-#define VIDEO_SIZEOF_VS_FRAME_MJPEG_DESC 34
+#define VIDEO_SIZEOF_VS_FRAME_MJPEG_DESC(n) (26 + n)
struct video_cs_if_vs_colorformat_descriptor {
uint8_t bLength;
@@ -1076,7 +1076,7 @@ struct video_autoexposure_mode {
WBVAL(wTotalLength), /* wTotalLength */ \
DBVAL(dwClockFrequency), /* dwClockFrequency : 0x005b8d80 -> 6,000,000 == 6MHz*/ \
0x01, /* bInCollection : Number of streaming interfaces. */ \
- 0x01, /* baInterfaceNr(1) : VideoStreaming interface 1 belongs to this VideoControl interface.*/ \
+ (uint8_t)(bFirstInterface + 1), /* baInterfaceNr(0) : VideoStreaming interface 1 belongs to this VideoControl interface.*/ \
/* Input Terminal 1 -> Processing Unit 2 -> Output Terminal 3 */ \
0x12, \
0x24, \
@@ -1121,9 +1121,9 @@ struct video_autoexposure_mode {
0x00, /* bInterfaceProtocol : PC_PROTOCOL_UNDEFINED */ \
0x00 /* iInterface : unused */
-#define VIDEO_VS_HEADER_DESCRIPTOR_INIT(bNumFormats, wTotalLength, bEndpointAddress) \
+#define VIDEO_VS_HEADER_DESCRIPTOR_INIT(bNumFormats, wTotalLength, bEndpointAddress, bControlSize, ...) \
/*Class-specific VideoStream Header Descriptor (Input) */ \
- 0x0e, \
+ 0x0d + PP_NARG(__VA_ARGS__), \
0x24, \
VIDEO_VS_INPUT_HEADER_DESCRIPTOR_SUBTYPE, \
bNumFormats, /* bNumFormats : One format descriptor follows. */ \
@@ -1134,8 +1134,8 @@ struct video_autoexposure_mode {
0x00, /* bStillCaptureMethod : Device supports still image capture method 0. */ \
0x00, /* bTriggerSupport : Hardware trigger supported for still image capture */ \
0x00, /* bTriggerUsage : Hardware trigger should initiate a still image capture. */ \
- 0x01, /* bControlSize : Size of the bmaControls field */ \
- 0x00 /* bmaControls : No VideoStreaming specific controls are supported.*/
+ bControlSize, /* bControlSize : Size of the bmaControls field */ \
+ __VA_ARGS__ /* bmaControls : No VideoStreaming specific controls are supported.*/
#define VIDEO_VS_FORMAT_UNCOMPRESSED_DESCRIPTOR_INIT(bFormatIndex, bNumFrameDescriptors, GUIDFormat) \
/*Payload Format(UNCOMPRESSED) Descriptor */ \
@@ -1183,8 +1183,8 @@ struct video_autoexposure_mode {
0x00 /* bCopyProtect : No restrictions imposed on the duplication of this video stream. */
#define VIDEO_VS_FRAME_MJPEG_DESCRIPTOR_INIT(bFrameIndex, wWidth, wHeight, dwMinBitRate, dwMaxBitRate, \
- dwMaxVideoFrameBufferSize, dwDefaultFrameInterval, dwMinFrameInterval1, dwMinFrameInterval2) \
- 0x22, /* bLength */ \
+ dwMaxVideoFrameBufferSize, dwDefaultFrameInterval, bFrameIntervalType, ...) \
+ 0x1a + PP_NARG(__VA_ARGS__), /* bLength */ \
0x24, /* bDescriptorType : CS_INTERFACE */ \
VIDEO_VS_FRAME_MJPEG_DESCRIPTOR_SUBTYPE, /* bDescriptorSubType : VS_FRAME_MJPEG */ \
bFrameIndex, /* bFrameIndex : First (and only) frame descriptor */ \
@@ -1195,26 +1195,7 @@ struct video_autoexposure_mode {
DBVAL(dwMaxBitRate), /* dwMaxBitRate (4bytes): Max bit rate in bits/s */ \
DBVAL(dwMaxVideoFrameBufferSize), /* dwMaxVideoFrameBufSize (4bytes): Maximum video or still frame size, in bytes. */ \
DBVAL(dwDefaultFrameInterval), /* dwDefaultFrameInterval : 1,000,000 * 100ns -> 10 FPS */ \
- 0x02, /* bFrameIntervalType : Indicates how the frame interval can be programmed. 0: Continuous frame interval 1..255: The number of discrete frame */ \
- DBVAL(dwMinFrameInterval1), /* dwMinFrameInterval : 1,000,000 ns *100ns -> 10 FPS,Shortest frame interval supported (at highest frame rate), in 100 ns units */ \
- DBVAL(dwMinFrameInterval2) /* dwMaxFrameInterval : 1,000,000 ns *100ns -> 10 FPS,Longest frame interval supported (at lowest frame rate), in 100 ns units */
-
-#define VIDEO_VS_FRAME_MJPEG_DESCRIPTOR_INIT_V2(bFrameIndex, wWidth, wHeight, dwMinBitRate, dwMaxBitRate, \
- dwMaxVideoFrameBufferSize, dwDefaultFrameInterval, dwMinFrameInterval1, dwMinFrameInterval2) \
- 0x26, /* bLength */ \
- 0x24, /* bDescriptorType : CS_INTERFACE */ \
- VIDEO_VS_FRAME_MJPEG_DESCRIPTOR_SUBTYPE, /* bDescriptorSubType : VS_FRAME_MJPEG */ \
- bFrameIndex, /* bFrameIndex : First (and only) frame descriptor */ \
- 0x00, /* bmCapabilities : Still images using capture method 0 are supported at this frame setting.D1: Fixed frame-rate. */ \
- WBVAL(wWidth), /* wWidth (2bytes): Width of frame is 128 pixels. */ \
- WBVAL(wHeight), /* wHeight (2bytes): Height of frame is 64 pixels. */ \
- DBVAL(dwMinBitRate), /* dwMinBitRate (4bytes): Min bit rate in bits/s */ \
- DBVAL(dwMaxBitRate), /* dwMaxBitRate (4bytes): Max bit rate in bits/s */ \
- DBVAL(dwMaxVideoFrameBufferSize), /* dwMaxVideoFrameBufSize (4bytes): Maximum video or still frame size, in bytes. */ \
- DBVAL(dwDefaultFrameInterval), /* dwDefaultFrameInterval : 1,000,000 * 100ns -> 10 FPS */ \
- 0x00, /* bFrameIntervalType : Indicates how the frame interval can be programmed. 0: Continuous frame interval 1..255: The number of discrete frame */ \
- DBVAL(dwMinFrameInterval1), /* dwMinFrameInterval : 1,000,000 ns *100ns -> 10 FPS,Shortest frame interval supported (at highest frame rate), in 100 ns units */ \
- DBVAL(dwMinFrameInterval2), /* dwMaxFrameInterval : 1,000,000 ns *100ns -> 10 FPS,Longest frame interval supported (at lowest frame rate), in 100 ns units */ \
- 0x00, 0x00, 0x00, 0x00 /* dwFrameIntervalStep : No frame interval step supported. */
+ bFrameIntervalType, /* bFrameIntervalType : Indicates how the frame interval can be programmed. 0: Continuous frame interval 1..255: The number of discrete frame */ \
+ __VA_ARGS__
// clang-format on
#endif /* USB_VIDEO_H_ */
diff --git a/class/video/usbd_video.c b/class/video/usbd_video.c
index 33fa48f6..10071eb7 100644
--- a/class/video/usbd_video.c
+++ b/class/video/usbd_video.c
@@ -709,7 +709,11 @@ static void video_notify_handler(uint8_t event, void *arg)
case USBD_EVENT_SET_INTERFACE: {
struct usb_interface_descriptor *intf = (struct usb_interface_descriptor *)arg;
- usbd_video_set_interface_callback(intf->bAlternateSetting);
+ if (intf->bAlternateSetting == 1) {
+ usbd_video_open(intf->bInterfaceNumber);
+ } else {
+ usbd_video_close(intf->bInterfaceNumber);
+ }
}
break;
diff --git a/class/video/usbd_video.h b/class/video/usbd_video.h
index 772b6607..28208ead 100644
--- a/class/video/usbd_video.h
+++ b/class/video/usbd_video.h
@@ -31,11 +31,12 @@ extern "C" {
void usbd_video_add_interface(usbd_class_t *class, usbd_interface_t *intf);
+void usbd_video_open(uint8_t intf);
+void usbd_video_close(uint8_t intf);
void usbd_video_probe_and_commit_controls_init(uint32_t dwFrameInterval, uint32_t dwMaxVideoFrameSize, uint32_t dwMaxPayloadTransferSize);
uint32_t usbd_video_mjpeg_payload_fill(uint8_t *input, uint32_t input_len, uint8_t *output, uint32_t *out_len);
void usbd_video_mjpeg_payload_header_toggle(uint8_t *output, uint32_t packets);
-void usbd_video_sof_callback(void);
-void usbd_video_set_interface_callback(uint8_t value);
+
#ifdef __cplusplus
}