em100/lib.rs
1//! Rust library for controlling Dediprog EM100Pro SPI flash emulators.
2//!
3//! The crates.io package is named `rem100`; its library crate is named `em100`.
4//! The package also provides the `rem100` command-line utility.
5//!
6//! Library-only users should disable the default `cli` feature:
7//!
8//! ```toml
9//! [dependencies]
10//! rem100 = { version = "0.1", default-features = false }
11//! ```
12//!
13//! # Example
14//!
15//! ```no_run
16//! use em100::{list_devices, Em100, Result};
17//!
18//! fn main() -> Result<()> {
19//! for (bus, address, serial) in list_devices()? {
20//! println!("{bus}:{address} {serial}");
21//! }
22//!
23//! let device = Em100::open(None, None, None)?;
24//! println!("{}", device.serial_string());
25//! Ok(())
26//! }
27//! ```
28//!
29//! The `cli` feature enables the command-line binary and CLI-only downloading
30//! and archive helpers. The `web` feature enables the egui interface; on
31//! `wasm32-unknown-unknown`, USB access uses WebUSB through `nusb`.
32//!
33//! Copyright 2012-2019 Google Inc.
34//! Rust port copyright 2024
35//!
36//! This program is free software; you can redistribute it and/or modify
37//! it under the terms of the GNU General Public License as published by
38//! the Free Software Foundation; version 2 of the License.
39
40pub mod chips;
41pub mod error;
42pub mod hexdump;
43
44// Image module requires device types
45#[cfg(not(target_arch = "wasm32"))]
46pub mod image;
47
48// Modules that require blocking USB operations (not available on wasm32)
49#[cfg(not(target_arch = "wasm32"))]
50pub mod device;
51#[cfg(not(target_arch = "wasm32"))]
52pub mod firmware;
53#[cfg(not(target_arch = "wasm32"))]
54pub mod fpga;
55#[cfg(not(target_arch = "wasm32"))]
56pub mod sdram;
57#[cfg(not(target_arch = "wasm32"))]
58pub mod spi;
59#[cfg(not(target_arch = "wasm32"))]
60pub mod system;
61#[cfg(not(target_arch = "wasm32"))]
62pub mod trace;
63#[cfg(not(target_arch = "wasm32"))]
64pub mod usb;
65
66// CLI-only modules
67#[cfg(feature = "cli")]
68pub mod download;
69#[cfg(feature = "cli")]
70pub mod tar;
71
72// Web module (native GUI only, not wasm32)
73#[cfg(all(feature = "web", not(target_arch = "wasm32")))]
74pub mod web;
75
76// Async WebUSB modules (for wasm32)
77#[cfg(target_arch = "wasm32")]
78pub mod web_device;
79#[cfg(target_arch = "wasm32")]
80pub mod web_usb;
81
82pub use chips::{ChipDatabase, ChipDesc, parse_dcfg};
83pub use error::{Error, Result};
84
85// Re-exports for native platforms only
86#[cfg(not(target_arch = "wasm32"))]
87pub use device::{DebugInfo, DeviceInfo, Em100, HoldPinState, HwVersion, Voltages, list_devices};
88#[cfg(not(target_arch = "wasm32"))]
89pub use firmware::{
90 FirmwareInfo, firmware_read, firmware_to_dpfw, firmware_write, validate_firmware,
91};
92#[cfg(not(target_arch = "wasm32"))]
93pub use sdram::{ProgressCallback, read_sdram_with_progress, write_sdram_with_progress};