diff --git a/.vscode/settings.json b/.vscode/settings.json index 7de1ea3..dbc3db6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -82,7 +82,8 @@ "public_service.h": "c", "stm32irq.h": "c", "project_configs.h": "c", - "*.bak": "c" + "*.bak": "c", + "zflash.h": "c" }, "files.autoGuessEncoding": false, "files.encoding": "utf8" diff --git a/auto.py b/auto.py new file mode 100644 index 0000000..1090d79 --- /dev/null +++ b/auto.py @@ -0,0 +1,17 @@ +import time +import ctypes +from pynput.keyboard import Key +from pynput.keyboard import Controller +a=0 +while True: + if ctypes.windll.user32.GetForegroundWindow() == 0: + print('0') + time.sleep(2) + else: + a = a+1 + b = Controller() + b.press(Key.f20) + b.release(Key.f20) + time.sleep(30) + print('1') + print(a) diff --git a/stm32basic b/stm32basic index 7628a01..219877a 160000 --- a/stm32basic +++ b/stm32basic @@ -1 +1 @@ -Subproject commit 7628a01fff313fd263d7de7e93d7d652b4325e59 +Subproject commit 219877a3ae5cfabe04211a9121eac9519b6081cc diff --git a/stm32components b/stm32components index 03d9638..a3069a8 160000 --- a/stm32components +++ b/stm32components @@ -1 +1 @@ -Subproject commit 03d9638ccbc69971524957a68e51842da0960940 +Subproject commit a3069a8005dcb8277f95d0341551c145fac2a046 diff --git a/usrc/appdep.hpp b/uappbase/base.hpp similarity index 63% rename from usrc/appdep.hpp rename to uappbase/base.hpp index 2a3b287..13f3e36 100644 --- a/usrc/appdep.hpp +++ b/uappbase/base.hpp @@ -1,4 +1,5 @@ #pragma once -#include "ucomponents/ucomponents.hpp" +#include "stm32basic/stm32basic.hpp" #include "stm32halport/stm32halport.hpp" -#include "stm32basic/stm32basic.hpp" \ No newline at end of file +#include "ucomponents/ucomponents.hpp" +#include "main.h" \ No newline at end of file diff --git a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp deleted file mode 100644 index 57f1232..0000000 --- a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include "preportional_valve_ctrl.hpp" - -using namespace iflytop; -using namespace zscanprotocol; - -#define WORK_STATE_REG 0x0000 -#define CTRL_STATE_REG 0x0001 -#define POS_STATE_REG 0x0013 -#define OVERTIME 30 -#define TAG "PreportionalValveCtrl" - -void PreportionalValveCtrl::initialize(UART_HandleTypeDef* huart) { m_modbusBlockHost.initialize(huart); } - -int32_t PreportionalValveCtrl::writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal) { - // 重发三次 - for (size_t i = 0; i < 3; i++) { - int32_t err = m_modbusBlockHost.writeReg06(slaveAddr, regAddr, regVal, OVERTIME); - if (err == 0) return 0; - } - return err::kerr_subdevice_offline; -} -int32_t PreportionalValveCtrl::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal) { - // 重发三次 - for (size_t i = 0; i < 3; i++) { - int32_t err = m_modbusBlockHost.readReg03(slaveAddr, regAddr, regVal, OVERTIME); - if (err == 0) return 0; - } - return err::kerr_subdevice_offline; -} - -int32_t PreportionalValveCtrl::setValvePos(int32_t valueid, int32_t pos) { // - int32_t ret = 0; - if (valueid > 255 || valueid < 1) { - return err::kerr_invalid_param; - } - ret = writeReg06(valueid, CTRL_STATE_REG, pos); - if (!ret) return err::kerr_subdevice_offline; - - m_last_set_valve_ticket = HAL_GetTick(); - m_targetpos[valueid] = pos; - return 0; -} - -int32_t PreportionalValveCtrl::getValvePos(int32_t valueid, int32_t* pos) { - int32_t ret = 0; - if (valueid > 255 || valueid < 1) { - return err::kerr_invalid_param; - } - - uint16_t pos16 = 0; - ret = readReg03(valueid, POS_STATE_REG, &pos16); - if (!ret) return err::kerr_subdevice_offline; - - *pos = pos16; - return 0; -} -int32_t PreportionalValveCtrl::getValveOrderPos(int32_t valueid, int32_t* pos) { - int32_t ret = 0; - if (valueid > 255 || valueid < 1) { - return err::kerr_invalid_param; - } - - uint16_t pos16 = 0; - ret = readReg03(valueid, CTRL_STATE_REG, &pos16); - if (!ret) return err::kerr_subdevice_offline; - - *pos = pos16; - return 0; -} - -int32_t PreportionalValveCtrl::isBusy(int32_t valueid, int32_t* busy) { -#if 1 - int32_t orderpos = 0; - int32_t pos = 0; - int32_t err = 0; - -#if 0 - err = getValveOrderPos(valueid, &orderpos); - if (err != 0) return err; -#endif - orderpos = m_targetpos[valueid]; - - err = getValvePos(valueid, &pos); - if (err != 0) return err; - - if (abs(m_targetpos[valueid] - pos) <= 11) { - *busy = 0; - } else { - *busy = 1; - } - return 0; -#endif -} - -int32_t PreportionalValveCtrl::getValveWorkState(int32_t valueid, int32_t* state) { - int32_t ret = 0; - if (valueid > 255 || valueid < 1) { - return err::kerr_invalid_param; - } - - uint16_t state16 = 0; - ret = readReg03(valueid, WORK_STATE_REG, &state16); - if (!ret) return err::kerr_subdevice_offline; - *state = state16; - return 0; -} \ No newline at end of file diff --git a/ucomponents/preportional_valve/preportional_valve_ctrl.hpp b/ucomponents/preportional_valve/preportional_valve_ctrl.hpp deleted file mode 100644 index 63c676c..0000000 --- a/ucomponents/preportional_valve/preportional_valve_ctrl.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once -#include -#include - -#include "stm32components/modbus/modbus_block_host.hpp" -#include "stm32basic/stm32basic.hpp" -#include "stm32components/stm32components.hpp" - -/** - * @brief - * - * https://iflytop1.feishu.cn/wiki/GQwCwHMqFiaJRwks80ncwaYKnSe - */ - -namespace iflytop { -using namespace std; -class PreportionalValveCtrl { - public: - typedef enum { - kstate_stop = 0x0, - kstate_running_forward = 0xaa, - kstate_running_backward = 0xbb, - kstate_err_state = 0xea, - } work_state_t; - - private: - /* data */ - ModbusBlockHost m_modbusBlockHost; - int32_t val = 0; - uint32_t m_last_set_valve_ticket = 0; - uint16_t m_targetpos[255]; - - public: - PreportionalValveCtrl() {}; - ~PreportionalValveCtrl() {}; - - void initialize(UART_HandleTypeDef* huart); - int32_t setValvePos(int32_t valueid, int32_t pos); - int32_t getValvePos(int32_t valueid, int32_t* pos); - int32_t getValveOrderPos(int32_t valueid, int32_t* pos); - int32_t isBusy(int32_t valueid, int32_t* busy); - int32_t getValveWorkState(int32_t valueid, int32_t* state); - - private: - - int32_t writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal); - int32_t readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal); -}; - -} // namespace iflytop \ No newline at end of file diff --git a/ucomponents/ucomponents.hpp b/ucomponents/ucomponents.hpp index c2c1096..7b9637e 100644 --- a/ucomponents/ucomponents.hpp +++ b/ucomponents/ucomponents.hpp @@ -1,2 +1 @@ -#pragma once -#include "preportional_valve/preportional_valve_ctrl.hpp" \ No newline at end of file +#pragma once \ No newline at end of file diff --git a/usrc/app/main_controler_ui/README.md b/ui/README.md similarity index 100% rename from usrc/app/main_controler_ui/README.md rename to ui/README.md diff --git a/usrc/app/main_controler_ui/hand_acid_mainboard_ui.HMI b/ui/hand_acid_mainboard_ui.HMI similarity index 100% rename from usrc/app/main_controler_ui/hand_acid_mainboard_ui.HMI rename to ui/hand_acid_mainboard_ui.HMI diff --git a/usrc/app/main_controler_ui/ui.h b/ui/ui.h similarity index 100% rename from usrc/app/main_controler_ui/ui.h rename to ui/ui.h diff --git a/usrc/app/apublicboard/public_board_initer.hpp b/usrc/app/apublicboard/public_board_initer.hpp deleted file mode 100644 index 5c48202..0000000 --- a/usrc/app/apublicboard/public_board_initer.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "appdep.hpp" -#include "project_configs.h" -namespace iflytop { -#define PB PublicBoardIniter::ins() -class PublicBoardIniter { - private: - /* data */ - public: - static PublicBoardIniter* ins() { - static PublicBoardIniter instance; - return &instance; - } - - void MX_TIM6_Init(); - void MX_TIM7_Init(); -}; - -} // namespace iflytop \ No newline at end of file diff --git a/usrc/app/main_controler/abasicboard/basicboard.cpp b/usrc/app/main_controler/abasicboard/basicboard.cpp deleted file mode 100644 index 0ab2347..0000000 --- a/usrc/app/main_controler/abasicboard/basicboard.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "basicboard.hpp" -using namespace iflytop; - diff --git a/usrc/app/main_controler/abasicboard/basicboard.hpp b/usrc/app/main_controler/abasicboard/basicboard.hpp deleted file mode 100644 index 28d5c51..0000000 --- a/usrc/app/main_controler/abasicboard/basicboard.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "appdep.hpp" -namespace iflytop { -using namespace std; -class BasicBoard { - private: - /* data */ - BasicBoard() {} - - public: - static BasicBoard* ins() { - static BasicBoard instance; - return &instance; - } - - -}; - -} // namespace iflytop \ No newline at end of file diff --git a/usrc/app/main_controler/main_controler.cpp b/usrc/app/main_controler/main_controler.cpp deleted file mode 100644 index 0baba7f..0000000 --- a/usrc/app/main_controler/main_controler.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "main_controler.hpp" - -using namespace iflytop; diff --git a/usrc/app/main_controler/main_controler.hpp b/usrc/app/main_controler/main_controler.hpp deleted file mode 100644 index a3b22d4..0000000 --- a/usrc/app/main_controler/main_controler.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "appdep.hpp" - -namespace iflytop { -class MainControler { - - public: - static MainControler* ins() { - static MainControler instance; - return &instance; - } - void init(){} -}; -} // namespace iflytop \ No newline at end of file diff --git a/usrc/app/valvecontroler/valvecontroler.cpp b/usrc/app/valvecontroler/valvecontroler.cpp deleted file mode 100644 index bff395d..0000000 --- a/usrc/app/valvecontroler/valvecontroler.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "valvecontroler.hpp" - -using namespace iflytop; - -void ValvaControler::init() {} \ No newline at end of file diff --git a/usrc/app/valvecontroler/valvecontroler.hpp b/usrc/app/valvecontroler/valvecontroler.hpp deleted file mode 100644 index 57cd082..0000000 --- a/usrc/app/valvecontroler/valvecontroler.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include "appdep.hpp" - -namespace iflytop { -class ValvaControler { - public: - static ValvaControler* ins() { - static ValvaControler instance; - return &instance; - } - void init(); -}; -} // namespace iflytop \ No newline at end of file diff --git a/usrc/app_main.cpp b/usrc/app_main.cpp deleted file mode 100644 index 51fdda6..0000000 --- a/usrc/app_main.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include -#include -// -#include "appdep.hpp" -#include "apppublic/boardid.hpp" -// -#include "app/main_controler/main_controler.hpp" -#include "app/valvecontroler/valvecontroler.hpp" - -#define TAG "main" -extern void umain(); -extern "C" { -void StartDefaultTask(void const *argument) { umain(); } -} -/******************************************************************************* - * MAIN * - *******************************************************************************/ - -using namespace iflytop; - -/* IWDG init function */ -void MX_IWDG_Init(void) { - hiwdg.Instance = IWDG; - hiwdg.Init.Prescaler = IWDG_PRESCALER_256; - hiwdg.Init.Reload = 501; - if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { - Error_Handler(); - } -} - -static ZGPIO debuglight0; -static ZGPIO debuglight1; -static bool errorFlag; -static inline void debugLightLoop() { - static bool light = false; - static uint32_t lastcall = 0; - - if (errorFlag) { - if (zos_haspassedms(lastcall) > 30) { - light = !light; - debuglight0.write(light); - debuglight1.write(light); - lastcall = zos_get_tick(); - } - } else { - if (zos_haspassedms(lastcall) > 300) { - light = !light; - debuglight0.write(light); - debuglight1.write(light); - lastcall = zos_get_tick(); - } - } -} - -int32_t getDeviceIdFromFlash() { - int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD; - if (*deviceId <= 0) { - return 0; - } - return *deviceId; -} - -void umain() { - MX_IWDG_Init(); - - debuglight0.initAsOutput(DEBUG_LIGHT_IO0, kxs_gpio_nopull, false, false); - debuglight1.initAsOutput(DEBUG_LIGHT_IO1, kxs_gpio_nopull, false, false); - int32_t id = getDeviceIdFromFlash(); - if (id == boardid::kbmainboard) { - MainControler::ins()->init(); - } else if (id == boardid::kvalveboard) { - ValvaControler::ins()->init(); - } else { - errorFlag = true; - } - - while (true) { - osDelay(30); - debugLightLoop(); - HAL_IWDG_Refresh(&hiwdg); - } -} diff --git a/usrc/appcfg/appcfg.hpp b/usrc/appcfg/appcfg.hpp new file mode 100644 index 0000000..6569ff4 --- /dev/null +++ b/usrc/appcfg/appcfg.hpp @@ -0,0 +1,2 @@ +#pragma once +#include "project_configs.h" \ No newline at end of file diff --git a/usrc/appcfg/publicboard.hpp b/usrc/appcfg/publicboard.hpp deleted file mode 100644 index 58c5a02..0000000 --- a/usrc/appcfg/publicboard.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define DEBUG_UART_TX PA9 -#define DEBUG_UART_RX PA10 \ No newline at end of file diff --git a/usrc/app/apublicboard/public_board_initer.cpp b/usrc/apphal/apphal.cpp similarity index 87% rename from usrc/app/apublicboard/public_board_initer.cpp rename to usrc/apphal/apphal.cpp index 888ef7e..0cfd937 100644 --- a/usrc/app/apublicboard/public_board_initer.cpp +++ b/usrc/apphal/apphal.cpp @@ -1,21 +1,7 @@ -#include "public_board_initer.hpp" - -#include "appcfg/publicboard.hpp" +#include "apphal.hpp" using namespace iflytop; -#include "main.h" -/** - * @brief 资料列表 - * - * CAN1 PA11 PA12 - * UART1 PA9 PA10 - * TIM6 - * TIM7 - * - */ - -/* TIM6 init function */ -void PublicBoardIniter::MX_TIM6_Init(void) { +void AppHal::MX_TIM6_Init(void) { __HAL_RCC_TIM6_CLK_ENABLE(); TIM_MasterConfigTypeDef sMasterConfig = {0}; @@ -38,7 +24,7 @@ void PublicBoardIniter::MX_TIM6_Init(void) { HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); } /* TIM7 init function */ -void PublicBoardIniter::MX_TIM7_Init(void) { +void AppHal::MX_TIM7_Init(void) { __HAL_RCC_TIM7_CLK_ENABLE(); TIM_MasterConfigTypeDef sMasterConfig = {0}; @@ -61,10 +47,17 @@ void PublicBoardIniter::MX_TIM7_Init(void) { HAL_NVIC_EnableIRQ(TIM7_IRQn); } -static void debug_uart_init() { +#define EARLY_ASSERT(exptr) \ + if (!exptr) { \ + while (true) { \ + } \ + } + +void AppHal::DEBUG_UART_INIT(Pin_t tx, Pin_t rx, int32_t baudrate) { GPIO_InitTypeDef GPIO_InitStruct = {0}; - static_assert(PA9 == DEBUG_UART_TX); - static_assert(PA10 == DEBUG_UART_RX); + + EARLY_ASSERT(PA9 == tx); + EARLY_ASSERT(PA10 == rx); /*********************************************************************************************************************** * IO初始化 * @@ -81,7 +74,7 @@ static void debug_uart_init() { HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); huart1.Instance = USART1; - huart1.Init.BaudRate = 460800; + huart1.Init.BaudRate = baudrate; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; @@ -114,4 +107,13 @@ static void debug_uart_init() { __HAL_LINKDMA(&huart1, hdmarx, hdma2_stream2); HAL_NVIC_SetPriority(USART1_IRQn, 5, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); -} \ No newline at end of file +} + +void AppHal::MX_IWDG_Init(void) { + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_64; + hiwdg.Init.Reload = 4095; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { + Error_Handler(); + } +} diff --git a/usrc/apphal/apphal.hpp b/usrc/apphal/apphal.hpp new file mode 100644 index 0000000..0a511dd --- /dev/null +++ b/usrc/apphal/apphal.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "appcfg/appcfg.hpp" +#include "uappbase/base.hpp" +namespace iflytop { +class AppHal { + private: + /* data */ + public: + static void MX_TIM6_Init(void); + static void MX_TIM7_Init(void); + static void DEBUG_UART_INIT(Pin_t tx, Pin_t rx, int32_t baudrate); + static void MX_IWDG_Init(void); +}; + +} // namespace iflytop diff --git a/usrc/apppublic/boardid.cpp b/usrc/apppublic/boardid.cpp deleted file mode 100644 index fe67826..0000000 --- a/usrc/apppublic/boardid.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "boardid.hpp" - -#include "appdep.hpp" -#include "project_configs.h" -using namespace iflytop; - -boardid::id_t BoardId_get() { - int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD; - if (*deviceId <= 0) { - return boardid::kunsupport; - } - return (boardid::id_t)*deviceId; -} diff --git a/usrc/apppublic/boardid.hpp b/usrc/apppublic/boardid.hpp deleted file mode 100644 index 3d6b80e..0000000 --- a/usrc/apppublic/boardid.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "appdep.hpp" -namespace iflytop { -namespace boardid { -typedef enum { - kunsupport = 0, - kbmainboard = 1, - kvalveboard = 2, -} id_t; -} - -boardid::id_t BoardId_get(); - -} // namespace iflytop diff --git a/usrc/main.c b/usrc/main.c index 9a49f67..88a7037 100644 --- a/usrc/main.c +++ b/usrc/main.c @@ -88,6 +88,8 @@ void MX_GPIO_Init(void) { GPIO_InitStruct.Alternate = GPIO_AF0_MCO; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); } +extern void umain(); +void StartDefaultTask(void const *argument) { umain(); } int main(void) { HAL_Init(); @@ -98,6 +100,7 @@ int main(void) { MX_FREERTOS_Init(); osKernelStart(); + // main is in app_core.cpp while (1) { } } diff --git a/usrc/project_configs.h b/usrc/project_configs.h index d62fe56..0783f22 100644 --- a/usrc/project_configs.h +++ b/usrc/project_configs.h @@ -7,19 +7,16 @@ #define SDK_IRQ_PREEMPTPRIORITY_DEFAULT 5 // IO中断默认中断等级 #define SDK_CFG__CFG_FLASH_ADDR 0x080C0000 // flash配置地址 #define SDK_CFG__SN_FLASH_ADDR 0x080E0004 // -#define SDK_MAX_TASK 10 // 最大任务数量 + +#define SDK_MAX_TASK 10 // 最大任务数量 +#define DEBUG_UART huart1 // 调试串口 /*********************************************************************************************************************** - * PROJECT_CONFIG * + * FLASH分区 * ***********************************************************************************************************************/ -/** - * @brief 基础配置 - */ -#define SOFTWARE_VERSION 1 // 软件版本 -#define HARDWARE_VERSION 1 // 硬件版本 -#define SN_HEADER "SN" // SN号前缀 -#define DEBUG_UART huart1 // 调试串口 -#define DEBUG_LIGHT_IO0 PE0 // 调试指示灯 -#define DEBUG_LIGHT_IO1 PE2 // 调试指示灯 +// #define BOARD_TYPE_ID_FLASH_ADD 0x080E0000 // 板子类型 +// #define SN_FLASH_ADD 0x080E0004 // 使用扇区11存储SN编码 -#define BOARD_TYPE_ID_FLASH_ADD 0x080E0000 // 板子类型 +#define SOFTWARE_VERSION 100 // 软件版本 +#define HARDWARE_VERSION 1 // 硬件版本 +#define PROJECT "hand_acid_main_board" // 工程名称 diff --git a/usrc/service/app_core.cpp b/usrc/service/app_core.cpp new file mode 100644 index 0000000..64a2d8a --- /dev/null +++ b/usrc/service/app_core.cpp @@ -0,0 +1,23 @@ +#include "app_core.hpp" + +#include +#include + +#define TAG "main" + +extern "C" { +void umain() { AppCore::ins()->initialize(); } +} +using namespace iflytop; +void AppCore::initialize() { + AppHal::MX_TIM6_Init(); + AppHal::MX_TIM7_Init(); + AppHal::DEBUG_UART_INIT(PA9, PA10, 460800); + AppHal::MX_IWDG_Init(); + + ZLOGI(TAG, "======================= boardinfo ==================== "); + ZLOGI(TAG, "project : %s ", PROJECT); + ZLOGI(TAG, "version : %d ", SOFTWARE_VERSION); + ZLOGI(TAG, "sn : %s", sn_get_str()); + ZLOGI(TAG, "="); +} diff --git a/usrc/service/app_core.hpp b/usrc/service/app_core.hpp new file mode 100644 index 0000000..95a32c7 --- /dev/null +++ b/usrc/service/app_core.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "appcfg/appcfg.hpp" +#include "apphal/apphal.hpp" +#include "uappbase/base.hpp" + +namespace iflytop { +class AppCore { + private: + /* data */ + AppCore(/* args */) {} + + public: + static AppCore* ins() { + static AppCore ins; + return &ins; + } + void initialize(); +}; + +} // namespace iflytop \ No newline at end of file