Skip to content

Commit ab10d5b

Browse files
committed
Added example for ESP32-S3
1 parent 1abc02e commit ab10d5b

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[target.xtensa-esp32s3-none-elf]
2+
runner = "espflash flash --monitor"
3+
4+
[build]
5+
rustflags = ["-C", "link-arg=-nostartfiles", "-C", "link-arg=-Wl,-Tlinkall.x"]
6+
target = "xtensa-esp32s3-none-elf"
7+
8+
[unstable]
9+
build-std = ["core", "alloc"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/.vscode
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "example-esp32s3"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
esp-hal = { version = "0.22", features = ["esp32s3"] }
8+
esp-backtrace = { version = "0.14.2", features = [
9+
"esp32s3",
10+
"panic-handler",
11+
"println",
12+
] }
13+
esp-println = { version = "0.12.0", features = ["esp32s3", "log"] }
14+
usb-device = { version = "0.3.2", features = ["control-buffer-256"] }
15+
usbd-midi = { path = "../../" }
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "esp"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//! Example for ESP32-S3.
2+
3+
#![no_std]
4+
#![no_main]
5+
6+
use core::ptr::addr_of_mut;
7+
8+
use esp_backtrace as _;
9+
use esp_println::println;
10+
use usb_device::prelude::*;
11+
use usbd_midi::{
12+
data::usb_midi::midi_packet_reader::MidiPacketBufferReader, midi_device::MidiClass,
13+
};
14+
15+
static mut EP_MEMORY: [u32; 1024] = [0; 1024];
16+
17+
#[esp_hal::xtensa_lx_rt::entry]
18+
fn main() -> ! {
19+
let mut config = esp_hal::Config::default();
20+
config.cpu_clock = esp_hal::clock::CpuClock::Clock240MHz;
21+
let peripherals = esp_hal::init(config);
22+
23+
let usb_bus_allocator = esp_hal::otg_fs::UsbBus::new(
24+
esp_hal::otg_fs::Usb::new(peripherals.USB0, peripherals.GPIO20, peripherals.GPIO19),
25+
unsafe { &mut *addr_of_mut!(EP_MEMORY) },
26+
);
27+
28+
let mut midi_class = MidiClass::new(&usb_bus_allocator, 1, 1).unwrap();
29+
30+
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus_allocator, UsbVidPid(0x16c0, 0x5e4))
31+
.device_class(0)
32+
.device_sub_class(0)
33+
.strings(&[StringDescriptors::default()
34+
.manufacturer("Music Company")
35+
.product("MIDI Device")
36+
.serial_number("12345678")])
37+
.unwrap()
38+
.build();
39+
40+
loop {
41+
if usb_dev.poll(&mut [&mut midi_class]) {
42+
let mut buffer = [0; 64];
43+
if let Ok(size) = midi_class.read(&mut buffer) {
44+
let buffer_reader = MidiPacketBufferReader::new(&buffer, size);
45+
for packet in buffer_reader.into_iter() {
46+
if let Ok(packet) = packet {
47+
println!("{:?}", packet);
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)