新增 CommonCenter 类和 Config 结构体,提供超声波测距功能的配置和实例化支持
All checks were successful
Build and Upload Artifact / build and upload-artifact (push) Successful in 20m2s

This commit is contained in:
chauyinn
2025-05-10 18:23:47 +08:00
parent b9a9165c71
commit 3f2e7bf019
3 changed files with 32 additions and 0 deletions

View File

@@ -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;
}
};

View File

@@ -3,11 +3,13 @@
#include "Common/serial_port.hpp" #include "Common/serial_port.hpp"
#include "Helper/gpio_helper.hpp" #include "Helper/gpio_helper.hpp"
#include "Center/common_center.hpp"
void Setup() { void Setup() {
GpioHelper::EnableAllGpioPeripheral(); GpioHelper::EnableAllGpioPeripheral();
DelaySetup(); DelaySetup();
auto ultrasonic = CommonCenter::GetUltrasonic();
} }
extern "C" void AppStart() { extern "C" void AppStart() {

14
Core/App/config.hpp Normal file
View File

@@ -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};
};