components/
eui64.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 Tock Contributors 2024.
4
5//! Component for EUI-64 (Extended Unique Identifier).
6//!
7//! Usage
8//! -----
9//! ```rust
10//!let eui64 = components::eui64::Eui64Component::new(u64::from_le_bytes(device_id))
11//!     .finalize(components::eui64_component_static!());
12//! ```
13
14use capsules_extra::eui64::Eui64;
15use core::mem::MaybeUninit;
16use kernel::component::Component;
17
18#[macro_export]
19macro_rules! eui64_component_static {
20    () => {{
21        kernel::static_buf!(capsules_extra::eui64::Eui64)
22    };};
23}
24
25pub type Eui64ComponentType = capsules_extra::eui64::Eui64;
26
27pub struct Eui64Component {
28    eui64: u64,
29}
30
31impl Eui64Component {
32    pub fn new(eui64: u64) -> Self {
33        Self { eui64 }
34    }
35}
36
37impl Component for Eui64Component {
38    type StaticInput = &'static mut MaybeUninit<Eui64>;
39    type Output = &'static Eui64;
40
41    fn finalize(self, s: Self::StaticInput) -> Self::Output {
42        s.write(Eui64::new(self.eui64))
43    }
44}