Get it working
This commit is contained in:
parent
4eac78708b
commit
a31b23e072
3 changed files with 15 additions and 22 deletions
|
@ -8,7 +8,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embassy-executor = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
embassy-executor = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||||
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "pio", "critical-section-impl"] }
|
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "pio", "critical-section-impl"] }
|
||||||
embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt"] }
|
embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "msos-descriptor"] }
|
||||||
embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] }
|
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" }
|
embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" }
|
||||||
|
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -5,22 +5,11 @@
|
||||||
|
|
||||||
mod mouse_hid;
|
mod mouse_hid;
|
||||||
|
|
||||||
use core::future::Future;
|
|
||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
|
|
||||||
use embassy_futures::join::join;
|
use embassy_futures::join::join;
|
||||||
|
|
||||||
use embassy_rp::usb::Driver;
|
|
||||||
use embassy_rp::{interrupt, peripherals::USB};
|
|
||||||
|
|
||||||
use embassy_usb::class::hid::{HidWriter, ReportId, RequestHandler, State};
|
|
||||||
use embassy_usb::control::OutResponse;
|
|
||||||
use embassy_usb::{Builder, Config};
|
|
||||||
|
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
|
||||||
use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
|
use usbd_hid::descriptor::MouseReport;
|
||||||
|
|
||||||
use crate::mouse_hid::{MouseConfig, MouseHID};
|
use crate::mouse_hid::{MouseConfig, MouseHID};
|
||||||
|
|
||||||
|
@ -36,7 +25,7 @@ async fn main(_spawner: Spawner) {
|
||||||
vendor_id: 0x046d,
|
vendor_id: 0x046d,
|
||||||
product_id: 0x101b,
|
product_id: 0x101b,
|
||||||
manufacturer: "Logitech",
|
manufacturer: "Logitech",
|
||||||
product: "Marathon Mouse/Performance Plus M705",
|
product: "Performance Plus M705",
|
||||||
serial_number: "B14D65DA",
|
serial_number: "B14D65DA",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -44,15 +33,14 @@ async fn main(_spawner: Spawner) {
|
||||||
|
|
||||||
let usb_fut = MouseHID::run_usb().await;
|
let usb_fut = MouseHID::run_usb().await;
|
||||||
|
|
||||||
const PIXEL: i8 = 100;
|
const PIXEL: i8 = 2;
|
||||||
const WAIT_TIME: Duration = Duration::from_secs(1);
|
const WAIT_TIME: Duration = Duration::from_secs(10);
|
||||||
|
|
||||||
// Do stuff with the class!
|
// Do stuff with the class!
|
||||||
let hid_fut = async {
|
let hid_fut = async {
|
||||||
loop {
|
loop {
|
||||||
mouse_move(&mut mouse_hid, WAIT_TIME, PIXEL).await;
|
mouse_move(&mut mouse_hid, WAIT_TIME, PIXEL).await;
|
||||||
mouse_move(&mut mouse_hid, WAIT_TIME, -PIXEL).await;
|
mouse_move(&mut mouse_hid, Duration::from_millis(50), -PIXEL).await;
|
||||||
// mouse_move(&mut mouse_hid, Duration::from_millis(50), -PIXEL).await;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ use usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
|
||||||
static mut DEVICE_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
static mut DEVICE_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
||||||
static mut CONFIG_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
static mut CONFIG_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
||||||
static mut BOS_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
static mut BOS_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
||||||
|
static mut MSOS_DESCRIPTOR_BUFFER: [u8; 256] = [0; 256];
|
||||||
static mut CONTROL_BUFFER: [u8; 64] = [0; 64];
|
static mut CONTROL_BUFFER: [u8; 64] = [0; 64];
|
||||||
static mut STATE: Option<State<'static>> = None;
|
static mut STATE: Option<State<'static>> = None;
|
||||||
static mut USB: Option<UsbDevice<'static, Driver<'static, USB>>> = None;
|
static mut USB: Option<UsbDevice<'static, Driver<'static, USB>>> = None;
|
||||||
|
@ -35,12 +36,15 @@ impl MouseHID<'static> {
|
||||||
let irq = interrupt::take!(USBCTRL_IRQ);
|
let irq = interrupt::take!(USBCTRL_IRQ);
|
||||||
let driver = Driver::new(usb, irq);
|
let driver = Driver::new(usb, irq);
|
||||||
|
|
||||||
|
// Create embassy-usb Config
|
||||||
let mut config = Config::new(mouse_config.vendor_id, mouse_config.product_id);
|
let mut config = Config::new(mouse_config.vendor_id, mouse_config.product_id);
|
||||||
config.manufacturer = Some(mouse_config.manufacturer);
|
config.manufacturer = Some(mouse_config.manufacturer);
|
||||||
config.product = Some(mouse_config.product);
|
config.product = Some(mouse_config.product);
|
||||||
config.serial_number = Some(mouse_config.serial_number);
|
config.serial_number = Some(mouse_config.serial_number);
|
||||||
config.device_class = 0;
|
config.device_class = 0;
|
||||||
config.device_protocol = 2;
|
config.device_protocol = 2;
|
||||||
|
config.max_power = 100;
|
||||||
|
config.max_packet_size_0 = 64;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
STATE = Some(State::new());
|
STATE = Some(State::new());
|
||||||
|
@ -52,6 +56,7 @@ impl MouseHID<'static> {
|
||||||
unsafe { &mut DEVICE_DESCRIPTOR_BUFFER },
|
unsafe { &mut DEVICE_DESCRIPTOR_BUFFER },
|
||||||
unsafe { &mut CONFIG_DESCRIPTOR_BUFFER },
|
unsafe { &mut CONFIG_DESCRIPTOR_BUFFER },
|
||||||
unsafe { &mut BOS_DESCRIPTOR_BUFFER },
|
unsafe { &mut BOS_DESCRIPTOR_BUFFER },
|
||||||
|
unsafe { &mut MSOS_DESCRIPTOR_BUFFER },
|
||||||
unsafe { &mut CONTROL_BUFFER },
|
unsafe { &mut CONTROL_BUFFER },
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -89,17 +94,17 @@ impl MouseHID<'static> {
|
||||||
struct MyRequestHandler {}
|
struct MyRequestHandler {}
|
||||||
|
|
||||||
impl RequestHandler for MyRequestHandler {
|
impl RequestHandler for MyRequestHandler {
|
||||||
fn get_report(&self, id: ReportId, _buf: &mut [u8]) -> Option<usize> {
|
fn get_report(&self, _id: ReportId, _buf: &mut [u8]) -> Option<usize> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_report(&self, id: ReportId, data: &[u8]) -> OutResponse {
|
fn set_report(&self, _id: ReportId, _data: &[u8]) -> OutResponse {
|
||||||
OutResponse::Accepted
|
OutResponse::Accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_idle_ms(&self, id: Option<ReportId>, dur: u32) {}
|
fn set_idle_ms(&self, _id: Option<ReportId>, _dur: u32) {}
|
||||||
|
|
||||||
fn get_idle_ms(&self, id: Option<ReportId>) -> Option<u32> {
|
fn get_idle_ms(&self, _id: Option<ReportId>) -> Option<u32> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue