You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

295 lines
8.3 KiB

#include "driver.hpp"
using namespace iflytop;
#define TIMER2_FREQ 1000
#define TIMER1_FREQ 1000
#define ENABL_TRACE false
#define TAG "DRIVER"
/*******************************************************************************
* ·çÉÈÅäÖà *
*******************************************************************************/
PWMSpeedCtrlModule::config_t fan0cfg = {
.name = "fan0",
.pwm_cfg =
{
.name = "fan0pwmtimer",
.htim = &htim2,
.freq = TIMER2_FREQ,
.polarity = false,
},
.nfan = 2,
.fan0Channel = {3, 0, 0, 0},
.fanFBGpioCfg =
{
{.pin = PC10},
{.pin = PC11},
},
.fanPowerGpioCfg =
{
{
.pin = PC4,
.mode = ZGPIO::kMode_nopull,
.mirror = false,
},
},
.enablefbcheck = false,
.enableTrace = ENABL_TRACE,
};
PWMSpeedCtrlModule::config_t fan1cfg = {
.name = "fan1",
.pwm_cfg =
{
.name = "fan1pwmtimer",
.htim = &htim2,
.freq = TIMER2_FREQ,
.polarity = false,
},
.nfan = 2,
.fan0Channel = {4, 0, 0, 0},
.fanFBGpioCfg =
{
{.pin = PC12},
{.pin = PC13},
},
.fanPowerGpioCfg =
{
{
.pin = PC5,
.mode = ZGPIO::kMode_nopull,
.mirror = false,
},
},
.enablefbcheck = false,
.enableTrace = ENABL_TRACE,
};
/*******************************************************************************
* FanCtrlModule *
*******************************************************************************/
void FanCtrlModule::initialize(fan_index_t index) {
m_fanindex = index;
if (m_fanindex == kfan0) {
fan0.initialize(&fan0cfg);
} else if (m_fanindex == kfan1) {
fan1.initialize(&fan1cfg);
} else if (m_fanindex == kfan0and1) {
fan0.initialize(&fan0cfg);
fan1.initialize(&fan1cfg);
}
}
void FanCtrlModule::setFanSpeed(int32_t duty) {
if (m_fanindex == kfan0) {
fan0.startModule(duty);
} else if (m_fanindex == kfan1) {
fan1.startModule(duty);
} else if (m_fanindex == kfan0and1) {
fan0.startModule(duty);
fan1.startModule(duty);
}
}
void FanCtrlModule::stop() {
if (m_fanindex == kfan0) {
fan0.stopModule();
} else if (m_fanindex == kfan1) {
fan1.stopModule();
} else if (m_fanindex == kfan0and1) {
fan0.stopModule();
fan1.stopModule();
}
}
bool FanCtrlModule::isWorking() {
if (m_fanindex == kfan0) {
return fan0.isWorking();
} else if (m_fanindex == kfan1) {
return fan1.isWorking();
} else if (m_fanindex == kfan0and1) {
return fan0.isWorking() || fan1.isWorking();
}
return false;
}
void FanCtrlModule::clearError() {
if (m_fanindex == kfan0) {
fan0.clearError();
} else if (m_fanindex == kfan1) {
fan1.clearError();
} else if (m_fanindex == kfan0and1) {
fan0.clearError();
fan1.clearError();
}
};
bool FanCtrlModule::isError() {
if (m_fanindex == kfan0) {
return fan0.isError();
} else if (m_fanindex == kfan1) {
return fan1.isError();
} else if (m_fanindex == kfan0and1) {
return fan0.isError() || fan1.isError();
}
return false;
}
/*******************************************************************************
* Ë®±ÃÅäÖà *
*******************************************************************************/
PWMSpeedCtrlModule::config_t pumpcfg = {
.name = "pump",
.pwm_cfg =
{
.name = "pumptime",
.htim = &htim2,
.freq = TIMER2_FREQ,
.polarity = false,
},
.nfan = 1,
.fan0Channel = {2, 0, 0, 0},
.fanFBGpioCfg =
{
{.pin = PC3},
},
.fanPowerGpioCfg =
{
{
.pin = PC2,
.mode = ZGPIO::kMode_nopull,
.mirror = false,
},
},
.enablefbcheck = false,
.enableTrace = ENABL_TRACE,
};
/*******************************************************************************
* PumpCtrlModule *
*******************************************************************************/
void PumpCtrlModule::initialize() { pump.initialize(&pumpcfg); }
void PumpCtrlModule::setPumpSpeed(int32_t duty) { pump.startModule(duty); }
void PumpCtrlModule::stop() { pump.stopModule(); }
bool PumpCtrlModule::isError() { return pump.isError(); }
bool PumpCtrlModule::isWorking() { return pump.isWorking(); }
void PumpCtrlModule::clearError() { return pump.clearError(); }
/*******************************************************************************
* ÅÁ¶ûÌùÅäÖà *
*******************************************************************************/
#define PELTIER_POLARITY false
DRV8710::config_t peltier_config0 = {
.pwm_cfg =
{
.name = "peltier1_pwm",
.htim = &htim1,
.freq = TIMER1_FREQ,
.polarity = false,
},
.in1_chnannel_index = 3, // PE13
.in2 = PE14,
.nsleep = PB13,
.nfault = PB14,
.sensePin = PB15,
.shaft = PELTIER_POLARITY,
.enableTrace = ENABL_TRACE,
};
DRV8710::config_t peltier_config1 = {
.pwm_cfg =
{
.name = "peltier0_pwm",
.htim = &htim1,
.freq = TIMER1_FREQ,
.polarity = false,
},
.in1_chnannel_index = 1, // PE9
.in2 = PE11,
.nsleep = PB2,
.nfault = PB3,
.sensePin = PB4,
.shaft = !PELTIER_POLARITY,
.enableTrace = ENABL_TRACE,
};
void PeltierCtrlModule::initialize(peltier_index_t index) {
m_index = index;
if (m_index == kpeltier0) {
peltier0.initialize(&peltier_config0);
} else if (m_index == kpeltier1) {
peltier1.initialize(&peltier_config1);
} else if (m_index == kpeltier0and1) {
peltier0.initialize(&peltier_config0);
peltier1.initialize(&peltier_config1);
}
}
void PeltierCtrlModule::setSpeed(int32_t duty) {
m_workflag = true;
if (m_index == kpeltier0) {
peltier0.enable(true);
peltier0.move(duty);
} else if (m_index == kpeltier1) {
peltier1.enable(true);
peltier1.move(duty);
} else if (m_index == kpeltier0and1) {
peltier0.enable(true);
peltier0.move(duty);
peltier1.enable(true);
peltier1.move(duty);
}
}
void PeltierCtrlModule::stop() {
m_workflag = false;
if (m_index == kpeltier0) {
peltier0.enable(false);
peltier0.move(0);
} else if (m_index == kpeltier1) {
peltier1.enable(false);
peltier1.move(0);
} else if (m_index == kpeltier0and1) {
peltier0.enable(false);
peltier0.move(0);
peltier1.enable(false);
peltier1.move(0);
}
}
bool PeltierCtrlModule::isError() {
if (m_index == kpeltier0) {
return peltier0.isFault();
} else if (m_index == kpeltier1) {
return peltier1.isFault();
} else if (m_index == kpeltier0and1) {
return peltier0.isFault() || peltier1.isFault();
}
return false;
}
bool PeltierCtrlModule::dumpErrorInfo() { //
if (m_index == kpeltier0) {
ZLOGI(TAG, "motor0 fault:%d,sense:%d", peltier0.isFault(), peltier0.getSensePinState());
} else if (m_index == kpeltier1) {
ZLOGI(TAG, "motor1 fault:%d,sense:%d", peltier1.isFault(), peltier1.getSensePinState());
} else if (m_index == kpeltier0and1) {
ZLOGI(TAG, "motor0 fault:%d,sense:%d", peltier0.isFault(), peltier0.getSensePinState());
ZLOGI(TAG, "motor1 fault:%d,sense:%d", peltier1.isFault(), peltier1.getSensePinState());
}
return true;
};
bool PeltierCtrlModule::isWorking() { return m_workflag; }
void PeltierCtrlModule::clearError() {
if (m_index == kpeltier0) {
peltier0.clearFault();
} else if (m_index == kpeltier1) {
peltier1.clearFault();
} else if (m_index == kpeltier0and1) {
peltier0.clearFault();
peltier1.clearFault();
}
}