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 {
45            controller,
46            rng,
47            config,
48        }
49    }
50}
51
52impl<
53    C: Controller + 'static,
54    RNG: RngCore + CryptoRng,
55    const CONNECTIONS_MAX: usize,
56    const L2CAP_CHANNELS_MAX: usize,
57    const L2CAP_MTU: usize,
58> WirelessReporterDriverBuilder
59    for TroubleReporterBuilder<C, RNG, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX, L2CAP_MTU>
60{
61    type Output = TroubleReporter;
62
63    type Error = ();
64
65    async fn build(
66        self,
67    ) -> Result<(Self::Output, impl Future<Output = ()> + 'static), Self::Error> {
68        Ok((
69            TroubleReporter {
70                output_tx: OUTPUT_CHANNEL.sender(),
71            },
72            task::run::<_, _, CONNECTIONS_MAX, L2CAP_CHANNELS_MAX, L2CAP_MTU>(
73                self.controller,
74                self.rng,
75                OUTPUT_CHANNEL.receiver(),
76                self.config,
77            ),
78        ))
79    }
80}