Skip to main content
RKTK API Docs RKTK Home Repo

rktk_drivers_common/trouble/reporter/
mod.rs

1use driver::TroubleReporter;
2use rand_core::{CryptoRng, RngCore};
3use rktk::{drivers::interface::wireless::WirelessReporterDriverBuilder, utils::Channel};
4use trouble_host::{Controller, gap::PeripheralConfig};
5
6mod driver;
7mod server;
8mod task;
9
10enum Report {
11    Keyboard(usbd_hid::descriptor::KeyboardReport),
12    MediaKeyboard(usbd_hid::descriptor::MediaKeyboardReport),
13    Mouse(usbd_hid::descriptor::MouseReport),
14}
15
16static OUTPUT_CHANNEL: Channel<Report, 4> = Channel::new();
17
18pub struct TroubleReporterConfig {
19    pub advertise_name: &'static str,
20    pub peripheral_config: Option<PeripheralConfig<'static>>,
21}
22
23pub struct TroubleReporterBuilder<
24    C: Controller + 'static,
25    RNG: RngCore + CryptoRng + 'static,
26    const CONNECTIONS_MAX: usize,
27    const L2CAP_CHANNELS_MAX: usize,
28    const L2CAP_MTU: usize,
29> {
30    controller: C,
31    rng: &'static mut RNG,
32    config: TroubleReporterConfig,
33}
34
35impl<
36    C: Controller + 'static,
37    RNG: RngCore + CryptoRng,
38    const CONNECTIONS_MAX: usize,
39    const L2CAP_CHANNELS_MAX: usize,
40    const L2CAP_MTU: usize,
41> TroubleReporterBuilder<C, RNG, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX, L2CAP_MTU>
42{
43    pub fn new(controller: C, rng: &'static mut RNG, config: TroubleReporterConfig) -> Self {
44        Self { controller, rng, config }
45    }
46}
47
48impl<
49    C: Controller + 'static,
50    RNG: RngCore + CryptoRng,
51    const CONNECTIONS_MAX: usize,
52    const L2CAP_CHANNELS_MAX: usize,
53    const L2CAP_MTU: usize,
54> WirelessReporterDriverBuilder
55    for TroubleReporterBuilder<C, RNG, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX, L2CAP_MTU>
56{
57    type Output = TroubleReporter;
58
59    type Error = ();
60
61    async fn build(
62        self,
63    ) -> Result<(Self::Output, impl Future<Output = ()> + 'static), Self::Error> {
64        Ok((
65            TroubleReporter { output_tx: OUTPUT_CHANNEL.sender() },
66            task::run::<_, _, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX, L2CAP_MTU>(
67                self.controller,
68                self.rng,
69                OUTPUT_CHANNEL.receiver(),
70                self.config,
71            ),
72        ))
73    }
74}