Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

samples: usb: add UAC2 implicit feedback sample #70029

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

tmon-nordic
Copy link
Contributor

The sample illustates how to achieve bidirectional asynchronous audio. Implicit feedback is the only way to achieve asynchronous USB headset on devices that have only one isochronous IN and one isochronous OUT endpoint.

The sample implements stereo playback and mono recording. While it would be possible to have stereo recording, the commonly available headsets are mono only. The number of channels can differ between audio sink and source because the only requirement is that the two run on same clock.

@tmon-nordic tmon-nordic added area: USB Universal Serial Bus area: Samples Samples Experimental Experimental features not enabled by default labels Mar 11, 2024
@zephyrbot zephyrbot requested review from kartben and nashif March 11, 2024 10:10
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y

#Enable timer for asynchronous feedback
CONFIG_NRFX_TIMER2=y
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use a NRFX type timer here, or can a generic Zephyr timer be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feedback_nrf53.c implementation uses timer and connects USB SOF and I2S FRAMESTART to it with DPPI. DPPI is so specific to Nordic that I don't really see how to achieve this without resorting to low-level hardware interface.

I don't know how to achieve proper feedback without relying on the low-level functionality. This however is something that application has to somehow figure out and I do provide a working sample implementation for nRF53.

return NULL;
}

void feedback_process(struct feedback_ctx *ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With should normally be executed in these functions? Can some comments be added to guide customers?

Copy link
Contributor Author

@tmon-nordic tmon-nordic Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read the comment in feedback.h:
https://github.com/zephyrproject-rtos/zephyr/blob/602054402313f885c2a722616ceee87c735668b6/samples/subsys/usb/uac2_implicit_feedback/src/feedback.h#L22-L33

The comment refers to what has to be reported. How this is achieved is entirely up to the implementer.

I only know how to achieve it using DPPI subsystem and TIMER on nRF53. I hope that eventually someone will come up with platform independent solution, but this is not a trivial task at all and I think it would require some sort of interrupt/event timestamping API that is simply not available yet (and some clever filtering because the control goal is to have I2S FRAMESTART and USB SOF happen at the same time, where obviously one interrupt handler will execute before the other and the two will keep "swapping" with each other which one executes first).


struct usb_i2s_ctx {
const struct device *i2s_dev;
bool headphones_enabled;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more descriptive to name this playback and recording? Or out and in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to understand the sample I believe it is crucial to understand the audio device devicetree description. In devicetree description there are headphones and microphone terminals. headphones_enabled and microphone_enabled therefore is probably the least confusing name possible - headphones_enabled refers to headphones output terminal and microphone_enabled refers to microphone input terminal.

@desowin desowin force-pushed the implicit-feedback branch 2 times, most recently from e960c03 to a0cb4b1 Compare June 3, 2024 14:37
@carlescufi carlescufi requested a review from koffes June 10, 2024 11:21
@carlescufi
Copy link
Member

@koffes please take another look

@carlescufi carlescufi added this to the v3.7.0 milestone Jun 10, 2024
samples/subsys/usb/uac2_implicit_feedback/prj.conf Outdated Show resolved Hide resolved
Comment on lines +51 to +55
/* Counter used to determine when to start I2S and then when to start
* sending RX packets to host. Overflows are not a problem because this
* variable is not necessary after both I2S and RX is started.
*/
uint8_t i2s_counter;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you move it down to the other uint8_t you could probably reduce the size of the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 5 bool variables before this uint8_t, so moving this uint8_t won't really save anything.

On nRF5340DK the sizeof(struct usb_i2s_ctx) is 24 bytes. When i2s_counter is moved to the end of structure the size remains unchanged at 24 bytes. Moving all pointers to the beginning also makes the size remain intact.

Because there are 9 single-byte members (5 bool and 4 uint8_t) separated into two "blocks", shuffling them around won't give any structure size reduction regardless if the pointer size is 4 or 8 bytes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, bool, "the default is CHAR_TYPE_SIZE"

tests:
sample.subsys.usb.uac2_implicit_feedback:
depends_on:
- usb_device
Copy link
Collaborator

@jfischer-no jfischer-no Jun 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must be - usbd (#73269 merged), sorry thought of it too late

jfischer-no
jfischer-no previously approved these changes Jun 11, 2024
@aescolar aescolar modified the milestones: v3.7.0, v4.0.0 Jun 17, 2024
@aescolar
Copy link
Member

Bulk changing the milestone from everything which did not make it to the v3.7.0 freeze deadline
and which is not labeled as a bug or documentation (or does not appear clearly as only containing
a bug fix or a documentation change).
If you disagree about this change please add the milestone again.

Please note that until rc2 only PRs containing bug fixes, docs and tests can be merged.
After that and until release only bug fixes and docs changes.

Exceptions require approval by the release team and a vote by the TSC.
https://docs.zephyrproject.org/latest/project/release_process.html#stabilization-phase

The sample illustates how to achieve bidirectional asynchronous audio.
Implicit feedback is the only way to achieve asynchronous USB headset
on devices that have only one isochronous IN and one isochronous OUT
endpoint.

The sample implements stereo playback and mono recording. While it would
be possible to have stereo recording, the commonly available headsets
are mono only. The number of channels can differ between audio sink and
source because the only requirement is that the two run on same clock.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
@nashif nashif merged commit d3e1bc8 into zephyrproject-rtos:main Aug 26, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: USB Universal Serial Bus Experimental Experimental features not enabled by default
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants