reda_sp/model/components/
mosfet.rs

1use std::collections::HashMap;
2use derive_builder::Builder;
3use reda_unit::{Length, Number};
4
5use crate::ToSpice;
6
7#[derive(Debug, Clone, Builder)]
8#[builder(setter(strip_option, into))]
9pub struct MosFET {
10    pub name: String,        // Mname
11    pub drain: String,       // ND
12    pub gate: String,        // NG
13    pub source: String,      // NS
14    pub bulk: String,        // bulk)
15    pub model_name: String,  // ModName
16    pub length: Length,      // L=VAL
17    pub width: Length,       // W=VAL
18    #[builder(default)]
19    pub parameters: HashMap<String, Number>,
20}
21
22impl ToSpice for MosFET {
23    fn to_spice(&self) -> String {
24        let mut line = format!(
25            "M{} {} {} {} {} {} L={} W={}",
26            self.name,
27            self.drain,
28            self.gate,
29            self.source,
30            self.bulk,
31            self.model_name,
32            self.length,
33            self.width
34        );
35        for (k, v) in &self.parameters {
36            line.push_str(&format!(" {}={}", k, v));
37        }
38        line
39    }
40}
41
42#[derive(Debug, Clone)]
43pub enum MOSFETKind {
44    NMOS,
45    PMOS,
46}