Skip to content

WIP: platform: esp32s3: add Waveshare standalone ultrasonic gesture sensing - #11626

Draft
lgirdwood wants to merge 23 commits into
thesofproject:mainfrom
lgirdwood:topic/esp32s3-ultrasound
Draft

lgirdwood wants to merge 23 commits into
thesofproject:mainfrom
lgirdwood:topic/esp32s3-ultrasound

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

Adds standalone hostless ultrasonic Doppler gesture and presence sensing on the Waveshare ESP32-S3-CAM-OV5640 board (ES8311 speaker DAC + dual ES7210 microphones over full-duplex I2S0), reporting Event ABI v2 gestures over both 48-byte USB HID (/dev/hidrawX) and USB CDC-ACM (US_EVENT) with zero host audio DMA.

Stacked on #11522 (lgirdwood:feature/mcu-ports, paired with lgirdwood/zephyr:feature/mcu-dai-ports in west.yml) and shares the core ultrasonic TX/RX module & Event ABI v2 updates with #11576 (lgirdwood:topic/ultrasound-gesture).

Commits (above feature/mcu-ports)

  1. audio: ultrasound: add ultrasonic TX/RX Doppler gesture modules and DT binding
    • Hostless ultrasound_tx (phase-continuous carrier + Approach B duty-cycled bursting with in-DSP presence auto-boost) and ultrasound_rx (Q23 mixer, CIC decimation, 64-pt Hann FFT, slew-limited per-bin stationary clutter tracker, sub-hop (+ -> -) stereo zero-crossing swipe/tap detection, sustained Push/Pull gating).
    • Adds sof,ultrasound-config.yaml Devicetree binding and dts_root in zephyr/module.yml.
  2. platform: esp32s3: add Waveshare standalone ultrasonic sensing and USB HID reporter
    • Static hostless TX/RX pipelines (esp32s3_pipeline_def.c), Waveshare calibration overlay (esp32s3_cam_ov5640_ultrasound.overlay — 19.5 kHz carrier, 13% TX amplitude, 34 mm mic baseline), USB HID + CDC event transport (ultrasound_usb_event.c), interactive us shell commands, host monitor script (scripts/ultrasound_usb_monitor.py), and sof bootloader ROM download entry.
  3. audio: ultrasound: add Event ABI v2 kinematics and fix Push/Pull edge cases
    • Upgrades struct sof_ultrasound_event to Event ABI v2 (56 B: duration_ms, displacement_mm, pos_x_permille, zc_lag_ms_q2, proximity; TX/RX config structs stay ABI v1).
    • Adds 64 ms Pull defer + immediate flush on +1 reversal, Push rescue on radial (|lag| < 10 ms) ZC recoil and 1-ch ZC timeout with withdrawal tail suppression, brief-jab TAP cap (<= 10 approach hops), and 100 ms push_quiet_ms.
  4. platform: esp32s3: upgrade Waveshare ultrasound USB HID/CDC to ABI v2 and add mic mask diag
    • Bumps USB HID report descriptor and struct sof_ultrasound_usb_hid_report from 32 B to 48 B (ABI v2) and updates US_EVENT CDC output and scripts/ultrasound_usb_monitor.py (supports v1 & v2).
    • Adds waveshare_mic_mask() (ES7210 MIC1/MIC2 PGA gain control) and us mic <0..3> shell diagnostic command.

Companion Zephyr Fixes (lgirdwood/zephyr:feature/mcu-dai-ports)

  • b5af4b18eab: drivers: dai: esp32: fix ESP32-S3 full-duplex I2S0 RX clock lock and L/R alignment (20 MHz integer RX oversampling clock, DAI_TRIGGER_PRE_START pre-DMA RX/AFIFO reset, deterministic WS 0->1 + 6 us start).
  • b4e88b7b3dc: drivers: dma: esp32_gdma: disable RX owner check on circular audio rings (prevents IN_DSCR_ERR GDMA halt and mid-stream I2S0 RX AFIFO L/R halfword slip during CPU/USB/I2C load).

Hardware Verification (Waveshare ESP32-S3-CAM-OV5640)

  • I2S0 L/R alignment & GDMA stability: 10/10 cold hard resets (in_conf1=0x200c, in_int_raw=0x0, physical ES7210 MIC1 -> ch0 / MIC2 -> ch1) and 20/20 RX-only restarts with zero channel swaps.
  • Gestures & Event ABI v2: Live verified SWIPE_LEFT, SWIPE_RIGHT, PULL, PUSH, TAP, and PRESENCE_DETECTED/PRESENCE_LOST with duration, displacement, lateral position (L/C/R), proximity, and zero-crossing lag over USB HID and CDC.

… unsigned int

Align drc_arm.c helper signatures and local loop/index variables with
commit 1fe1b8c ("audio: drc: use size_t for byte, sample and frame
counts"):
- Use size_t for byte, division frame, and loop indices (nbyte,
  div_start, count, i, j, inc).
- Use unsigned int for channel counts and indices (nch, ch).
- Use bool for boolean flags (is_release, is_releasing, is_bad_db,
  is_2byte).

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
… builds

Allow CONFIG_SOF_FULL_ZEPHYR_APPLICATION targets without CONFIG_USERSPACE
(such as single-core ARM Cortex-M microcontrollers) to build cleanly:
- Guard generated <zephyr/syscalls/*.h> includes with CONFIG_USERSPACE and
  map syscall wrappers directly to z_impl_* functions when userspace is
  disabled.
- Set Cortex-M cache line fallback alignment to 32 bytes in rtos/cache.h
  while preserving 64 bytes for host/POSIX library builds.
- Ensure generated sof_versions.h and uuid-registry.h are created and
  added to include paths before building SOF subdirectories and app.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Wire up NXP i.MX SAI, S/PDIF, ESAI, and MICFIL DAI types in IPC4/IPC3 DAI
lookup and DMA device mapping so Zephyr-based NXP i.MX / i.MX RT platforms
can instantiate SAI and S/PDIF Copiers in IPC4 pipelines.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…ine capture

- Add CONFIG_ZEPHYR_DOMAIN_AUDIO_TIMER to drive the Zephyr LL scheduling
  domain directly from hardware DAI DMA period completion callbacks while
  suppressing SysTick k_timer ticks when audio is active.
- Scope eDMA source/destination address increment setup in dai-zephyr.c
  to NXP i.MX DAI types.
- Allow DAI component state transitions in dai_comp_trigger_internal() when
  CONFIG_STATIC_PIPELINE is enabled alongside IPC4.
- Pass (dma_fmt, local_fmt) instead of (local_fmt, dma_fmt) to
  pcm_get_conversion_function() for capture streams in
  set_new_local_buffer().
- Reset static pipelines cleanly on XRUN recovery when host IPC stream
  structures are absent.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…ipeline bridge

- Add the COMP_USB_AUDIO host endpoint component with lock-free SPSC
  playback/capture ring buffers and asynchronous USB SOF-to-DAI rate
  estimation for explicit UAC2 feedback.
- Extend upstream static_pipeline_uac2.c to bridge Zephyr UAC2 callbacks
  with COMP_USB_AUDIO ring buffers, support zero-copy UAC2 capture double-
  buffer replenishment via static_pipeline_uac2_buf_release(), and query
  the playback rate adjustment for USB feedback.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add Sound Open Firmware platform and board support for PJRC Teensy 4.1
(NXP i.MX RT1062 Cortex-M7 @ 600 MHz):
- src/platform/teensy41/: pure SOF platform initialization, clocks, memory
  layout, and upstream static_pipeline descriptor graph (USB Audio <->
  Volume <-> S/PDIF or SAI1 I2S Copier).
- zephyr/lib/{alloc.c,dma.c}: static SOF heap and eDMA0 registration.
- app/boards/teensy41.{conf,overlay} & app/src/: Zephyr UAC2 composite
  device initialization, HalfKay bootloader soft-reboot request (0xFB),
  and upstream static_pipeline startup.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…priority

- static_pipeline_loader: pause pipelines cleanly instead of hard component resets on stop, cancel pipe_task before COMP_TRIGGER_STOP, and restore cached kcontrols on restart
- static_pipeline_uac2: unify SOF-driven LL pipeline copy without synchronous UAC2 copy hacks, preserve effect bypass switches on mute, and maintain continuous ISO IN streaming on Teensy/RP2350/nRF54LM20
- boards: set CONFIG_LL_THREAD_PRIORITY=-16 (cooperative) across RP2350, Teensy 4.1, and nRF54LM20 to prevent usbd_thread (-8) preemption mid-pipeline_copy()
- usb_audio / i2s_audio / dai-zephyr / pipeline-stream / platform defs: add adaptive TDM rate-matching and clean non-module-adapter endpoint handling
- eq_iir / drc_arm / volume: support float and fixed-point MCU pipeline configurations cleanly

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…upport

- Add esp32s3_cam_ov5640_esp32s3_procpu config and overlay (UAC2, CDC-ACM, I2C0, I2S0 GPIO10-14 with 256*fs MCLK)
- Add Waveshare codec driver for CH32V003 PA control (0x24), ES8311 DAC (0x18), and ES7210 dual-mic ADC (0x40)
- Default ESP32-S3 topology to I2S master clock mode on Waveshare OV5640, initialize codecs after topology setup, sync codec rate on UAC2 rate changes, and identify board as 'SOF ESP32S3 Waveshare CAM'

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…T binding

Add hostless ultrasonic carrier TX and stereo Doppler gesture/presence RX
modules with Approach B in-DSP presence feedback, slew-limited per-bin
stationary clutter rejection, steady-floor sideband SNR gating, sub-hop
(+ -> -) Doppler zero-crossing stereo swipe/tap classification, and
deliberate Push/Pull stroke gating with continuous-tail suppression.

Add Zephyr Devicetree binding (sof,ultrasound-config.yaml) and register
dts_root in zephyr/module.yml so static MCU pipelines supply per-board
acoustic and geometry tuning declaratively.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…B HID reporter

Add standalone hostless ultrasonic TX/RX static pipelines, Devicetree
per-board calibration overlay (19.5 kHz carrier, 13% linear TX amplitude,
34 mm dual ES7210 mic / 45 mm centered speaker geometry), 32-byte USB HID
and CDC-ACM event reporting, interactive 'us' shell diagnostics, host
monitor script, and hands-free 'sof bootloader' ROM download entry.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
… cases

Upgrade struct sof_ultrasound_event to Event ABI v2 (56 bytes, backward
compatible for the first 40 bytes; TX/RX config blobs remain ABI v1) by
adding duration_ms, displacement_mm, pos_x_permille, zc_lag_ms_q2, and
proximity telemetry across gesture and presence events.

Improve Push and Pull gesture reliability:
- Defer PULL emission by 64 ms (capped at 1200 ms) to capture full stroke
  duration and radial displacement, and flush any qualified pending PULL
  immediately on a +1 approach reversal so quick return strokes never drop
  the Pull.
- Rescue qualified sustained PUSH strokes (>= 6 active hops, >= 25 Hz
  peak Doppler, >= 3 stereo hops) when hand recoil triggers a radial
  (|lag| < 10 ms) stereo zero-crossing or 1-channel zero-crossing timeout,
  while suppressing the subsequent withdrawal tail.
- Cap TAP classification to brief jabs (<= 10 approach hops) so sustained
  Pushes are not absorbed as Taps or discarded as NONE, and tighten
  push_quiet_ms to 100 ms.

Verified live on Waveshare ESP32-S3-CAM-OV5640 hardware.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
… and add mic mask diag

Update the Waveshare ESP32-S3-CAM-OV5640 ultrasonic HID report descriptor
and struct sof_ultrasound_usb_hid_report from 32 to 48 bytes (ABI v2),
adding duration_ms, displacement_mm, pos_x_permille, zc_lag_ms_q2, and
proximity fields to both USB HID input reports and CDC-ACM US_EVENT lines.

Update scripts/ultrasound_usb_monitor.py to decode both v1 (32 B) and v2
(48 B) HID/CDC events with formatted duration, displacement, lateral
position (L/C/R), proximity (FAR/MID/NEAR), and zero-crossing lag.

Add waveshare_mic_mask() (ES7210 MIC1/MIC2 analog PGA gain control) and
the 'us mic <0..3>' shell diagnostic command to verify physical L/R mic
channel alignment.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…t passthrough

Static IPC4 volume components initialize at 0 dB (VOL_ZERO_DB) and enter
passthrough mode (scale_vol = vol_passthrough_*). Subsequent static
kcontrol volume updates wrote cd->volume[] without clearing is_passthrough
or refreshing scale_vol, leaving UAC2 Master Playback Volume stuck at 0 dB.

Serialize vol_static_apply_volume(), vol_static_apply_volume_chan(), and
vol_static_apply_switch() under a spinlock, clear is_passthrough, mark
copy_gain = true, refresh scale_vol when prepared, and keep
ramp_finished = true for non-ramped static controls so live 0%..100%
volume changes do not flap in and out of passthrough mid-stream.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add a fixed-point 4th-order (2-biquad) Butterworth low-pass guard filter
(fc = 14 kHz at 48 kHz, Q28 coefficients, Q27 state) applied to additive
host playback audio before summing the ultrasonic carrier across S16_LE,
S24_4LE, and S32_LE paths.

Keeps audible playback flat (< 0.5 dB through 12 kHz) while attenuating
19.25..20.5 kHz playback content by > 30..38 dB so bright music/speech
cannot bleed into the ultrasonic Doppler passband. Bypassed completely
when ultrasound TX is disabled or running standalone.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…onic sensing

Add a combined UAC2 speaker playback + ultrasonic gesture sensing mode
for Waveshare ESP32-S3-CAM-OV5640 (esp32s3_cam_ov5640_ultrasound_audio):
- Wire Pipeline 1 as USB_PB (5) -> VOL_PB (6) -> ULTRASOUND_TX (1, additive)
  -> DAI_I2S_PB (2) so host playback volume/mute scales only audio while
  the 19.5 kHz carrier and Pipeline 2 RX gesture sensing stay uninterrupted.
- Keep Pipeline 1 running when host playback stops, flush the USB playback
  ring via usb_audio_flush_playback(), and skip redundant 48 kHz I2C codec
  re-programming in waveshare_codec_set_rate().
- Set ES8311 DAC output register 0x32 to 0xBF (0.0 dB unity instead of
  0xCC +6.5 dB boost) to prevent internal DAC clipping and chord-beat IMD
  when summing audio and ultrasonic carrier, with 20% TX carrier in the
  combined overlay.
- Use playback-only UAC2 ISO OUT (disabling UAC2 capture ISO IN and DWC2
  hibernation) so ESP32-S3's DWC2 IN TX FIFOs cleanly serve CDC-ACM +
  48-byte USB HID ABI v2 concurrently with UAC2 playback.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants