Skip to content

Commit d0da791

Browse files
committed
Boot up the USB Audio Class device
1 parent 0b88765 commit d0da791

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ harness = false
1616
[dependencies]
1717
bbqueue = "0.5.1"
1818
byte-slice-cast = { version = "1.2.1", default-features = false }
19+
bytemuck = "1.11.0"
1920
cortex-m = "0.7.5"
2021
cortex-m-rt = "0.7.1"
2122
cortex-m-rtic = "1.1.3"
@@ -24,10 +25,7 @@ defmt-rtt = "0.3.2"
2425
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
2526
stm32f4xx-hal = { version = "0.13.2", features = ["stm32f411", "rtic", "usb_fs", "i2s", "defmt"] }
2627
synopsys-usb-otg = { version = "0.3.0", features = ["fs"] }
27-
usb-device = { version = "0.2.3" }
28-
29-
# TEMP
30-
usbd-serial = "0.1.1"
28+
usb-device = { version = "0.2.8", features = ["control-buffer-256"] }
3129

3230
[patch.crates-io]
3331
stm32f4xx-hal = { git = "https://github.com/dgoodlad/stm32f4xx-hal", branch = "synopsys-otg-0.3.0" }

src/bin/main.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ mod app {
2222
use usb_device::prelude::*;
2323
use usb_device::bus::UsbBusAllocator;
2424

25-
use usbd_serial::SerialPort;
26-
2725
use bbqueue::{
2826
BBBuffer,
2927
Consumer,
3028
Producer,
3129
};
3230

3331
use crabdac_firmware::sof_timer::SofTimer;
32+
use crabdac_firmware::uac::{
33+
simple_stereo_output::SimpleStereoOutput,
34+
ClockCounter,
35+
};
3436

3537
const CHANNELS: usize = 2;
3638
const USB_SAMPLE_SIZE: usize = 4;
@@ -50,7 +52,7 @@ mod app {
5052
sof_timer: SofTimer<TIM2, PA0<Alternate<1>>>,
5153

5254
usb_dev: UsbDevice<'static, UsbBusType>,
53-
serial: SerialPort<'static, UsbBusType>
55+
usb_audio: SimpleStereoOutput<'static, UsbBusType>,
5456
}
5557

5658
#[monotonic(binds = TIM5, default = true)]
@@ -96,7 +98,12 @@ mod app {
9698

9799
*cx.local.usb_bus = Some(UsbBus::new(usb, cx.local.usb_ep_memory));
98100

99-
let serial = SerialPort::new(&cx.local.usb_bus.as_ref().unwrap());
101+
let usb_audio = SimpleStereoOutput::new(
102+
cx.local.usb_bus.as_ref().unwrap(),
103+
96000,
104+
4,
105+
24
106+
);
100107

101108
let usb_dev = UsbDeviceBuilder::new(cx.local.usb_bus.as_ref().unwrap(), UsbVidPid(0x1209, 0x0001))
102109
.manufacturer("Crabs Pty Ltd.")
@@ -115,7 +122,7 @@ mod app {
115122
consumer,
116123
sof_timer,
117124
usb_dev,
118-
serial,
125+
usb_audio,
119126
},
120127
init::Monotonics(mono),
121128
)
@@ -132,18 +139,18 @@ mod app {
132139

133140
#[inline(never)]
134141
#[link_section = ".data.usb_handler"]
135-
#[task(binds = OTG_FS, local = [producer, usb_dev, serial])]
142+
#[task(binds = OTG_FS, local = [producer, usb_dev, usb_audio])]
136143
fn usb_handler(cx: usb_handler::Context) {
137144
let producer: &mut bbqueue::Producer<'static, BUFFER_SIZE> = cx.local.producer;
138145
let usb_dev: &mut UsbDevice<UsbBusType> = cx.local.usb_dev;
139-
let serial: &mut SerialPort<UsbBusType> = cx.local.serial;
146+
let usb_audio: &mut SimpleStereoOutput<UsbBusType> = cx.local.usb_audio;
140147

141148
// TODO replace this with real USB data
142149
let bytes_received: usize = MAX_FRAME_SIZE;
143150
let data: [u8; MAX_FRAME_SIZE] = [0; MAX_FRAME_SIZE];
144151
let volume_amp: i32 = 1;
145152

146-
while usb_dev.poll(&mut [serial]) {
153+
while usb_dev.poll(&mut [usb_audio]) {
147154
}
148155

149156
//match producer.grant_exact(bytes_received) {

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#![no_main]
22
#![no_std]
33

4-
use stm32f4xx_hal as _; // memory layout
4+
use stm32f4xx_hal as hal; // memory layout
55
use defmt_rtt as _; // global logger
66
use panic_probe as _;
77

88
pub mod sof_timer;
9+
pub mod uac;
910

1011
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
1112
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked

0 commit comments

Comments
 (0)