Skip to main content

bmputil/
lib.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2// SPDX-FileCopyrightText: 2022-2025 1BitSquared <info@1bitsquared.com>
3// SPDX-FileContributor: Written by Mikaela Szekely <mikaela.szekely@qyriad.me>
4// SPDX-FileContributor: Written by Piotr Esden-Tempski <piotr@esden.net>
5// SPDX-FileContributor: Modified by Rachel Mant <git@dragonmux.network>
6
7#![allow(clippy::tabs_in_doc_comments)]
8
9use clap::ValueEnum;
10use clap::builder::PossibleValue;
11
12use crate::firmware_type::FirmwareType;
13
14pub mod bmp;
15mod bmp_matcher;
16pub mod docs_viewer;
17pub mod error;
18mod firmware_file;
19pub mod firmware_selector;
20pub mod firmware_type;
21pub mod flasher;
22pub mod metadata;
23pub mod probe_identity;
24pub mod serial;
25pub mod switcher;
26pub mod usb;
27#[cfg(windows)]
28pub mod windows;
29
30pub trait BmpParams
31{
32	fn index(&self) -> Option<usize>;
33	fn serial_number(&self) -> Option<&str>;
34}
35
36pub trait FlashParams
37{
38	fn allow_dangerous_options(&self) -> AllowDangerous;
39	fn override_firmware_type(&self) -> Option<FirmwareType>;
40}
41
42#[derive(Clone, Copy)]
43pub enum AllowDangerous
44{
45	Never,
46	Really,
47}
48
49impl ValueEnum for AllowDangerous
50{
51	fn value_variants<'a>() -> &'a [Self]
52	{
53		&[Self::Never, Self::Really]
54	}
55
56	fn to_possible_value(&self) -> Option<PossibleValue>
57	{
58		match self {
59			Self::Never => Some("never".into()),
60			Self::Really => Some("really".into()),
61		}
62	}
63}