RKTK API Docs RKTK Home Repo

rktk_drivers_common/usb/
mod.rs

1//! USB reporter implementation using [`embassy_usb`].
2
3use core::sync::atomic::AtomicBool;
4
5mod builder;
6#[cfg(feature = "defmt-usb")]
7mod defmt_logger;
8mod driver;
9mod handler;
10mod raw_hid;
11mod rrp;
12mod task;
13
14#[cfg(feature = "usb-remote-wakeup")]
15type RemoteWakeupSignal = rktk::utils::Signal<()>;
16type ReadySignal = rktk::utils::Signal<()>;
17static SUSPENDED: AtomicBool = AtomicBool::new(false);
18
19pub use builder::CommonUsbReporterBuilder;
20/// Re-export of underlying embassy-usb driver's config type
21pub use embassy_usb::Config as UsbDriverConfig;
22
23/// Options for the [`CommonUsbReporterDriverBuilder`].
24pub struct CommonUsbDriverConfig<D: embassy_usb::driver::Driver<'static>> {
25    /// embassy-usb driver instance.
26    pub driver: D,
27    /// Config for underlying embassy-usb driver.
28    pub driver_config: UsbDriverConfig<'static>,
29    /// USB Poll interval for mouse in ms.
30    pub mouse_poll_interval: u8,
31    /// USB Poll interval for keyboard in ms.
32    pub keyboard_poll_interval: u8,
33    /// If this is set to true, defmt-usb logger waits for DTR signal before log output.
34    /// This allows you to view logs recorded before the logger client is started.
35    #[cfg(feature = "defmt-usb")]
36    pub defmt_usb_use_dtr: bool,
37}
38
39impl<D: embassy_usb::driver::Driver<'static>> CommonUsbDriverConfig<D> {
40    /// Create usb options for the driver with default options.
41    ///
42    /// * `driver`: embassy-usb driver instance
43    /// * `vid`: USB vendor ID
44    /// * `pid`: USB product ID
45    pub fn new(driver: D, mut driver_config: UsbDriverConfig<'static>) -> Self {
46        driver_config.supports_remote_wakeup = cfg!(feature = "usb-remote-wakeup");
47        Self {
48            driver_config,
49            mouse_poll_interval: 1,
50            keyboard_poll_interval: 1,
51            driver,
52            #[cfg(feature = "defmt-usb")]
53            defmt_usb_use_dtr: true,
54        }
55    }
56}