mct8316a eeprom programming

This commit is contained in:
2025-10-19 15:57:57 -07:00
parent d552fe3627
commit 086ac7f195
19 changed files with 1106 additions and 203 deletions

View File

@@ -0,0 +1,275 @@
#![allow(dead_code)]
#[derive(Debug, Clone)]
pub struct FaultConfig1 {
pub no_motor_detect_deglitch_time: NoMotorDetectDeglitchTime,
pub cycle_by_cycle_current_limit: CycleByCycleCurrentLimit,
pub lock_detection_current_limit: LockDetectionCurrentLimit,
pub lock_detection_current_limit_mode: LockMode,
pub lock_detection_current_limit_deglitch_time: LockDetectionCurrentLimitDeglitchTime,
/// Max of 0x7
pub cycle_by_cycle_pwm_limit: u8,
pub motor_lock_mode: LockMode,
pub lock_retry_time: LockRetryTime,
}
impl Default for FaultConfig1 {
fn default() -> Self {
Self {
no_motor_detect_deglitch_time: NoMotorDetectDeglitchTime::Milliseconds1,
cycle_by_cycle_current_limit: CycleByCycleCurrentLimit::RecoverNextPwmFaultActiveRecirculation,
lock_detection_current_limit: LockDetectionCurrentLimit::NotApplicable,
lock_detection_current_limit_mode: LockMode::LatchFaultTristated,
lock_detection_current_limit_deglitch_time: LockDetectionCurrentLimitDeglitchTime::Milliseconds1,
cycle_by_cycle_pwm_limit: 0,
motor_lock_mode: LockMode::LatchFaultTristated,
lock_retry_time: LockRetryTime::Milliseconds100,
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum NoMotorDetectDeglitchTime {
Milliseconds1 = 0x0,
Milliseconds10 = 0x1,
Milliseconds25 = 0x2,
Milliseconds50 = 0x3,
Milliseconds100 = 0x4,
Milliseconds250 = 0x5,
Milliseconds500 = 0x6,
Milliseconds1000 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum CycleByCycleCurrentLimit {
RecoverNextPwmFaultActiveRecirculation = 0x0,
RecoverNextPwmFaultInactiveRecirculation = 0x1,
RecoverVsoxFaultActiveRecirculation = 0x2,
RecoverVsoxFaultInactiveRecirculation = 0x3,
RecoverRetryFaultActiveRecirculation = 0x4,
RecoverRetryFaultInactiveRecirculation = 0x5,
ReportOnly = 0x6,
Disabled = 0xF,
}
#[derive(Debug, Copy, Clone)]
pub enum LockDetectionCurrentLimit {
NotApplicable = 0x0,
Volts0_1 = 0x1,
Volts0_2 = 0x2,
Volts0_3 = 0x3,
Volts0_4 = 0x4,
Volts0_5 = 0x5,
Volts0_6 = 0x6,
Volts0_7 = 0x7,
Volts0_8 = 0x8,
Volts0_9 = 0x9,
Volts1_0 = 0xA,
Volts1_1 = 0xB,
Volts1_2 = 0xC,
Volts1_3 = 0xD,
Volts1_4 = 0xE,
Volts1_5 = 0xF,
}
#[derive(Debug, Copy, Clone)]
pub enum LockMode {
LatchFaultTristated = 0x0,
LatchFaultRecirculation = 0x1,
LatchFaultHighSideBrake = 0x2,
LatchFaultLowSideBrake = 0x3,
RecoverRetryTristated = 0x4,
RecoverRetryRecirculation = 0x5,
RecoverRetryHighSideBrake = 0x6,
RecoverRetryLowSideBrake = 0x7,
ReportOnly = 0x8,
Disabled = 0xF,
}
#[derive(Debug, Copy, Clone)]
pub enum LockDetectionCurrentLimitDeglitchTime {
Milliseconds1 = 0x0,
Milliseconds2 = 0x1,
Milliseconds5 = 0x2,
Milliseconds10 = 0x3,
Milliseconds25 = 0x4,
Milliseconds50 = 0x5,
Milliseconds75 = 0x6,
Milliseconds100 = 0x7,
Milliseconds250 = 0x8,
Milliseconds500 = 0x9,
Seconds1 = 0xA,
Seconds2_5 = 0xB,
Seconds5 = 0xC,
Seconds10 = 0xD,
Seconds25 = 0xE,
Seconds50 = 0xF,
}
#[derive(Debug, Copy, Clone)]
pub enum LockRetryTime {
Milliseconds100 = 0x0,
Milliseconds500 = 0x1,
Milliseconds1000 = 0x2,
Milliseconds2000 = 0x3,
Milliseconds3000 = 0x4,
Milliseconds5000 = 0x5,
Milliseconds7500 = 0x6,
Milliseconds10000 = 0x7,
}
#[derive(Debug, Clone)]
pub struct FaultConfig2 {
/// Lock 1
pub lock_abnormal_speed_enable: bool,
/// Lock 2
pub lock_loss_of_sync_enable: bool,
/// Lock 3
pub lock_no_motor_enable: bool,
pub abnormal_speed_lock_threshold: AbnormalSpeedLockThreshold,
pub loss_sync_times: LossSyncTimes,
pub no_motor_threshold: NoMotorThreshold,
pub max_motor_voltage_mode: MotorVoltageMode,
pub max_motor_voltage: MaxMotorVoltage,
pub min_motor_voltage_mode: MotorVoltageMode,
pub min_motor_voltage: MinMotorVoltage,
pub automatic_retries: AutomaticRetries,
pub lock_min_speed: LockMinSpeed,
pub abnormal_speed_lock: AbnormalSpeedLock,
pub zero_duty_threshold: ZeroDutyThreshold,
}
impl Default for FaultConfig2 {
fn default() -> Self {
Self {
lock_abnormal_speed_enable: false,
lock_loss_of_sync_enable: false,
lock_no_motor_enable: false,
abnormal_speed_lock_threshold: AbnormalSpeedLockThreshold::Hertz250,
loss_sync_times: LossSyncTimes::Count2,
no_motor_threshold: NoMotorThreshold::Volts0_005,
max_motor_voltage_mode: MotorVoltageMode::Latch,
max_motor_voltage: MaxMotorVoltage::NoLimit,
min_motor_voltage_mode: MotorVoltageMode::Latch,
min_motor_voltage: MinMotorVoltage::NoLimit,
automatic_retries: AutomaticRetries::NoLimit,
lock_min_speed: LockMinSpeed::Hertz0_5,
abnormal_speed_lock: AbnormalSpeedLock::Ratio2,
zero_duty_threshold: ZeroDutyThreshold::Percent1,
}
}
}
#[derive(Debug, Copy, Clone)]
pub enum AbnormalSpeedLockThreshold {
Hertz250 = 0x0,
Hertz500 = 0x1,
Hertz750 = 0x2,
Hertz1000 = 0x3,
Hertz1250 = 0x4,
Hertz1500 = 0x5,
Hertz1750 = 0x6,
Hertz2000 = 0x7,
Hertz2250 = 0x8,
Hertz2500 = 0x9,
Hertz2750 = 0xA,
Hertz3000 = 0xB,
Hertz3250 = 0xC,
Hertz3500 = 0xD,
Hertz3750 = 0xE,
Hertz4000 = 0xF,
}
#[derive(Debug, Copy, Clone)]
pub enum LossSyncTimes {
Count2 = 0x0,
Count3 = 0x1,
Count4 = 0x2,
Count5 = 0x3,
Count6 = 0x4,
Count7 = 0x5,
Count8 = 0x6,
Count9 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum NoMotorThreshold {
Volts0_005 = 0x0,
Volts0_0075 = 0x1,
Volts0_010 = 0x2,
Volts0_0125 = 0x3,
Volts0_020 = 0x4,
Volts0_025 = 0x5,
Volts0_030 = 0x6,
Volts0_04 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum MotorVoltageMode {
Latch = 0x0,
AutomaticClear = 0x1,
}
#[derive(Debug, Copy, Clone)]
pub enum MaxMotorVoltage {
NoLimit = 0x0,
Volts20 = 0x1,
Volts25 = 0x2,
Volts30 = 0x3,
Volts35 = 0x4,
Volts40 = 0x5,
Volts50 = 0x6,
Volts60 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum MinMotorVoltage {
NoLimit = 0x0,
Volts6 = 0x1,
Volts7 = 0x2,
Volts8 = 0x3,
Volts9 = 0x4,
Volts10 = 0x5,
Volts12 = 0x6,
Volts15 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum AutomaticRetries {
NoLimit = 0x0,
Count2 = 0x1,
Count3 = 0x2,
Count5 = 0x3,
Count7 = 0x4,
Count10 = 0x5,
Count15 = 0x6,
Count20 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum LockMinSpeed {
Hertz0_5 = 0x0,
Hertz1 = 0x1,
Hertz2 = 0x2,
Hertz3 = 0x3,
Hertz5 = 0x4,
Hertz10 = 0x5,
Hertz15 = 0x6,
Hertz20 = 0x7,
}
#[derive(Debug, Copy, Clone)]
pub enum AbnormalSpeedLock {
Ratio2 = 0x0,
Ratio4 = 0x1,
Ratio6 = 0x2,
Ratio8 = 0x3,
}
#[derive(Debug, Copy, Clone)]
pub enum ZeroDutyThreshold {
Percent1 = 0x0,
Percent1_5 = 0x1,
Percent2 = 0x2,
Percent2_5 = 0x3,
}