Skip to content

Commit a5f63c9

Browse files
author
Victor Brzeski
committed
usb: device_next: uac2: Support configurable polling rates
1 parent 47828ec commit a5f63c9

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

dts/bindings/usb/uac2/zephyr,uac2-audio-streaming.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,9 @@ properties:
7878
type: int
7979
description: |
8080
Number of effectively used bits in audio subslot.
81+
82+
polling-period-us:
83+
type: int
84+
description: |
85+
Input or output type reports polling period in microseconds. For USB full
86+
speed this could be clamped to 1ms or 255ms depending on the value.

subsys/usb/device_next/class/usbd_uac2_macros.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,13 +707,21 @@
707707
#define AS_BYTES_PER_SAMPLE(node) \
708708
DT_PROP(node, subslot_size)
709709

710+
#define AS_FS_DATA_EP_BINTERVAL(node) \
711+
USB_FS_INT_EP_INTERVAL(DT_PROP_OR(node, polling_period_us, 1))
712+
713+
#define AS_HS_DATA_EP_BINTERVAL(node) \
714+
USB_HS_INT_EP_INTERVAL(DT_PROP_OR(x, polling_period_us, 1))
715+
710716
/* Asynchronous endpoints needs space for 1 extra sample */
711717
#define AS_SAMPLES_PER_FRAME(node) \
712-
((ROUND_UP(AS_CLK_MAX_FREQUENCY(node), 1000) / 1000) + \
718+
((ROUND_UP(AS_CLK_MAX_FREQUENCY(node), 1000) / 1000) * \
719+
AS_FS_DATA_EP_BINTERVAL(node) + \
713720
UTIL_NOT(AS_IS_SOF_SYNCHRONIZED(node)))
714721

715722
#define AS_SAMPLES_PER_MICROFRAME(node) \
716-
((ROUND_UP(AS_CLK_MAX_FREQUENCY(node), 8000) / 8000) + \
723+
((ROUND_UP((AS_CLK_MAX_FREQUENCY(node), 8000) / 8000) <<
724+
(AS_HS_DATA_EP_BINTERVAL(node) - 1)) + \
717725
UTIL_NOT(AS_IS_SOF_SYNCHRONIZED(node)))
718726

719727
#define AS_DATA_EP_SYNC_TYPE(node) \
@@ -728,8 +736,9 @@
728736
AS_DATA_EP_USAGE_TYPE(node)
729737

730738
#define AS_FS_DATA_EP_MAX_PACKET_SIZE(node) \
731-
AUDIO_STREAMING_NUM_SPATIAL_LOCATIONS(node) * \
732-
AS_BYTES_PER_SAMPLE(node) * AS_SAMPLES_PER_FRAME(node)
739+
(AUDIO_STREAMING_NUM_SPATIAL_LOCATIONS(node) * \
740+
AS_BYTES_PER_SAMPLE(node) * AS_SAMPLES_PER_FRAME(node)) \
741+
<< (AS_FS_DATA_EP_BINTERVAL(node) - 1)
733742

734743
#define AS_HS_DATA_EP_TPL(node) \
735744
USB_TPL_ROUND_UP(AUDIO_STREAMING_NUM_SPATIAL_LOCATIONS(node) * \
@@ -745,7 +754,7 @@
745754
AS_DATA_EP_ADDR(node), /* bEndpointAddress */ \
746755
AS_DATA_EP_ATTR(node), /* bmAttributes */ \
747756
U16_LE(AS_FS_DATA_EP_MAX_PACKET_SIZE(node)), /* wMaxPacketSize */ \
748-
0x01, /* bInterval */
757+
AS_FS_DATA_EP_BINTERVAL(node), /* bInterval */
749758

750759
#define AS_ISOCHRONOUS_DATA_ENDPOINT_FS_DESCRIPTORS_ARRAYS(node) \
751760
static uint8_t DESCRIPTOR_NAME(fs_std_data_ep, node)[] = { \
@@ -758,7 +767,7 @@
758767
AS_DATA_EP_ADDR(node), /* bEndpointAddress */ \
759768
AS_DATA_EP_ATTR(node), /* bmAttributes */ \
760769
U16_LE(AS_HS_DATA_EP_MAX_PACKET_SIZE(node)), /* wMaxPacketSize */ \
761-
0x01, /* bInterval */
770+
AS_HS_DATA_EP_BINTERVAL(node), /* bInterval */
762771

763772
#define AS_ISOCHRONOUS_DATA_ENDPOINT_HS_DESCRIPTORS_ARRAYS(node) \
764773
static uint8_t DESCRIPTOR_NAME(hs_std_data_ep, node)[] = { \

0 commit comments

Comments
 (0)