diff --git a/Cargo.toml b/Cargo.toml index 1f0888b..7515d93 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] } embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" } +numtoa = "0.2.4" + usbd-hid = "0.6.1" defmt = "0.3" @@ -23,4 +25,4 @@ panic-probe = { version = "0.3", features = ["print-defmt"] } [features] serial = [] -# default = ["serial"] \ No newline at end of file +default = ["serial"] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index fe657e9..628a8c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use usbd_hid::descriptor::MouseReport; use crate::{mouse_hid::mouse_config::MouseConfig, mouse_hid::MouseHID}; #[cfg(feature = "serial")] -use crate::usb_serial::Serial; +use crate::usb_serial::{Serial, SerialConfig}; use crate::mouse_sensor::{MouseSensor, MouseSensorPins}; @@ -88,7 +88,7 @@ where T: Instance, CSP: CsPin + 'd, { - let mut serial = Serial::new(usb); + let mut serial = Serial::new(usb, SerialConfig::new()); let usb_future = Serial::run_usb().await; @@ -104,7 +104,8 @@ where // pan: 0, // }; - serial.send_msg("test").await; + serial.send_number(x, 10).await; + serial.send_number(y, 10).await; } } }; diff --git a/src/mouse_sensor/wrapper.rs b/src/mouse_sensor/wrapper.rs index ea58f6b..8425704 100644 --- a/src/mouse_sensor/wrapper.rs +++ b/src/mouse_sensor/wrapper.rs @@ -66,7 +66,7 @@ where T: Instance, CSP: CsPin + 'd, { - spi_device: PAW3212DB_TJDT<'d, L, CSP, T>, + pub spi_device: PAW3212DB_TJDT<'d, L, CSP, T>, led: Output<'d, PIN_25>, } diff --git a/src/usb_serial/mod.rs b/src/usb_serial/mod.rs index 2edbaad..44e28e0 100644 --- a/src/usb_serial/mod.rs +++ b/src/usb_serial/mod.rs @@ -1,3 +1,7 @@ +mod serial_config; + +use numtoa::NumToA; + use core::future::Future; use embassy_rp::usb::Driver; @@ -6,6 +10,8 @@ use embassy_rp::{interrupt, peripherals::USB}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::{Builder, Config, UsbDevice}; +pub use serial_config::SerialConfig; + static mut DEVICE_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256]; static mut CONFIG_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256]; static mut BOS_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256]; @@ -19,16 +25,19 @@ pub struct Serial<'a> { } impl Serial<'static> { - pub fn new(usb: USB) -> Serial<'static> { + pub fn new(usb: USB, serial_config: SerialConfig<'static>) -> Serial<'static> { // Create the driver, from the HAL. let irq = interrupt::take!(USBCTRL_IRQ); let driver = Driver::new(usb, irq); // Create embassy-usb Config - let mut config = Config::new(0xc0de, 0xcafe); - config.manufacturer = Some("Embassy"); - config.product = Some("USB-serial example"); - config.serial_number = Some("12345678"); + let mut config = Config::new( + serial_config.vendor_id as u16, + serial_config.product_id as u16, + ); + config.manufacturer = Some(serial_config.manufacturer); + config.product = Some(serial_config.product); + config.serial_number = Some(serial_config.serial_number); config.max_power = 100; config.max_packet_size_0 = 64; @@ -68,7 +77,18 @@ impl Serial<'static> { unsafe { USB.as_mut().unwrap().run() } } - pub async fn send_msg(&mut self, msg: &str) { - self.class.write_packet(msg.as_bytes()).await.unwrap_or(()); + pub async fn send_msg(&mut self, s: &str) { + self.class.write_packet(s.as_bytes()).await.unwrap_or(()); + } + + pub async fn send_number(&mut self, i: T, base: I) + where + T: NumToA, + { + let mut buf = [0; 256]; + + let s = i.numtoa_str(base, &mut buf); + + self.send_msg(s).await; } }