Add core firmware modules: input, menu, NRF24L01, OLED, protocol, PWM, storage + UI assets

This commit is contained in:
root
2026-06-25 22:55:41 +08:00
parent 97ab93e93d
commit 5c0ff0ce63
22 changed files with 3671 additions and 17 deletions

View File

@@ -2,17 +2,23 @@
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
* @brief : 萝莉3代航模遥控器 - 主程序
* @author : 小云 (Hermes Agent)
* @date : 2026-06-25
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
* 系统架构:
* - 10ms 定时循环: 按键扫描 + ADC 轮询 + LED 更新
* - 主循环: 混控计算 + 菜单 UI + 协议收发
* - 中断: SysTick (时基), EXTI (NRF IRQ), UART (SBUS)
*
* 模块依赖:
* oled.h -> OLED SSD1306 128x64 显示
* input.h -> 按键/ADC 输入采集
* menu.h -> 菜单系统与 UI 交互
* storage.h -> Flash 存储 (模型/配置)
* pwm_out.h -> PWM/LED/WS2812 输出
* nrf24l01.h-> NRF24L01+ 2.4G 无线
* protocol.h-> 协议层 (RF/SBUS/USB HID)
******************************************************************************
*/
/* USER CODE END Header */
@@ -26,6 +32,15 @@
#include "usb.h"
#include "gpio.h"
/* 应用层模块 */
#include "oled.h"
#include "input.h"
#include "menu.h"
#include "storage.h"
#include "pwm_out.h"
#include "nrf24l01.h"
#include "protocol.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
@@ -38,7 +53,7 @@
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define MAIN_LOOP_PERIOD_MS 10 /* 主循环周期 10ms */
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
@@ -49,13 +64,14 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
static uint32_t last_loop_tick = 0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
static void System_Init(void);
static void System_Loop10ms(void);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
@@ -69,7 +85,6 @@ void SystemClock_Config(void);
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
@@ -101,8 +116,10 @@ int main(void)
MX_USB_PCD_Init();
MX_TIM3_Init();
MX_TIM4_Init();
/* USER CODE BEGIN 2 */
/* USER CODE BEGIN 2 */
/* ---- 应用层初始化 ---- */
System_Init();
/* USER CODE END 2 */
/* Infinite loop */
@@ -112,6 +129,18 @@ int main(void)
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
uint32_t now = HAL_GetTick();
/* 10ms 定时任务 */
if (now - last_loop_tick >= MAIN_LOOP_PERIOD_MS) {
last_loop_tick = now;
System_Loop10ms();
}
/* 实时任务: 混控 + 菜单 + 协议 */
Mixer_Compute(g_channels);
Menu_Run();
Protocol_Run();
}
/* USER CODE END 3 */
}
@@ -165,6 +194,67 @@ void SystemClock_Config(void)
/* USER CODE BEGIN 4 */
/**
* @brief 系统初始化: 加载配置、初始化各模块、显示开机画面
* @retval None
*/
static void System_Init(void) {
/* 1. 加载存储配置 */
Storage_Init();
Storage_Load();
/* 2. 初始化 OLED 并显示开机画面 */
OLED_Init();
OLED_DrawBitmap(0, 0, bitmap_bytes, 64, 64); /* 开机 Logo */
OLED_ShowString(70, 20, "Loli3", 16);
OLED_ShowString(70, 40, "RC v3.0", 6);
OLED_Display();
HAL_Delay(2000); /* 显示 2 秒 */
/* 3. 初始化输入模块 */
Input_Init();
/* 4. 初始化 PWM/LED */
PWM_Init();
LED_SetSystem(1); /* 系统 LED 常亮 */
/* 5. 初始化 NRF24L01 */
NRF24L01_Init();
if (NRF24L01_Check()) {
/* NRF24L01 存在 */
NRF24L01_SetChannel(g_config.nrf_channel);
LED_SetNRF(0); /* 慢闪 = 未连接 */
} else {
/* NRF24L01 未检测到 */
LED_SetNRF(3); /* 灭 */
}
/* 6. 初始化协议层 */
Protocol_Init();
/* 7. 初始化菜单 */
Menu_Init();
/* 8. 根据配置设置 PWM 模式 */
PWM_SetMode(0, g_config.pwm1_mode);
PWM_SetMode(1, g_config.pwm2_mode);
PWM_SetWS2812Mode(g_config.ws2812_effect);
PWM_SetLEDBrightness(g_config.led_brightness);
PWM_SetVibrateLevel(g_config.vibrate_level);
}
/**
* @brief 10ms 定时任务: 按键扫描 + ADC 轮询 + LED 闪烁更新
* @retval None
*/
static void System_Loop10ms(void) {
/* 按键 + ADC 扫描 */
Input_Scan();
/* LED 闪烁更新 */
LED_Update();
}
/* USER CODE END 4 */
/**
@@ -174,13 +264,17 @@ void SystemClock_Config(void)
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
/* 错误时 LED 快闪 */
__disable_irq();
while (1)
{
/* 系统 LED 快闪指示错误 */
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_6);
for (volatile uint32_t i = 0; i < 500000; i++);
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number