forked from tock/tock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boards: components: Initial support for the Atecc508a CryptoAuthentic…
…ation Device Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
- Loading branch information
1 parent
118a413
commit ddf0a32
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed under the Apache License, Version 2.0 or the MIT License. | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// Copyright Tock Contributors 2022. | ||
|
||
//! Components for the ATECC508A CryptoAuthentication Device. | ||
//! | ||
//! Usage | ||
//! ----- | ||
//! ```rust | ||
//! let atecc508a = | ||
//! Atecc508aComponent::new(mux_i2c, 0x60).finalize(components::atecc508a_component_static!()); | ||
//! ``` | ||
use capsules_core::virtualizers::virtual_i2c::{I2CDevice, MuxI2C}; | ||
use capsules_extra::atecc508a::Atecc508a; | ||
use core::mem::MaybeUninit; | ||
use kernel::component::Component; | ||
use kernel::hil::i2c; | ||
|
||
// Setup static space for the objects. | ||
#[macro_export] | ||
macro_rules! atecc508a_component_static { | ||
($I:ty $(,)?) => {{ | ||
let i2c_device = | ||
kernel::static_buf!(capsules_core::virtualizers::virtual_i2c::I2CDevice<'static, $I>); | ||
let i2c_buffer = kernel::static_buf!([u8; 40]); | ||
let entropy_buffer = kernel::static_buf!([u8; 32]); | ||
let atecc508a = kernel::static_buf!(capsules_extra::atecc508a::Atecc508a<'static>); | ||
|
||
(i2c_device, i2c_buffer, entropy_buffer, atecc508a) | ||
};}; | ||
} | ||
|
||
pub struct Atecc508aComponent<I: 'static + i2c::I2CMaster<'static>> { | ||
i2c_mux: &'static MuxI2C<'static, I>, | ||
i2c_address: u8, | ||
} | ||
|
||
impl<I: 'static + i2c::I2CMaster<'static>> Atecc508aComponent<I> { | ||
pub fn new(i2c: &'static MuxI2C<'static, I>, i2c_address: u8) -> Self { | ||
Atecc508aComponent { | ||
i2c_mux: i2c, | ||
i2c_address: i2c_address, | ||
} | ||
} | ||
} | ||
|
||
impl<I: 'static + i2c::I2CMaster<'static>> Component for Atecc508aComponent<I> { | ||
type StaticInput = ( | ||
&'static mut MaybeUninit<I2CDevice<'static, I>>, | ||
&'static mut MaybeUninit<[u8; 40]>, | ||
&'static mut MaybeUninit<[u8; 32]>, | ||
&'static mut MaybeUninit<Atecc508a<'static>>, | ||
); | ||
type Output = &'static Atecc508a<'static>; | ||
|
||
fn finalize(self, s: Self::StaticInput) -> Self::Output { | ||
let atecc508a_i2c = s.0.write(I2CDevice::new(self.i2c_mux, self.i2c_address)); | ||
|
||
let i2c_buffer = s.1.write([0; 40]); | ||
let entropy_buffer = s.2.write([0; 32]); | ||
|
||
let atecc508a = | ||
s.3.write(Atecc508a::new(atecc508a_i2c, i2c_buffer, entropy_buffer)); | ||
|
||
atecc508a_i2c.set_client(atecc508a); | ||
atecc508a | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters