#![allow(dead_code)]

// This comes from the ICD
#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone)]
pub struct GateDriverConfig1 {
    pub slew_rate: SlewRate,
    pub overvoltage_protection_level: OvervoltageProtectionLevel,
    pub overvoltage_protection_enable: bool,
    pub overtemperature_warning_enable: bool,
    pub overcurrent_protection_deglitch_time: OvercurrentProtectionDeglitchTime,
    pub overcurrent_protection_retry_time: OvercurrentProtectionRetryTime,
    pub overcurrent_protection_level: OvercurrentProtectionLevel,
    pub overcurrent_fault_mode: OvercurrentFaultMode,
    pub low_demag_comparator_threshold: DemagComparatorThreshold,
    pub high_demag_comparator_threshold: DemagComparatorThreshold,
    pub synchronous_rectification_enable: bool,
    pub asynchronous_rectification_enable: bool,
    pub current_sense_amplifier: CurrentSenseAmplifier,
}

impl Default for GateDriverConfig1 {
    fn default() -> Self {
        Self {
            slew_rate: SlewRate::VoltsPerMicro25,
            overvoltage_protection_level: OvervoltageProtectionLevel::Volts32,
            overvoltage_protection_enable: false,
            overtemperature_warning_enable: false,
            overcurrent_protection_deglitch_time: OvercurrentProtectionDeglitchTime::Microsecond0_2,
            overcurrent_protection_retry_time: OvercurrentProtectionRetryTime::Millisecond5,
            overcurrent_protection_level: OvercurrentProtectionLevel::Amps16,
            overcurrent_fault_mode: OvercurrentFaultMode::Latch,
            low_demag_comparator_threshold: DemagComparatorThreshold::Milliamps100,
            high_demag_comparator_threshold: DemagComparatorThreshold::Milliamps100,
            synchronous_rectification_enable: false,
            asynchronous_rectification_enable: false,
            current_sense_amplifier: CurrentSenseAmplifier::VoltsPerAmp0_15,
        }
    }
}

#[derive(Debug, Copy, Clone)]
pub enum SlewRate {
    VoltsPerMicro25 = 0x0,
    VoltsPerMicro50 = 0x1,
    VoltsPerMicro125 = 0x2,
    VoltsPerMicro200 = 0x3,
}

#[derive(Debug, Copy, Clone)]
pub enum OvervoltageProtectionLevel {
    Volts32 = 0x0,
    Volts20 = 0x1,
}

#[derive(Debug, Copy, Clone)]
pub enum OvercurrentProtectionDeglitchTime {
    Microsecond0_2 = 0x0,
    Microsecond0_6 = 0x1,
    Microsecond1_1 = 0x2,
    Microsecond1_6 = 0x3,
}

#[derive(Debug, Copy, Clone)]
pub enum OvercurrentProtectionRetryTime {
    Millisecond5 = 0x0,
    Millisecond500 = 0x1,
}

#[derive(Debug, Copy, Clone)]
pub enum OvercurrentProtectionLevel {
    Amps16 = 0x0,
    Amps24 = 0x1,
}

#[derive(Debug, Copy, Clone)]
pub enum OvercurrentFaultMode {
    Latch = 0x0,
    AutomaticRetry = 0x1,
    ReportOnly = 0x2,
    None = 0x3,
}

#[derive(Debug, Copy, Clone)]
pub enum DemagComparatorThreshold {
    Milliamps100 = 0x0,
    Milliamps150 = 0x1,
}

#[derive(Debug, Copy, Clone)]
pub enum CurrentSenseAmplifier {
    VoltsPerAmp0_15 = 0x0,
    VoltsPerAmp0_3 = 0x1,
    VoltsPerAmp0_6 = 0x2,
    VoltsPerAmp1_2 = 0x3,
}

#[derive(Debug, Clone)]
pub struct GateDriverConfig2 {
    pub driver_delay_compensation_enable: bool,
    pub target_delay: TargetDelay,
    pub buck_slew_rate: BuckSlewRate,
    pub buck_power_sequencing_disable: bool,
    pub buck_current_limit: BuckCurrentLimit,
    pub buck_voltage_selection: BuckVoltageSelection,
    pub buck_disable: bool,
}

impl Default for GateDriverConfig2 {
    fn default() -> Self {
        Self {
            driver_delay_compensation_enable: false,
            target_delay: TargetDelay::Automatic,
            buck_slew_rate: BuckSlewRate::VoltsPerMicrosecond1000,
            buck_power_sequencing_disable: false,
            buck_current_limit: BuckCurrentLimit::Milliamps600,
            buck_voltage_selection: BuckVoltageSelection::Volts3_3,
            buck_disable: false,
        }
    }
}

#[derive(Debug, Copy, Clone)]
pub enum TargetDelay {
    Automatic = 0x0,
    Microsecond0_4 = 0x1,
    Microsecond0_6 = 0x2,
    Microsecond0_8 = 0x3,
    Microsecond1_0 = 0x4,
    Microsecond1_2 = 0x5,
    Microsecond1_4 = 0x6,
    Microsecond1_6 = 0x7,
    Microsecond1_8 = 0x8,
    Microsecond2_0 = 0x9,
    Microsecond2_2 = 0xA,
    Microsecond2_4 = 0xB,
    Microsecond2_6 = 0xC,
    Microsecond2_8 = 0xD,
    Microsecond3_0 = 0xE,
    Microsecond3_2 = 0xF,
}

#[derive(Debug, Copy, Clone)]
pub enum BuckSlewRate {
    VoltsPerMicrosecond1000 = 0x0,
    VoltsPerMicrosecond200 = 0x1,
}

#[derive(Debug, Copy, Clone)]
pub enum BuckCurrentLimit {
    Milliamps600 = 0x0,
    Milliamps150 = 0x1,
}

#[derive(Debug, Copy, Clone)]
pub enum BuckVoltageSelection {
    Volts3_3 = 0x0,
    Volts5_0 = 0x1,
    Volts4_0 = 0x2,
    Volts5_7 = 0x3,
}
