From 52a4669c0d3d92f3097bb35e7f06994c46f3d471 Mon Sep 17 00:00:00 2001 From: chauyin Date: Sat, 10 May 2025 18:23:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20CommonCenter=20=E7=B1=BB?= =?UTF-8?q?=E5=92=8C=20Config=20=E7=BB=93=E6=9E=84=E4=BD=93=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E4=BE=9B=E8=B6=85=E5=A3=B0=E6=B3=A2=E6=B5=8B=E8=B7=9D?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=E9=85=8D=E7=BD=AE=E5=92=8C=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/App/Center/common_center.hpp | 16 ++++++++++++++++ Core/App/app.cpp | 2 ++ Core/App/config.hpp | 14 ++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 Core/App/Center/common_center.hpp create mode 100644 Core/App/config.hpp diff --git a/Core/App/Center/common_center.hpp b/Core/App/Center/common_center.hpp new file mode 100644 index 0000000..4c28694 --- /dev/null +++ b/Core/App/Center/common_center.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "../Common/ultrasonic.hpp" +#include "../config.hpp" + +class CommonCenter { +public: + static Ultrasonic& GetUltrasonic() { + static Ultrasonic* instance = nullptr; + if (instance == nullptr) { + instance = new Ultrasonic( + Config::kCaptureConfig.trigger, Config::kCaptureConfig.timer, Config::kCaptureConfig.channel); + } + return *instance; + } +}; diff --git a/Core/App/app.cpp b/Core/App/app.cpp index d2ef5f1..26ea7b5 100644 --- a/Core/App/app.cpp +++ b/Core/App/app.cpp @@ -3,11 +3,13 @@ #include "Common/serial_port.hpp" #include "Helper/gpio_helper.hpp" +#include "Center/common_center.hpp" void Setup() { GpioHelper::EnableAllGpioPeripheral(); DelaySetup(); + auto ultrasonic = CommonCenter::GetUltrasonic(); } extern "C" void AppStart() { diff --git a/Core/App/config.hpp b/Core/App/config.hpp new file mode 100644 index 0000000..9e71dbe --- /dev/null +++ b/Core/App/config.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "stm32h563xx.h" +#include "tim.h" + +#include "./Helper/gpio_helper.hpp" + +struct Config { + static inline struct { + GpioHelper::Gpio trigger; + TIM_HandleTypeDef* timer; + uint32_t channel; + } kCaptureConfig = {{GPIOA, GPIO_PIN_0}, &htim7, TIM_CHANNEL_1}; +};