- Notifications
You must be signed in to change notification settings - Fork0
donRaphaco/usbd-midi
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A simple usb midi device class forusb-device.
Currently this aims to be a very simple implementation, that allows the microcontroller to send MIDI information to the PC and also receive MIDI information.
This crate requires the use of a hardware driver, that implements theusb-device traits.
Turn on the integrated LED of a STM32 BluePill board as long as C2 is pressed
fnmain() -> !{let dp = pac::Peripherals::take().unwrap();letmut rcc = dp.RCC.constrain();letmut gpioa = dp.GPIOA.split(&mut rcc.apb2);letmut gpioc = dp.GPIOC.split(&mut rcc.apb2);letmut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh); led.set_high().unwrap();letmut usb_dp = gpioa.pa12.into_push_pull_output(&mut gpioa.crh);let usb =Peripheral{usb: dp.USB,pin_dm: gpioa.pa11,pin_dp: usb_dp.into_floating_input(&mut gpioa.crh),};let usb_bus =UsbBus::new(usb);letmut midi =MidiClass::new(&usb_bus,1,1);letmut usb_dev =UsbDeviceBuilder::new(&usb_bus,UsbVidPid(0x16c0,0x5e4)).product("MIDI Test").device_class(USB_AUDIO_CLASS).device_sub_class(USB_MIDISTREAMING_SUBCLASS).build();constCHANNEL1:Channel =Channel::new(0);loop{if !usb_dev.poll(&mut[&mut midi]){continue;}letmut buffer =[0;64];ifletOk(size) = midi.read(&mut buffer){let buffer_reader =MidiPacketBufferReader::new(&buffer, size);for packetin buffer_reader.into_iter(){ifletOk(packet) = packet{match packet.message{MidiMessage::NoteOn(CHANNEL1,Note::C2, ..) =>{ led.set_low().unwrap();},MidiMessage::NoteOff(CHANNEL1,Note::C2, ..) =>{ led.set_high().unwrap();}, _ =>{}}}}}}}
CallingMidiClass::new(&usb_bus, N, M); withN, M >= 1 to provide morethan one input or output port requires thecontrol-buffer-256 feature ofthe usb-device crate:
Cargo.toml:
usb-device = { version = ">=0.2.1", features = ["control-buffer-256"] }Up to 5 in/out pairs can be used this way until we again run out of bufferspace. Note that exceeding the available buffer space will silently failto send the descriptors correctly, no obviouspanic! will hint theactual problem.
About
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- Rust100.0%