|
|
@ -9,12 +9,17 @@ |
|
|
|
//
|
|
|
|
#include "sdk\components\flash\znvs.hpp"
|
|
|
|
//
|
|
|
|
#include "sdk/components/step_motor_ctrl_module/step_motor_ctrl_module.hpp"
|
|
|
|
#include "sdk\components\pipette_module\pipette_ctrl_module_v2.hpp"
|
|
|
|
#include "sdk\components\sensors\m3078\m3078_code_scaner.hpp"
|
|
|
|
#include "sdk\components\sensors\tmp117\tmp117.hpp"
|
|
|
|
#include "sdk\components\ti\drv8710.hpp"
|
|
|
|
#include "sdk\components\tmc\ic\ztmc5130.hpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\pwm_ctrl_module.hpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module.hpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.cpp"
|
|
|
|
#include "sdk\components\water_cooling_temperature_control_module\water_cooling_temperature_control_module_factory.hpp"
|
|
|
|
// #include "M3078CodeScanner"
|
|
|
|
|
|
|
|
#define TAG "main"
|
|
|
|
using namespace iflytop; |
|
|
@ -24,27 +29,78 @@ extern void umain(); |
|
|
|
extern "C" { |
|
|
|
void StartDefaultTask(void const* argument) { umain(); } |
|
|
|
} |
|
|
|
|
|
|
|
extern "C" { |
|
|
|
extern DMA_HandleTypeDef hdma_usart2_rx; |
|
|
|
extern DMA_HandleTypeDef hdma_usart2_tx; |
|
|
|
} |
|
|
|
static ZCanCmder g_zcanCmder; |
|
|
|
static ZIProtocolParser g_ziProtocolParser; |
|
|
|
//
|
|
|
|
static TMC5130 g_motor; |
|
|
|
static StepMotorCtrlModule g_stepMotorCtrlModule; |
|
|
|
//
|
|
|
|
static PipetteModule g_pipetteModule; |
|
|
|
// USART4_TX
|
|
|
|
|
|
|
|
uint8_t getId() { |
|
|
|
static bool init = false; |
|
|
|
static ZGPIO ID0; |
|
|
|
static ZGPIO ID1; |
|
|
|
static ZGPIO ID2; |
|
|
|
static ZGPIO ID3; |
|
|
|
static ZGPIO ID4; |
|
|
|
if (!init) { |
|
|
|
ID0.initAsInput(ID0_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
ID1.initAsInput(ID1_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
ID2.initAsInput(ID2_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
ID3.initAsInput(ID3_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
ID4.initAsInput(ID4_IO, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
init = true; |
|
|
|
void init_and_reg_motor() { |
|
|
|
osDelay(1000); |
|
|
|
{ |
|
|
|
TMC5130::cfg_t cfg = { |
|
|
|
.spi = &TMC_MOTOR_SPI, //
|
|
|
|
.csgpio = MOTOR0_CSN, //
|
|
|
|
.ennPin = MOTOR0_ENN, //
|
|
|
|
.spi_mode_select = MOTOR1_SPI_MODE_SELECT, //
|
|
|
|
}; |
|
|
|
g_motor.initialize(&cfg); |
|
|
|
g_motor.setMotorShaft(false); |
|
|
|
ZLOGI(TAG, "motora initialize 5160:%x ", g_motor.readICVersion()); |
|
|
|
} |
|
|
|
uint8_t id = ID0.getState() * 1 + ID1.getState() * 2 + ID2.getState() * 4 + ID3.getState() * 8 + ID4.getState() * 16; |
|
|
|
return id; |
|
|
|
|
|
|
|
g_motor.setAcceleration(100); |
|
|
|
g_motor.setDeceleration(100); |
|
|
|
g_motor.setIHOLD_IRUN(0, 8, 10); |
|
|
|
|
|
|
|
static ZGPIO input[10]; |
|
|
|
input[0].initAsInput(PD1 /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[1].initAsInput(PD2 /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[2].initAsInput(PD3 /*DIAG0*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
input[3].initAsInput(PD4 /*DIAG1*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); |
|
|
|
|
|
|
|
g_stepMotorCtrlModule.initialize(BOARD_ID * 10 + 1, &g_motor, input, ZARRAY_SIZE(input), MOTOR_CFG_FLASH_MARK); |
|
|
|
g_ziProtocolParser.registerModule(&g_stepMotorCtrlModule); |
|
|
|
} |
|
|
|
|
|
|
|
void init_and_reg_cliptip_module() { |
|
|
|
// # RS232输出压力流
|
|
|
|
// /1U2!0R\r
|
|
|
|
// # 设置移液枪最大行程100,防止设备误操作导致吸入液体到设备中
|
|
|
|
// /1u1,100R\r
|
|
|
|
PipetteModule::config_t cfg = { |
|
|
|
.limit_ul = 100, |
|
|
|
}; |
|
|
|
|
|
|
|
PipetteModule::hardward_config_t hardwarecfg = { |
|
|
|
.uart = &huart2, |
|
|
|
.hdma_rx = &hdma_usart2_rx, |
|
|
|
.hdma_tx = &hdma_usart2_tx, |
|
|
|
}; |
|
|
|
g_pipetteModule.initialize(BOARD_ID * 10 + 2, &cfg, &hardwarecfg); |
|
|
|
g_ziProtocolParser.registerModule(&g_pipetteModule); |
|
|
|
} |
|
|
|
|
|
|
|
void init_and_reg_m3078() { //
|
|
|
|
static M3078CodeScanner codescanner; |
|
|
|
static M3078CodeScanner::hardware_config_t cfg = { |
|
|
|
.uart = &huart2, |
|
|
|
.hdma_rx = nullptr, |
|
|
|
.hdma_tx = nullptr, |
|
|
|
|
|
|
|
.codeReadOkPin = PinNull, |
|
|
|
.rstPin = PinNull, |
|
|
|
.triggerPin = PD15, |
|
|
|
}; |
|
|
|
codescanner.initialize(BOARD_ID * 10 + 3, &cfg); |
|
|
|
g_ziProtocolParser.registerModule(&codescanner); |
|
|
|
} |
|
|
|
|
|
|
|
void umain() { |
|
|
@ -59,17 +115,8 @@ void umain() { |
|
|
|
zos_cfg_t zoscfg; |
|
|
|
zos_init(&zoscfg); |
|
|
|
|
|
|
|
uint8_t deviceId = getId(); |
|
|
|
ZLOGI(TAG, "motorId:%d", deviceId); |
|
|
|
|
|
|
|
if (deviceId == 0) { |
|
|
|
ZLOGE(TAG, "motorId can't be 0"); |
|
|
|
chip_set_error(); |
|
|
|
while (true) { |
|
|
|
} |
|
|
|
} |
|
|
|
ZLOGI(TAG, "boardId:%d", BOARD_ID); |
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*******************************************************************************
|
|
|
|
* NVSINIT * |
|
|
|
*******************************************************************************/ |
|
|
@ -80,124 +127,13 @@ void umain() { |
|
|
|
ZNVS::ins().alloc_config(MOTOR_CFG_FLASH_MARK, (uint8_t*)&cfg, sizeof(cfg)); |
|
|
|
} |
|
|
|
ZNVS::ins().init_config(); |
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 风扇配置 * |
|
|
|
*******************************************************************************/ |
|
|
|
PWMSpeedCtrlModule::config_t fan0cfg = { |
|
|
|
.fanCtrlTim = &htim2, |
|
|
|
.nfan = 2, |
|
|
|
.fan0Channel = {3, 0, 0, 0}, |
|
|
|
.fanFBGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC10}, |
|
|
|
{.pin = PC11}, |
|
|
|
}, |
|
|
|
.fanPowerGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC4, .mode = ZGPIO::kMode_nopull, .mirror = false}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
PWMSpeedCtrlModule::config_t fan1cfg = { |
|
|
|
.fanCtrlTim = &htim2, |
|
|
|
.nfan = 2, |
|
|
|
.fan0Channel = {4, 0, 0, 0}, |
|
|
|
.fanFBGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC12}, |
|
|
|
{.pin = PC13}, |
|
|
|
}, |
|
|
|
.fanPowerGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC5, .mode = ZGPIO::kMode_nopull, .mirror = false}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 水泵配置 * |
|
|
|
*******************************************************************************/ |
|
|
|
PWMSpeedCtrlModule::config_t pumpcfg = { |
|
|
|
.fanCtrlTim = &htim2, |
|
|
|
.nfan = 1, |
|
|
|
.fan0Channel = {2, 0, 0, 0}, |
|
|
|
.fanFBGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC3}, |
|
|
|
}, |
|
|
|
.fanPowerGpioCfg = |
|
|
|
{ |
|
|
|
{.pin = PC2, .mode = ZGPIO::kMode_nopull, .mirror = false}, |
|
|
|
}, |
|
|
|
}; |
|
|
|
|
|
|
|
DRV8710::config_t peltier_config0 = { |
|
|
|
.tim = &htim1, |
|
|
|
.in1_chnannel_index = 1, |
|
|
|
.in2 = PE10, |
|
|
|
.nsleep = PB2, |
|
|
|
.nfault = PB3, |
|
|
|
.shaft = false, |
|
|
|
}; |
|
|
|
|
|
|
|
DRV8710::config_t peltier_config1 = { |
|
|
|
.tim = &htim1, |
|
|
|
.in1_chnannel_index = 3, |
|
|
|
.in2 = PE14, |
|
|
|
.nsleep = PB13, |
|
|
|
.nfault = PB14, |
|
|
|
.shaft = false, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
static TMP117 temp[4]; |
|
|
|
static PWMSpeedCtrlModule fan0; |
|
|
|
static PWMSpeedCtrlModule fan1; |
|
|
|
static PWMSpeedCtrlModule pump; |
|
|
|
static DRV8710 peltier0; |
|
|
|
static DRV8710 peltier1; |
|
|
|
|
|
|
|
static WaterCoolingTemperatureControlModule waterCoolingTemperatureControlModule; |
|
|
|
|
|
|
|
fan0.initialize(&fan0cfg, true); |
|
|
|
fan1.initialize(&fan1cfg, true); |
|
|
|
pump.initialize(&pumpcfg, false); |
|
|
|
peltier0.initialize(&peltier_config0); |
|
|
|
peltier1.initialize(&peltier_config1); |
|
|
|
|
|
|
|
temp[0].initializate(&hi2c1, TMP117::ID0); |
|
|
|
temp[1].initializate(&hi2c1, TMP117::ID1); |
|
|
|
temp[2].initializate(&hi2c1, TMP117::ID2); |
|
|
|
temp[3].initializate(&hi2c1, TMP117::ID3); |
|
|
|
|
|
|
|
WaterCoolingTemperatureControlModule::config_t temp_ctrl_config; |
|
|
|
waterCoolingTemperatureControlModule.createDefaultConfig(&temp_ctrl_config); |
|
|
|
|
|
|
|
WaterCoolingTemperatureControlModule::hardwared_config_t hardwared_config = //
|
|
|
|
{ |
|
|
|
.temperature_sensor = {&temp[0], &temp[1], &temp[2], &temp[3]}, |
|
|
|
.fanTable = {&fan0, &fan1}, |
|
|
|
.pump = &pump, |
|
|
|
.peltier_ctrl = {&peltier0, &peltier1}, |
|
|
|
.ext_input = |
|
|
|
{ |
|
|
|
{PC6, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true}, |
|
|
|
{PC7, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true}, |
|
|
|
}, |
|
|
|
.ext_output = |
|
|
|
{ |
|
|
|
{PD0, ZGPIO::kMode_nopull, false, false}, |
|
|
|
} //
|
|
|
|
}; |
|
|
|
|
|
|
|
waterCoolingTemperatureControlModule.initialize(deviceId, &temp_ctrl_config, &hardwared_config); |
|
|
|
|
|
|
|
auto zcanCmder_cfg = g_zcanCmder.createCFG(deviceId); |
|
|
|
auto zcanCmder_cfg = g_zcanCmder.createCFG(BOARD_ID); |
|
|
|
g_zcanCmder.init(zcanCmder_cfg); |
|
|
|
|
|
|
|
g_ziProtocolParser.initialize(&g_zcanCmder); |
|
|
|
g_ziProtocolParser.registerModule(&waterCoolingTemperatureControlModule); |
|
|
|
|
|
|
|
init_and_reg_motor(); |
|
|
|
init_and_reg_cliptip_module(); |
|
|
|
init_and_reg_m3078(); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
OSDefaultSchduler::getInstance()->loop(); |
|
|
|