diff --git a/a8000_protocol b/a8000_protocol index ba9d990..8fa3934 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit ba9d9901d640255796df949d24351064c1994bc8 +Subproject commit 8fa3934e833a116d68d4c32ebba8352ce1b8746f diff --git a/doc/ADC通道映射.png b/doc/ADC通道映射.png new file mode 100644 index 0000000..7de6377 Binary files /dev/null and b/doc/ADC通道映射.png differ diff --git a/doc/定时器映射表.png b/doc/定时器映射表.png new file mode 100644 index 0000000..e37c6ed Binary files /dev/null and b/doc/定时器映射表.png differ diff --git a/sdk b/sdk index f204e7c..775c939 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit f204e7c9f2418a9859ef30dd019356ace745b15c +Subproject commit 775c939fac59bda652b7b2e42bf76b212d091b7e diff --git a/usrc/public_service/ext_board_impl.cpp b/usrc/public_service/ext_board_impl.cpp index f0b748c..59f02e0 100644 --- a/usrc/public_service/ext_board_impl.cpp +++ b/usrc/public_service/ext_board_impl.cpp @@ -31,4 +31,14 @@ int32_t ExtBoardImpl::board_read_muti_io(int32_t *val) { } return 0; +} +int32_t ExtBoardImpl::board_read_inio_index_in_stm32(int32_t ioindex, int32_t *val) { + if (ioindex < 0 || ioindex >= ZARRAY_SIZE(IO)) return err::kparam_out_of_range; + *val = IO[ioindex].getPin(); + return 0; +} +int32_t ExtBoardImpl::board_read_outio_index_in_stm32(int32_t ioindex, int32_t *val) { + if (ioindex < 0 || ioindex >= ZARRAY_SIZE(IO)) return err::kparam_out_of_range; + *val = IO[ioindex].getPin(); + return 0; } \ No newline at end of file diff --git a/usrc/public_service/ext_board_impl.hpp b/usrc/public_service/ext_board_impl.hpp index d10eace..e37a4de 100644 --- a/usrc/public_service/ext_board_impl.hpp +++ b/usrc/public_service/ext_board_impl.hpp @@ -35,6 +35,8 @@ class ExtBoardImpl : public ZIBoard, public ZIModule { virtual int32_t board_read_ext_io(int32_t ioindex, int32_t *val); virtual int32_t board_write_ext_io(int32_t ioindex, int32_t val); virtual int32_t board_read_muti_io(int32_t *val); + virtual int32_t board_read_inio_index_in_stm32(int32_t ioindex, int32_t *val); + virtual int32_t board_read_outio_index_in_stm32(int32_t ioindex, int32_t *val); virtual int32_t getmoduleId(int off); }; diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/fan_ctrl_module.cpp b/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/fan_ctrl_module.cpp index 507b1b8..d47f6cf 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/fan_ctrl_module.cpp +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/fan_ctrl_module.cpp @@ -1,70 +1,16 @@ #include "fan_ctrl_module.hpp" +#include "../pri_board.h" #include "public_service\gins.h" using namespace iflytop; -#define TIMER2_FREQ 1000 -#define TIMER1_FREQ 1000 -#define ENABL_TRACE false - #define TAG "FanCtrlModule" /******************************************************************************* * 风扇配置 * *******************************************************************************/ -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, -}; + +PWMSpeedCtrlModule::config_t fan0cfg = FAN0_CFG; +PWMSpeedCtrlModule::config_t fan1cfg = FAN1_CFG; /******************************************************************************* * FanCtrlModule * diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/peltier_ctrl_module.cpp b/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/peltier_ctrl_module.cpp index b2ab429..36575de 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/peltier_ctrl_module.cpp +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/peltier_ctrl_module.cpp @@ -1,53 +1,17 @@ #include "peltier_ctrl_module.hpp" +#include "../pri_board.h" #include "public_service/public_service.hpp" -#define PELTIER_POLARITY false -#define TIMER2_FREQ 1000 -#define TIMER1_FREQ 1000 -#define ENABL_TRACE false - using namespace iflytop; #define TAG "PeltierCtrlModule" -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, -}; +DRV8710::config_t peltier_config0 = PELTIER_CONFIG0; +DRV8710::config_t peltier_config1 = PELTIER_CONFIG1; void PeltierCtrlModule::initialize(peltier_index_t index) { m_index = index; - if (m_index == kpeltier0) { peltier0.initialize(&peltier_config0); } else if (m_index == kpeltier1) { diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/pump_ctrl_module.cpp b/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/pump_ctrl_module.cpp index 22d6812..7f41d83 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/pump_ctrl_module.cpp +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/drivers/pump_ctrl_module.cpp @@ -1,11 +1,10 @@ #include "pump_ctrl_module.hpp" #include "public_service\gins.h" +#include "../pri_board.h" + using namespace iflytop; -#define TIMER2_FREQ 1000 -#define TIMER1_FREQ 1000 -#define ENABL_TRACE false PWMSpeedCtrlModule::config_t pumpcfg = { .name = "pump", diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/pri_board.h b/usrc/subboards/subboard40_and_50_temperature_ctrl/pri_board.h index 3693848..d3b98bd 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/pri_board.h +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/pri_board.h @@ -30,4 +30,113 @@ #define EXT_OUTPUT_IO6 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ #define EXT_OUTPUT_IO7 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ #define EXT_OUTPUT_IO8 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ -#define EXT_OUTPUT_IO9 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ \ No newline at end of file +#define EXT_OUTPUT_IO9 PinNull, ZGPIO::kMode_nopull, false /*mirror*/, true /*init val*/ + +#define PELTIER_POLARITY false +#define TIMER2_FREQ 1000 +#define TIMER1_FREQ 1000 +#define ENABL_TRACE true + +#define FAN0_CFG \ + { \ + .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, \ + } + +#define FAN1_CFG \ + { \ + .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, \ + } + +#define PELTIER_CONFIG0 \ + { \ + .pwm_cfg = \ + { \ + .name = "peltier1_pwm", \ + .htim = &htim1, \ + .freq = TIMER1_FREQ, \ + .polarity = false, \ + }, \ + .in1_chnannel_index = 3, .in2 = PE14, .nsleep = PB13, .nfault = PB14, .sensePin = PB15, .shaft = PELTIER_POLARITY, .enableTrace = ENABL_TRACE, \ + } + +#define PELTIER_CONFIG1 \ + { \ + .pwm_cfg = \ + { \ + .name = "peltier0_pwm", \ + .htim = &htim1, \ + .freq = TIMER1_FREQ, \ + .polarity = false, \ + }, \ + .in1_chnannel_index = 1, .in2 = PE11, .nsleep = PB2, .nfault = PB3, .sensePin = PB4, .shaft = !PELTIER_POLARITY, .enableTrace = ENABL_TRACE, \ + } + +#define PUMP_CFG \ + { \ + .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, \ + } \ No newline at end of file diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl.cpp b/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl.cpp index f82da7e..3d8a84e 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl.cpp +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl.cpp @@ -60,7 +60,7 @@ void Subboard40And50TemperatureCtrl::initialize() { ZLOGI(TAG, "temperature %d", i, temp[i].getTemperature()); } - if (getPeltierNum() == 1) { + if (getmoduleId(0) == 40) { fan.initialize(FanCtrlModule::kfan0); peltier.initialize(PeltierCtrlModule::kpeltier0); } else { @@ -88,7 +88,7 @@ void Subboard40And50TemperatureCtrl::initialize() { GService::inst()->getZCanProtocolParser()->registerModule(&waterCoolingTemperatureControlModule); } - if (getPeltierNum() == 1) { + if (getmoduleId(0) == 40) { static FanCtrlModule fan; static ZcanFanCtrlModule fan_ctrl_module; fan.initialize(FanCtrlModule::kfan1); diff --git a/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl_board.c b/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl_board.c index a0bbd1b..8034766 100644 --- a/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl_board.c +++ b/usrc/subboards/subboard40_and_50_temperature_ctrl/subboard40_and_50_temperature_ctrl_board.c @@ -37,7 +37,7 @@ void MX_TIM2_Init(void) { Error_Handler(); } /* USER CODE END TIM2_Init 2 */ - //HAL_TIM_MspPostInit(&htim2); + // HAL_TIM_MspPostInit(&htim2); GPIO_InitTypeDef GPIO_InitStruct = {0}; @@ -52,6 +52,90 @@ void MX_TIM2_Init(void) { GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF1_TIM2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + htim2_enable = true; +} + +void MX_TIM1_Init(void) { + /* USER CODE BEGIN TIM1_Init 0 */ + + /* USER CODE END TIM1_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + TIM_OC_InitTypeDef sConfigOC = {0}; + TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0}; + + /* USER CODE BEGIN TIM1_Init 1 */ + + /* USER CODE END TIM1_Init 1 */ + htim1.Instance = TIM1; + htim1.Init.Prescaler = 143; + htim1.Init.CounterMode = TIM_COUNTERMODE_UP; + htim1.Init.Period = 9999; + htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim1.Init.RepetitionCounter = 0; + htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE; + if (HAL_TIM_Base_Init(&htim1) != HAL_OK) { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + if (HAL_TIM_PWM_Init(&htim1) != HAL_OK) { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) { + Error_Handler(); + } + sConfigOC.OCMode = TIM_OCMODE_PWM1; + sConfigOC.Pulse = 0; + sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; + sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH; + sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; + sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET; + sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET; + if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) { + Error_Handler(); + } + if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) { + Error_Handler(); + } + sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE; + sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE; + sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF; + sBreakDeadTimeConfig.DeadTime = 0; + sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE; + sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH; + sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE; + if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN TIM1_Init 2 */ + + /* USER CODE END TIM1_Init 2 */ + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + /* USER CODE BEGIN TIM1_MspPostInit 0 */ + + /* USER CODE END TIM1_MspPostInit 0 */ + __HAL_RCC_GPIOE_CLK_ENABLE(); + /**TIM1 GPIO Configuration + PE9 ------> TIM1_CH1 + PE13 ------> TIM1_CH3 + */ + GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_13; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF1_TIM1; + HAL_GPIO_Init(GPIOE, &GPIO_InitStruct); + + /* USER CODE BEGIN TIM1_MspPostInit 1 */ + + /* USER CODE END TIM1_MspPostInit 1 */ } void MX_I2C1_Init(void) { @@ -87,5 +171,6 @@ void MX_I2C1_Init(void) { void subboard40_and_50_temperature_ctrl_board_init() { common_hardware_init(); MX_TIM2_Init(); + MX_TIM1_Init(); MX_I2C1_Init(); }