Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

donRaphaco/usbd-midi

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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.

Example

Receive MIDI

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();},                        _ =>{}}}}}}}

Using more than one MIDI port

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

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust100.0%

[8]ページ先頭

©2009-2025 Movatter.jp