mirror of
https://github.com/goldenfishs/MRobot.git
synced 2026-04-01 05:17:13 +08:00
重构User_code目录结构:将文件组织到子文件夹中
主要更改: - 将所有BSP外设文件移动到独立子文件夹(can/, fdcan/, uart/等) - 将所有Component文件移动到独立子文件夹(pid/, filter/, cmd/等) - 将所有Device文件移动到独立子文件夹(dr16/, bmi088/等) - 更新代码生成器以支持新的文件夹结构 - 保持向后兼容性,支持从子文件夹或根目录加载模板 - 添加STRUCTURE.md文档说明新的目录结构 优势: ✅ 更好的代码组织和管理 ✅ 便于添加、删除、修改模板 ✅ 清晰的模块划分 ✅ 向后兼容现有结构
This commit is contained in:
37
assets/User_code/device/led/led.c
Normal file
37
assets/User_code/device/led/led.c
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
led控制
|
||||
*/
|
||||
/*Includes -----------------------------------------*/
|
||||
#include "device/led.h"
|
||||
#include "device.h"
|
||||
|
||||
|
||||
/* Private define ----------------------------------------------------------- */
|
||||
/* Private macro ------------------------------------------------------------ */
|
||||
/* Private typedef ---------------------------------------------------------- */
|
||||
#ifdef LED_PWM
|
||||
int8_t DEVICE_LED_PWM_Set(BSP_PWM_Channel_t channel, float duty_cycle)
|
||||
{
|
||||
if (duty_cycle < 0.0f || duty_cycle > 1.0f) {
|
||||
return DEVICE_ERR_NULL; // 错误:占空比超出范围
|
||||
}
|
||||
uint16_t pulse = (uint16_t)(duty_cycle * (float)UINT16_MAX);
|
||||
BSP_PWM_Start(channel);
|
||||
BSP_PWM_SetComp(channel, pulse);
|
||||
return DEVICE_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LED_GPIO
|
||||
int8_t DEVICE_LED_GPIO_Set(BSP_GPIO_t gpio, bool value)
|
||||
{
|
||||
if (value) {
|
||||
BSP_GPIO_WritePin(gpio, true);
|
||||
} else {
|
||||
BSP_GPIO_WritePin(gpio, false);
|
||||
}
|
||||
return DEVICE_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
63
assets/User_code/device/led/led.h
Normal file
63
assets/User_code/device/led/led.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
/* USER DEFIN BEGIN */
|
||||
|
||||
/* USER DEFIN END */
|
||||
#include <stdint.h>
|
||||
#ifdef LED_GPIO
|
||||
#include "bsp/gpio.h"
|
||||
#endif
|
||||
#ifdef LED_PWM
|
||||
#include "bsp/pwm.h"
|
||||
#endif
|
||||
#include "bsp/bsp.h"
|
||||
/* Exported constants ------------------------------------------------------- */
|
||||
/* Exported macro ----------------------------------------------------------- */
|
||||
/* Exported types ----------------------------------------------------------- */
|
||||
|
||||
|
||||
typedef struct {
|
||||
#ifdef LED_GPIO
|
||||
BSP_GPIO_t gpio;
|
||||
#endif
|
||||
#ifdef LED_PWM
|
||||
BSP_PWM_Channel_t channel;
|
||||
#endif
|
||||
} DEVICE_LED_t;
|
||||
|
||||
|
||||
extern DEVICE_LED_t LED_Map;
|
||||
/* Exported functions prototypes -------------------------------------------- */
|
||||
#ifdef LED_PWM
|
||||
int8_t DEVICE_LED_PWM_Set(BSP_PWM_Channel_t channel, float duty_cycle)
|
||||
{
|
||||
if (duty_cycle < 0.0f || duty_cycle > 1.0f) {
|
||||
return DEVICE_ERR_NULL; // 错误:占空比超出范围
|
||||
}
|
||||
uint16_t pulse = (uint16_t)(duty_cycle * (float)UINT16_MAX);
|
||||
BSP_PWM_Start(channel);
|
||||
BSP_PWM_SetComp(channel, pulse);
|
||||
return DEVICE_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef LED_GPIO
|
||||
int8_t DEVICE_LED_GPIO_Set(BSP_GPIO_t gpio, bool value)
|
||||
{
|
||||
if (value) {
|
||||
BSP_GPIO_WritePin(gpio, true);
|
||||
} else {
|
||||
BSP_GPIO_WritePin(gpio, false);
|
||||
}
|
||||
return DEVICE_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user