atecc608b/lib.rs
1// Copyright (c) 2026 Tuloup Simon
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! `no_std` asynchronous driver for the Microchip ATECC608B secure element.
17//!
18//! This crate is intentionally generic over a [`hal::AteccHal`] trait so it can
19//! be built against any concrete hardware backend (RP2040 + `embassy-rp`, an
20//! STM32, or an in-memory mock for host-side tests). The crate is `no_std` and
21//! does not allocate on the heap.
22//!
23//! # Layered architecture
24//!
25//! The driver is split into several internal modules that map one-to-one to
26//! the layers of the protocol:
27//!
28//! - [`crc`] - CRC-16/DNP implementation used by every command frame.
29//! - [`packet`] - Encoding and decoding of the command/response packet.
30//! - [`wake`] - Wake / idle / sleep sequence and the response polling
31//! loop.
32//! - [`command`] - One module per high-level command (Info, Random, Sign,
33//! `GenKey`, etc). Each one exposes a typed async function on the
34//! [`driver::AteccChannel`] handle.
35//! - [`error`] - Error types for each layer, with `From` conversions for
36//! chaining.
37//! - [`opcodes`] - Numeric constants extracted from the Microchip
38//! `CryptoAuthLib` reference. Treat this as the single source of truth for
39//! on-the-wire values.
40//! - [`hal`] - The [`hal::AteccHal`] trait every backend must implement.
41//! - [`slot`] - Slot identifiers and helpers.
42//! - [`driver`] - The top-level [`driver::Atecc`] handle (sleeping) and
43//! [`driver::AteccChannel`] (awake) that together model the chip's
44//! wake / idle lifecycle.
45
46#![no_std]
47#![deny(missing_docs)]
48#![deny(unsafe_code)]
49#![warn(clippy::pedantic)]
50#![allow(rustdoc::private_intra_doc_links)]
51
52pub mod command;
53pub mod crc;
54pub mod driver;
55pub(crate) mod error;
56pub mod hal;
57pub mod opcodes;
58pub(crate) mod packet;
59pub(crate) mod slot;
60pub(crate) mod wake;
61
62pub use driver::Atecc;
63pub use driver::AteccChannel;
64pub use error::AteccError;
65pub use error::ChipError;
66pub use error::AteccErrorKind;
67pub use hal::AteccHal;
68pub use slot::Slot;