From 686569b3965efffae276621425483cd8bcb1e192 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 24 Aug 2024 14:41:08 +0800 Subject: [PATCH] init --- .settings/language.settings.xml | 4 +- stm32basic | 2 +- stm32components | 2 +- transmit_disinfection_micro (1).launch | 1 + .../preportional_valve/preportional_valve_ctrl.cpp | 2 +- usrc/app/dmapp.cpp | 8 +- usrc/app/dmapp.cpp.bak | 163 --------------------- usrc/app_main.cpp | 4 +- usrc/board/hal/hal.hpp | 3 +- .../hal/large_space_dm_liquid_ctrl_board_hal.cpp | 40 +---- .../hal/large_space_dm_liquid_ctrl_board_hal.hpp | 1 - usrc/board/hal/zhal_initer.cpp | 59 ++++++++ usrc/board/hal/zhal_initer.hpp | 13 ++ 13 files changed, 88 insertions(+), 214 deletions(-) delete mode 100644 usrc/app/dmapp.cpp.bak create mode 100644 usrc/board/hal/zhal_initer.cpp create mode 100644 usrc/board/hal/zhal_initer.hpp diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 02e817d..6106b10 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/stm32basic b/stm32basic index 7628a01..bed34d4 160000 --- a/stm32basic +++ b/stm32basic @@ -1 +1 @@ -Subproject commit 7628a01fff313fd263d7de7e93d7d652b4325e59 +Subproject commit bed34d48c7e2a5e019af3a567d4de3b47702c4dc diff --git a/stm32components b/stm32components index b3cae2e..a3069a8 160000 --- a/stm32components +++ b/stm32components @@ -1 +1 @@ -Subproject commit b3cae2e4945639f0148a5e3034b039f5679151e3 +Subproject commit a3069a8005dcb8277f95d0341551c145fac2a046 diff --git a/transmit_disinfection_micro (1).launch b/transmit_disinfection_micro (1).launch index d0bebac..edf1f4c 100644 --- a/transmit_disinfection_micro (1).launch +++ b/transmit_disinfection_micro (1).launch @@ -78,5 +78,6 @@ + diff --git a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp index 6117e74..8f8fdcb 100644 --- a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp +++ b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp @@ -12,7 +12,7 @@ using namespace zscanprotocol; void PreportionalValveCtrl::initialize(UART_HandleTypeDef* huart) {// m_modbusBlockHost.initialize(huart); - m_modbusBlockHost.enableDump(true); + m_modbusBlockHost.enableDump(false); } int32_t PreportionalValveCtrl::writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal) { diff --git a/usrc/app/dmapp.cpp b/usrc/app/dmapp.cpp index f9f3132..4a772c7 100644 --- a/usrc/app/dmapp.cpp +++ b/usrc/app/dmapp.cpp @@ -1,5 +1,6 @@ #include "dmapp.hpp" +#include "board/hal/zhal_initer.hpp" /** * @brief * 小空间和大空间硬件一样 @@ -125,8 +126,7 @@ void DisinfectionApp::initialize() { ***********************************************************************************************************************/ if (PORT::isLiquidCtrlBoard() && (PORT::isPipeDM())) { ZLOGI(TAG, "ProportionalValveCtrl init"); - LargeSpaceDMLiquidCtrlBoardHal::HUART2_INIT(9600); - printf("======================= \n"); + ZHALIniter::HUART2_INIT(PD5, PD6, 9600, UART_STOPBITS_1); proportionalValveCtrl.initialize(&huart2); } @@ -145,12 +145,12 @@ void DisinfectionApp::initialize() { if (GET_PARAM(0) == 1) { airTightnessTestChGpio.write(1); // 内管路,气密性测试 eValve0.write(0); - eValve1.write(0);// 电磁阀闭合 + eValve1.write(0); // 电磁阀闭合 state = true; } else { airTightnessTestChGpio.write(0); // 连接空气 eValve0.write(1); - eValve1.write(1);// 电磁阀打开 + eValve1.write(1); // 电磁阀打开 state = false; } zcanbus_send_ack(cxt->packet, NULL, 0); diff --git a/usrc/app/dmapp.cpp.bak b/usrc/app/dmapp.cpp.bak deleted file mode 100644 index 3ed75c6..0000000 --- a/usrc/app/dmapp.cpp.bak +++ /dev/null @@ -1,163 +0,0 @@ -#include "dmapp.hpp" - -/** - * @brief - * 小空间和大空间硬件一样 - * 管道式----- - * 液路控制板 - * 相比于大空间消毒机,不同的点: - * 1.增加比例阀控制 - * 2.空压机通道控制 - * 功率板 - * 相比于大空间消毒机,不同的点: - * 1. 风机改成鼓风机(可控风速) - * 拉杆箱------ - * 液路控制板 - * 功率板 - */ - -using namespace iflytop; -using namespace transmit_disfection_protocol; -#define TAG "DMAPP" - -DisinfectionApp* DisinfectionApp::ins() { - static DisinfectionApp instance; - return &instance; -} - -const char* DisinfectionApp::getName() { return "DisinfectionApp"; } - -void DisinfectionApp::initialize() { - int btid = PublicBoard::ins()->getBoardTypeId(); - // only support - // large space disinfection machine, - // small space disinfection machine, - // pipe disinfection machine, - ZASSERT(PORT::isLargeSpaceDM() || PORT::isLargeSpaceDM() || PORT::isPipeDM()); - - // 加热片 - if (PORT::isPowerCtrlBoard()) { - LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT(); - heaterCtrler.initialize(PC7, &hadc1, ADC_CHANNEL_2, &hadc1, ADC_CHANNEL_4); - } - - if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) { - } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) { - LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT(); - heaterCtrler.initialize(PC7, NULL, 0, &hadc1, ADC_CHANNEL_1); - } - - // 风机 - if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard)) { - LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT(); - blowerCtrler.initialize(PC5, &hadc1, ADC_CHANNEL_1); - } else if (isBoardType(kPipeDMPowerCtrlBoard)) { - LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT(); - LargeSpaceDmPowerCtrlBoardHal::HUART2_INIT(9600, UART_STOPBITS_1); - blowerCtrler.initializeAsHighPowerUartBlower(&huart2, &hadc1, ADC_CHANNEL_1); - } else if (isBoardType(kDrawBarDMPowerCtrlBoard)) { - DBDMPowerCtrlBoard::HTIM3_INIT(); - blowerCtrler.initializeAsMiniPwmBlower(&htim3, TIM_CHANNEL_3, PC6 /*en*/, PC9 /*fb*/); - } - - // 空压机 - if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard)) { - LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT(); - airComCtrler.initialize(PC3, &hadc1, ADC_CHANNEL_0); - } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) { - airComCtrler.initialize(PD14, NULL, 0); - } - - // 气密性测试空压机 - // kfn_air_tightness_test_ac_ctrl - if (isBoardType(kPipeDMPowerCtrlBoard)) { - REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) { - airComCtrler.open(GET_PARAM(0)); - zcanbus_send_ack(cxt->packet, NULL, 0); - }); - REG_LAMADA_FN(kfn_air_tightness_test_ac_is_open, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, airComCtrler.isOpen()); }); - - } else if (isBoardType(kDrawBarDMLiquidCtrlBoard)) { - static ZGPIO airCompressorCtrlGpio; - airCompressorCtrlGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false); - REG_LAMADA_FN(kfn_air_tightness_test_ac_ctrl, [&](ProcessContext* cxt) { - airCompressorCtrlGpio.write(GET_PARAM(0)); - zcanbus_send_ack(cxt->packet, NULL, 0); - }); - REG_LAMADA_FN(kfn_air_tightness_test_ac_is_open, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, airCompressorCtrlGpio.read()); }); - } - - // H2O2传感器 - if (isBoardType(kLargeSpaceDMPowerCtrlBoard, kSmallSpaceDMPowerCtrlBoard, kPipeDMPowerCtrlBoard, kDrawBarDMPowerCtrlBoard)) { - LargeSpaceDmPowerCtrlBoardHal::HUART3_INIT(19200, UART_STOPBITS_2); - LargeSpaceDmPowerCtrlBoardHal::HADC1_INIT(); - osDelay(3000); - h2o2Sensor.initialize(&huart3, &hadc1, ADC_CHANNEL_3); - } - - // 水浸传感器 - if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard)) { - ZLOGI(TAG, "WaterSensor init"); - evaporationBinWS.initAsInput(PC7, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/); - deviceBottomWS.initAsInput(PC8, kxs_gpio_nopull, kxs_gpio_no_irq, true /*mirror*/); - - REG_LAMADA_FN(kfn_device_bottom_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, deviceBottomWS.read()); }); - REG_LAMADA_FN(kfn_evaporation_tank_water_sensor_read_state, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, evaporationBinWS.read()); }); - } - - if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) { - // TMC电机初始化 - ZLOGI(TAG, "TMCMotorGroup init"); - LargeSpaceDMLiquidCtrlBoardHal::HSPI1_INIT(); - tmcPowerGroup.initialize(PB2, {&hspi1, PA4 /*cs*/, PB12 /*en*/}, {&hspi1, PC4 /*cs*/, PB13 /*en*/}); - } - - // 三色指示灯 - if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard)) { - // 三色指示灯初始化 - ZLOGI(TAG, "WarningLightDriver init"); - wlDriver.initialize(PD8, PD7, PD9, PD10); - } - - // 压力传感器初始化 - if (isBoardType(kLargeSpaceDMLiquidCtrlBoard, kSmallSpaceDMLiquidCtrlBoard, kPipeDMLiquidCtrlBoard, kDrawBarDMLiquidCtrlBoard)) { - ZLOGI(TAG, "PXXPSBus init"); - osDelay(1500); // 等待传感器上电 - LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(9600, UART_STOPBITS_1); - psBus.initialize(&huart3); - } - // 比例阀初始化 - if (isBoardType(kPipeDMLiquidCtrlBoard)) { - ZLOGI(TAG, "ProportionalValveCtrl init"); - LargeSpaceDMLiquidCtrlBoardHal::HUART2_INIT(9600); - proportionalValveCtrl.initialize(&huart2); - } - - // 气密性测试通道 - if (isBoardType(kPipeDMLiquidCtrlBoard)) { - static ZGPIO airTightnessTestChGpio; - static ZGPIO eValve; - static bool state = false; - airTightnessTestChGpio.initAsOutput(PD15, kxs_gpio_nopull, true, false); - eValve.initAsOutput(PD14, kxs_gpio_nopull, false, true); - - REG_LAMADA_FN(kfn_air_tightness_test_cutoff_ch, [&](ProcessContext* cxt) { - airTightnessTestChGpio.write(1); // 内管路,气密性测试 - eValve.write(0); // 电磁阀闭合 - state = true; - zcanbus_send_ack(cxt->packet, NULL, 0); - }); - REG_LAMADA_FN(kfn_air_tightness_test_release_ch, [&](ProcessContext* cxt) { - airTightnessTestChGpio.write(0); // 连接空气 - eValve.write(1); // 电磁阀打开 - state = false; - zcanbus_send_ack(cxt->packet, NULL, 0); - }); - // kfn_air_tightness_test_is_cutoff - REG_LAMADA_FN(kfn_air_tightness_test_is_cutoff, [&](ProcessContext* cxt) { zcanbus_send_ack(cxt->packet, state); }); - } -} - -/*********************************************************************************************************************** - * PROTOCOL_BIND * - ***********************************************************************************************************************/ diff --git a/usrc/app_main.cpp b/usrc/app_main.cpp index 0fc1a6c..a363438 100644 --- a/usrc/app_main.cpp +++ b/usrc/app_main.cpp @@ -140,10 +140,10 @@ void umain() { SysMgr::ins()->dumpSysInfo(); ZLOGI(TAG, "="); zcanbus_send_report(kreport_device_reset, NULL, 0, 100); - MX_IWDG_Init(); + // MX_IWDG_Init(); while (true) { osDelay(30); debug_light_ctrl(); - HAL_IWDG_Refresh(&hiwdg); + // HAL_IWDG_Refresh(&hiwdg); } } diff --git a/usrc/board/hal/hal.hpp b/usrc/board/hal/hal.hpp index 18e2207..22a350d 100644 --- a/usrc/board/hal/hal.hpp +++ b/usrc/board/hal/hal.hpp @@ -3,4 +3,5 @@ #include "dbdm_power_ctrl_board.hpp" #include "h2o2_ext_board.hpp" #include "large_space_dm_liquid_ctrl_board_hal.hpp" -#include "large_space_dm_power_ctrl_board.hpp" \ No newline at end of file +#include "large_space_dm_power_ctrl_board.hpp" +#include "zhal_initer.hpp" \ No newline at end of file diff --git a/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.cpp b/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.cpp index fb371ba..c06784c 100644 --- a/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.cpp +++ b/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.cpp @@ -108,47 +108,11 @@ void LargeSpaceDMLiquidCtrlBoardHal::HUART3_INIT(int baudrate, uint32_t StopBits __HAL_LINKDMA(uartHandle, hdmatx, hdma1_stream3); - HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(USART3_IRQn); + HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(USART3_IRQn); HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn); HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 5, 0); HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn); } - -void LargeSpaceDMLiquidCtrlBoardHal::HUART2_INIT(int baudrate, uint32_t StopBits) { - __HAL_RCC_USART2_CLK_ENABLE(); - __HAL_RCC_GPIOD_CLK_ENABLE(); - - - GPIO_InitTypeDef GPIO_InitStruct = {0}; - - huart2.Instance = USART2; - huart2.Init.BaudRate = baudrate; - huart2.Init.WordLength = UART_WORDLENGTH_8B; - huart2.Init.StopBits = StopBits; - huart2.Init.Parity = UART_PARITY_NONE; - huart2.Init.Mode = UART_MODE_TX_RX; - huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; - huart2.Init.OverSampling = UART_OVERSAMPLING_16; - if (HAL_UART_Init(&huart2) != HAL_OK) { - Error_Handler(); - } - - UART_HandleTypeDef* uartHandle = &huart3; - /**USART2 GPIO Configuration - PD5 ------> USART2_TX - PD6 ------> USART2_RX - */ - GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF7_USART2; - HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /* USART2 interrupt Init */ - HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); - HAL_NVIC_EnableIRQ(USART2_IRQn); -} diff --git a/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.hpp b/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.hpp index db78e55..c53037a 100644 --- a/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.hpp +++ b/usrc/board/hal/large_space_dm_liquid_ctrl_board_hal.hpp @@ -15,7 +15,6 @@ class LargeSpaceDMLiquidCtrlBoardHal { * @param StopBits UART_STOPBITS_1 UART_STOPBITS_2 */ static void HUART3_INIT(int baudrate, uint32_t StopBits); - static void HUART2_INIT(int baudrate, uint32_t StopBits = UART_STOPBITS_1); private: }; diff --git a/usrc/board/hal/zhal_initer.cpp b/usrc/board/hal/zhal_initer.cpp new file mode 100644 index 0000000..7858792 --- /dev/null +++ b/usrc/board/hal/zhal_initer.cpp @@ -0,0 +1,59 @@ +#include "zhal_initer.hpp" + +#include "base/appdep.hpp" + +using namespace iflytop; + +void ZHALIniter::HUART2_INIT(Pin_t tx, Pin_t rx, int baudrate, uint32_t StopBits) { + + __HAL_RCC_USART2_CLK_ENABLE(); + __HAL_RCC_DMA1_CLK_ENABLE(); + zaf_enable_clock(tx); + zaf_enable_clock(rx); + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + huart2.Instance = USART2; + huart2.Init.BaudRate = baudrate; + huart2.Init.WordLength = UART_WORDLENGTH_8B; + huart2.Init.StopBits = StopBits; + huart2.Init.Parity = UART_PARITY_NONE; + huart2.Init.Mode = UART_MODE_TX_RX; + huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart2.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart2) != HAL_OK) { + Error_Handler(); + } + + GPIO_InitStruct.Pin = chip_get_pinoff(tx); + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART2; + HAL_GPIO_Init(chip_get_gpio(tx), &GPIO_InitStruct); + + GPIO_InitStruct.Pin = chip_get_pinoff(rx); + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART2; + HAL_GPIO_Init(chip_get_gpio(rx), &GPIO_InitStruct); + + + /* USART2 interrupt Init */ + HAL_NVIC_SetPriority(USART2_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(USART2_IRQn); + + + + /* USART2 interrupt Init */ + HAL_NVIC_SetPriority(USART2_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(USART2_IRQn); + + __HAL_RCC_DMA1_CLK_ENABLE(); + HalUtils::uartdmainit(&huart2, &hdma1_stream5, DMA_CHANNEL_4, &hdma1_stream6, DMA_CHANNEL_4); + HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn); + HAL_NVIC_SetPriority(DMA1_Stream6_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream6_IRQn); +} diff --git a/usrc/board/hal/zhal_initer.hpp b/usrc/board/hal/zhal_initer.hpp new file mode 100644 index 0000000..d5cdf66 --- /dev/null +++ b/usrc/board/hal/zhal_initer.hpp @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +#include "base/appdep.hpp" +namespace iflytop { +class ZHALIniter { + public: + static void HUART2_INIT(Pin_t tx, Pin_t rx, int baudrate, uint32_t StopBits); + + private: +}; +} // namespace iflytop \ No newline at end of file