components/
wifi.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright OxidOS Automotive 2025.
4
5use capsules_extra::wifi;
6use core::mem::MaybeUninit;
7use kernel::{capabilities, component::Component, create_capability};
8
9#[macro_export]
10macro_rules! wifi_component_static {
11    ($D:ty $(,)?) => {{
12        kernel::static_buf!(capsules_extra::wifi::WifiDriver<'static, $D>)
13    }};
14}
15
16pub struct WifiComponent<D: 'static + wifi::Device<'static>> {
17    board_kernel: &'static kernel::Kernel,
18    driver_num: usize,
19    device: &'static D,
20}
21
22impl<D: 'static + wifi::Device<'static>> WifiComponent<D> {
23    pub fn new(
24        board_kernel: &'static kernel::Kernel,
25        driver_num: usize,
26        device: &'static D,
27    ) -> Self {
28        Self {
29            board_kernel,
30            driver_num,
31            device,
32        }
33    }
34}
35
36impl<D: 'static + wifi::Device<'static>> Component for WifiComponent<D> {
37    type StaticInput = &'static mut MaybeUninit<wifi::WifiDriver<'static, D>>;
38    type Output = &'static wifi::WifiDriver<'static, D>;
39    fn finalize(self, static_memory: Self::StaticInput) -> Self::Output {
40        let capability = create_capability!(capabilities::MemoryAllocationCapability);
41
42        let wifi = static_memory.write(wifi::WifiDriver::new(
43            self.device,
44            self.board_kernel.create_grant(self.driver_num, &capability),
45        ));
46        self.device.set_client(wifi);
47
48        wifi
49    }
50}