wasefire_board_api/
usb.rs

1// Copyright 2022 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//! USB interface.
16
17#[cfg(feature = "api-usb-ctap")]
18pub mod ctap;
19#[cfg(feature = "api-usb-serial")]
20pub mod serial;
21
22/// USB event.
23#[cfg_attr(feature = "defmt", derive(defmt::Format))]
24#[derive(Debug, PartialEq, Eq)]
25pub enum Event {
26    /// CTAP HID event.
27    #[cfg(feature = "api-usb-ctap")]
28    Ctap(ctap::Event),
29
30    /// Serial event.
31    #[cfg(feature = "api-usb-serial")]
32    Serial(serial::Event),
33}
34
35impl<B: crate::Api> From<Event> for crate::Event<B> {
36    fn from(event: Event) -> Self {
37        crate::Event::Usb(event)
38    }
39}
40
41/// USB interface.
42pub trait Api: Send {
43    /// CTAP HID interface.
44    #[cfg(feature = "api-usb-ctap")]
45    type Ctap: ctap::Api;
46
47    /// USB serial interface.
48    #[cfg(feature = "api-usb-serial")]
49    type Serial: serial::Api;
50}
51
52/// CTAP HID interface.
53#[cfg(feature = "api-usb-ctap")]
54pub type Ctap<B> = <super::Usb<B> as Api>::Ctap;
55
56/// USB serial interface.
57#[cfg(feature = "api-usb-serial")]
58pub type Serial<B> = <super::Usb<B> as Api>::Serial;