wasefire_board_api/fingerprint/
sensor.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 sensor interface.
16
17use crate::{Error, Support};
18
19/// Fingerprint sensor event.
20#[cfg_attr(feature = "defmt", derive(defmt::Format))]
21#[derive(Debug, PartialEq, Eq)]
22pub enum Event {
23    /// The image was captured.
24    ///
25    /// The image can be fetched by calling `read_capture()`. It must be fetched before another
26    /// image can be captured.
27    CaptureDone,
28
29    /// The capture process encountered an error.
30    CaptureError {
31        /// The device error.
32        error: Error,
33    },
34}
35
36impl<B: crate::Api> From<Event> for crate::Event<B> {
37    fn from(event: Event) -> Self {
38        super::Event::Sensor(event).into()
39    }
40}
41
42/// Fingerprint sensor interface.
43pub trait Api: Support<bool> + Send {
44    /// Width in bytes of an image.
45    const IMAGE_WIDTH: usize;
46
47    /// Height in bytes of an image.
48    const IMAGE_HEIGHT: usize;
49
50    /// Starts an image capture process.
51    ///
52    /// The process sends `CaptureDone` for success and `CaptureError` for error.
53    fn start_capture() -> Result<(), Error>;
54
55    /// Reads a captured image.
56    fn read_capture(image: &mut [u8]) -> Result<(), Error>;
57
58    /// Aborts an image capture process.
59    fn abort_capture() -> Result<(), Error>;
60}