Skip to main content

wasefire_board_api/
fingerprint.rs

1// Copyright 2025 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//! Fingerprint interface.
16
17use crate::Error;
18
19#[cfg(feature = "api-fingerprint-matcher")]
20pub mod matcher;
21#[cfg(feature = "api-fingerprint-sensor")]
22pub mod sensor;
23
24/// Fingerprint event.
25#[cfg_attr(feature = "defmt", derive(defmt::Format))]
26#[derive(Debug, PartialEq, Eq)]
27pub enum Event {
28    /// Fingerprint matcher event.
29    #[cfg(feature = "api-fingerprint-matcher")]
30    Matcher(matcher::Event),
31
32    /// Fingerprint sensor event.
33    #[cfg(feature = "api-fingerprint-sensor")]
34    Sensor(sensor::Event),
35
36    /// A finger was detected.
37    FingerDetected,
38}
39
40impl<B: crate::Api> From<Event> for crate::Event<B> {
41    fn from(event: Event) -> Self {
42        crate::Event::Fingerprint(event)
43    }
44}
45
46/// Fingerprint interface.
47pub trait Api: Send {
48    /// Fingerprint matcher interface.
49    #[cfg(feature = "api-fingerprint-matcher")]
50    type Matcher: matcher::Api;
51
52    /// Fingerprint sensor interface.
53    #[cfg(feature = "api-fingerprint-sensor")]
54    type Sensor: sensor::Api;
55
56    /// Enables finger detection.
57    fn enable() -> Result<(), Error>;
58
59    /// Disables finger detection.
60    fn disable() -> Result<(), Error>;
61}
62
63/// Fingerprint matcher interface.
64#[cfg(feature = "api-fingerprint-matcher")]
65pub type Matcher<B> = <super::Fingerprint<B> as Api>::Matcher;
66
67/// Fingerprint sensor interface.
68#[cfg(feature = "api-fingerprint-sensor")]
69pub type Sensor<B> = <super::Fingerprint<B> as Api>::Sensor;