wasefire_board_api/platform.rs
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Platform interface.
16
17use crate::Error;
18
19pub mod protocol;
20pub mod update;
21
22/// Platform event.
23#[cfg_attr(feature = "defmt", derive(defmt::Format))]
24#[derive(Debug, PartialEq, Eq)]
25pub enum Event {
26 /// Protocol event.
27 Protocol(protocol::Event),
28}
29
30impl<B: crate::Api> From<Event> for crate::Event<B> {
31 fn from(event: Event) -> Self {
32 crate::Event::Platform(event)
33 }
34}
35
36/// Platform interface.
37pub trait Api: Send {
38 /// Platform protocol interface.
39 type Protocol: protocol::Api;
40
41 /// Platform update interface.
42 type Update: update::Api;
43
44 /// Returns the platform serial.
45 fn serial() -> alloc::borrow::Cow<'static, [u8]>;
46
47 /// Returns the platform version.
48 ///
49 /// Versions are comparable with lexicographical order.
50 fn version() -> alloc::borrow::Cow<'static, [u8]>;
51
52 /// Reboots the device (thus platform and applets).
53 fn reboot() -> Result<!, Error>;
54}
55
56/// Platform protocol interface.
57pub type Protocol<B> = <super::Platform<B> as Api>::Protocol;
58
59/// Platform update interface.
60pub type Update<B> = <super::Platform<B> as Api>::Update;