Skip to main content

probe_rs/
plugin.rs

1//! Plugin system for probe-rs.
2//!
3//! This module contains the interfaces necessary to define and register plugins.
4//! Plugins can extend the functionality of probe-rs by adding e.g. new targets, probes, image formats.
5//!
6//! Plugins are registered by calling the [`register_plugin`] function.
7
8use probe_rs_target::ChipFamily;
9
10use crate::{flashing::ImageFormat, probe::ProbeFactory, vendor::Vendor};
11
12/// A plugin that can extend the functionality of probe-rs.
13#[derive(Clone, Default)]
14pub struct Plugin<'p> {
15    /// A list of vendors to register with probe-rs.
16    pub vendors: &'p [&'static dyn Vendor],
17
18    /// A list of image formats to register with probe-rs.
19    pub image_formats: &'p [&'static dyn ImageFormat],
20
21    /// A list of targets to register with probe-rs.
22    pub targets: &'p [ChipFamily],
23
24    /// A list of probe driver factories.
25    pub probe_drivers: &'p [&'static dyn ProbeFactory],
26}
27
28/// Register a plugin.
29pub fn register_plugin(plugin: Plugin<'_>) {
30    // Implementation of plugin registration
31    for vendor in plugin.vendors {
32        crate::vendor::register_vendor(*vendor);
33    }
34    for image_format in plugin.image_formats {
35        crate::flashing::register_image_format(*image_format);
36    }
37    for target in plugin.targets {
38        crate::config::registry::add_builtin_target(target.clone());
39    }
40    for probe_driver in plugin.probe_drivers {
41        crate::probe::register_probe_factory(*probe_driver);
42    }
43}