feat(faderboard): add echo serial usb interface
This commit is contained in:
parent
3cac6c3e37
commit
4ce5d0a1b3
|
@ -40,12 +40,6 @@ dependencies = [
|
|||
"vcell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||
|
||||
[[package]]
|
||||
name = "cast"
|
||||
version = "0.2.7"
|
||||
|
@ -84,7 +78,7 @@ checksum = "f0f6f3e36f203cfedbc78b357fb28730aa2c6dc1ab060ee5c2405e843988d3c7"
|
|||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -97,12 +91,6 @@ dependencies = [
|
|||
"void",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||
|
||||
[[package]]
|
||||
name = "faderboard"
|
||||
version = "0.1.0"
|
||||
|
@ -111,27 +99,8 @@ dependencies = [
|
|||
"cortex-m-rt",
|
||||
"panic-halt",
|
||||
"stm32f0xx-hal",
|
||||
"usb-device 0.3.2",
|
||||
"usbd-hid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapless"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||
dependencies = [
|
||||
"hash32",
|
||||
"stable_deref_trait",
|
||||
"usb-device",
|
||||
"usbd-serial",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -155,12 +124,6 @@ version = "0.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.86"
|
||||
|
@ -218,42 +181,6 @@ version = "0.7.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.204"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.204"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.71",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ssmarshal"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3e6ad23b128192ed337dfa4f1b8099ced0c2bf30d61e551b65fda5916dbb850"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||
|
||||
[[package]]
|
||||
name = "stm32-usbd"
|
||||
version = "0.6.0"
|
||||
|
@ -261,7 +188,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c6c94998f166d66b210a164648a0b7866428d8f1e0740bf8a4c5edd89d4750c1"
|
||||
dependencies = [
|
||||
"cortex-m",
|
||||
"usb-device 0.2.9",
|
||||
"usb-device",
|
||||
"vcell",
|
||||
]
|
||||
|
||||
|
@ -304,17 +231,6 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.71"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
@ -328,48 +244,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "1f6cc3adc849b5292b4075fc0d5fdcf2f24866e88e336dd27a8943090a520508"
|
||||
|
||||
[[package]]
|
||||
name = "usb-device"
|
||||
version = "0.3.2"
|
||||
name = "usbd-serial"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98816b1accafbb09085168b90f27e93d790b4bfa19d883466b5e53315b5f06a6"
|
||||
checksum = "db75519b86287f12dcf0d171c7cf4ecc839149fe9f3b720ac4cfce52959e1dfe"
|
||||
dependencies = [
|
||||
"heapless",
|
||||
"portable-atomic",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "usbd-hid"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41a2d4546ca3e6a5c6a85584e5caf29feabf3ec35d6cd6b772eb35bd3cff7256"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"ssmarshal",
|
||||
"usb-device 0.3.2",
|
||||
"usbd-hid-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "usbd-hid-descriptors"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcbee8c6735e90894fba04770bc41e11fd3c5256018856e15dc4dd1e6c8a3dd1"
|
||||
dependencies = [
|
||||
"bitfield",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "usbd-hid-macros"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "261079a9ada015fa1acac7cc73c98559f3a92585e15f508034beccf6a2ab75a2"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"serde",
|
||||
"syn 1.0.109",
|
||||
"usbd-hid-descriptors",
|
||||
"embedded-hal",
|
||||
"nb 0.1.3",
|
||||
"usb-device",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -10,5 +10,5 @@ cortex-m = "0.7.7"
|
|||
cortex-m-rt = "0.7.3"
|
||||
panic-halt = "0.2.0"
|
||||
stm32f0xx-hal = { git = "https://github.com/lujoga/stm32f0xx-hal.git", branch = "v0.18.0-backports", features = ["rt", "stm32f072", "stm32-usbd"] }
|
||||
usb-device = "0.3.2"
|
||||
usbd-hid = "0.7.0"
|
||||
usb-device = "0.2.9"
|
||||
usbd-serial = "0.1.1"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#![no_main]
|
||||
|
||||
mod touch;
|
||||
mod usb;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
|
||||
|
@ -13,9 +14,12 @@ use hal::adc::Adc;
|
|||
use hal::pac::Peripherals;
|
||||
use hal::prelude::*;
|
||||
use hal::pwm;
|
||||
use hal::usb::{Peripheral, UsbBus};
|
||||
|
||||
use touch::Touch;
|
||||
|
||||
use usb::Usb;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut p = Peripherals::take().unwrap();
|
||||
|
@ -49,8 +53,6 @@ fn main() -> ! {
|
|||
pwm6_pin, // TIM1_CH1
|
||||
tx, // USART1_TX
|
||||
rx, // USART1_RX
|
||||
usb_dm, // USB_DM
|
||||
usb_dp, // USB_DP
|
||||
mut dir5, // PA13
|
||||
mut dir4, // PA14
|
||||
mut dir3, // PA15
|
||||
|
@ -88,8 +90,6 @@ fn main() -> ! {
|
|||
gpioa.pa8.into_alternate_af2(cs),
|
||||
gpioa.pa9.into_alternate_af1(cs),
|
||||
gpioa.pa10.into_alternate_af1(cs),
|
||||
gpioa.pa11,
|
||||
gpioa.pa12,
|
||||
gpioa.pa13.into_push_pull_output(cs),
|
||||
gpioa.pa14.into_push_pull_output(cs),
|
||||
gpioa.pa15.into_push_pull_output(cs),
|
||||
|
@ -117,6 +117,13 @@ fn main() -> ! {
|
|||
)
|
||||
});
|
||||
|
||||
let usb_bus = UsbBus::new(Peripheral {
|
||||
usb: p.USB,
|
||||
pin_dm: gpioa.pa11,
|
||||
pin_dp: gpioa.pa12,
|
||||
});
|
||||
let mut usb = Usb::new(&usb_bus);
|
||||
|
||||
let mut _adc = Adc::new(p.ADC, &mut rcc);
|
||||
|
||||
let mut _pwm1 = pwm::tim16(p.TIM16, pwm1_pin, &mut rcc, 250.khz());
|
||||
|
@ -128,5 +135,7 @@ fn main() -> ! {
|
|||
|
||||
touch.setup();
|
||||
|
||||
loop {}
|
||||
loop {
|
||||
usb.poll();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
use stm32f0xx_hal::usb::UsbBusType;
|
||||
|
||||
use usb_device::bus::UsbBusAllocator;
|
||||
use usb_device::prelude::*;
|
||||
|
||||
use usbd_serial::SerialPort;
|
||||
|
||||
/// pid.codes VID
|
||||
const VENDOR_ID: u16 = 0x1209;
|
||||
|
||||
/// pid.codes Test PID - do not use outside of testing!
|
||||
/// TODO: apply for unique PID once project is finished
|
||||
const PRODUCT_ID: u16 = 0x0006;
|
||||
|
||||
pub struct Usb<'a> {
|
||||
usb_dev: UsbDevice<'a, UsbBusType>,
|
||||
serial: SerialPort<'a, UsbBusType>,
|
||||
}
|
||||
|
||||
impl<'a> Usb<'a> {
|
||||
pub fn new(usb_bus: &'a UsbBusAllocator<UsbBusType>) -> Self {
|
||||
let usb_dev = UsbDeviceBuilder::new(usb_bus, UsbVidPid(VENDOR_ID, PRODUCT_ID))
|
||||
.manufacturer("lujoga")
|
||||
.product("faderboard")
|
||||
.max_power(500)
|
||||
.build();
|
||||
|
||||
let serial = SerialPort::new(&usb_bus);
|
||||
|
||||
Usb { usb_dev, serial }
|
||||
}
|
||||
|
||||
pub fn poll(&mut self) {
|
||||
if self.usb_dev.poll(&mut [&mut self.serial]) {
|
||||
let mut buf = [0u8; 64];
|
||||
if let Ok(count) = self.serial.read(&mut buf[..]) {
|
||||
let _ = self.serial.write(&buf[..count]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue