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]
|
||||
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-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-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;
|
||||
|
||||
use core::future::Future;
|
||||
|
||||
use embassy_executor::Spawner;
|
||||
|
||||
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 usbd_hid::descriptor::{MouseReport, SerializedDescriptor};
|
||||
use usbd_hid::descriptor::MouseReport;
|
||||
|
||||
use crate::mouse_hid::{MouseConfig, MouseHID};
|
||||
|
||||
|
@ -36,7 +25,7 @@ async fn main(_spawner: Spawner) {
|
|||
vendor_id: 0x046d,
|
||||
product_id: 0x101b,
|
||||
manufacturer: "Logitech",
|
||||
product: "Marathon Mouse/Performance Plus M705",
|
||||
product: "Performance Plus M705",
|
||||
serial_number: "B14D65DA",
|
||||
},
|
||||
)
|
||||
|
@ -44,15 +33,14 @@ async fn main(_spawner: Spawner) {
|
|||
|
||||
let usb_fut = MouseHID::run_usb().await;
|
||||
|
||||
const PIXEL: i8 = 100;
|
||||
const WAIT_TIME: Duration = Duration::from_secs(1);
|
||||
const PIXEL: i8 = 2;
|
||||
const WAIT_TIME: Duration = Duration::from_secs(10);
|
||||
|
||||
// Do stuff with the class!
|
||||
let hid_fut = async {
|
||||
loop {
|
||||
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 CONFIG_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 STATE: Option<State<'static>> = 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 driver = Driver::new(usb, irq);
|
||||
|
||||
// Create embassy-usb Config
|
||||
let mut config = Config::new(mouse_config.vendor_id, mouse_config.product_id);
|
||||
config.manufacturer = Some(mouse_config.manufacturer);
|
||||
config.product = Some(mouse_config.product);
|
||||
config.serial_number = Some(mouse_config.serial_number);
|
||||
config.device_class = 0;
|
||||
config.device_protocol = 2;
|
||||
config.max_power = 100;
|
||||
config.max_packet_size_0 = 64;
|
||||
|
||||
unsafe {
|
||||
STATE = Some(State::new());
|
||||
|
@ -52,6 +56,7 @@ impl MouseHID<'static> {
|
|||
unsafe { &mut DEVICE_DESCRIPTOR_BUFFER },
|
||||
unsafe { &mut CONFIG_DESCRIPTOR_BUFFER },
|
||||
unsafe { &mut BOS_DESCRIPTOR_BUFFER },
|
||||
unsafe { &mut MSOS_DESCRIPTOR_BUFFER },
|
||||
unsafe { &mut CONTROL_BUFFER },
|
||||
);
|
||||
|
||||
|
@ -89,17 +94,17 @@ impl MouseHID<'static> {
|
|||
struct 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
|
||||
}
|
||||
|
||||
fn set_report(&self, id: ReportId, data: &[u8]) -> OutResponse {
|
||||
fn set_report(&self, _id: ReportId, _data: &[u8]) -> OutResponse {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue