feat: speed up PRTS LCD refresh

This commit is contained in:
TuxMonkey
2026-07-20 23:34:13 +08:00
parent b2169513e1
commit 8671f84139
14 changed files with 2296 additions and 98 deletions

View File

@@ -15,11 +15,14 @@
/* Includes ------------------------------------------------------------------*/
#include "bsp_adc.h"
#include "adc.h"
#include <stdbool.h>
/**
* @brief ADC sampling voltage array
*/
__attribute__((section (".AXI_SRAM"))) uint16_t ADC_Voltage_Val[2];
__attribute__((section(".dma_buffer"), aligned(32))) volatile uint16_t ADC_Voltage_Val[BSP_ADC_CHANNEL_COUNT];
static bool bsp_adc_started = false;
/**
* @brief Configures the ADC.
@@ -28,8 +31,16 @@ __attribute__((section (".AXI_SRAM"))) uint16_t ADC_Voltage_Val[2];
*/
void BSP_ADC_Init(void)
{
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *) ADC_Voltage_Val, 2);
if (bsp_adc_started)
{
return;
}
(void) HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
if (HAL_ADC_Start_DMA(&hadc1, (uint32_t *) ADC_Voltage_Val, BSP_ADC_CHANNEL_COUNT) == HAL_OK)
{
bsp_adc_started = true;
}
}
//------------------------------------------------------------------------------
@@ -41,8 +52,33 @@ void BSP_ADC_Init(void)
*/
float USER_ADC_Voltage_Update(void)
{
auto Voltage = (ADC_Voltage_Val[0] * 3.3f / 65535) * 11.0f;
return Voltage;
float voltage = ((float) ADC_Voltage_Val[BSP_ADC_BOARD_VOLTAGE_INDEX] * 3.3f / 65535.0f) * 11.0f;
return voltage;
}
//------------------------------------------------------------------------------
uint16_t BSP_ADC_GetRaw(uint32_t index)
{
if (index >= BSP_ADC_CHANNEL_COUNT)
{
return 0U;
}
return ADC_Voltage_Val[index];
}
uint16_t BSP_ADC_GetJoystickRaw(void)
{
return BSP_ADC_GetRaw(BSP_ADC_JOYSTICK_INDEX);
}
uint16_t BSP_ADC_GetJoystickRaw12(void)
{
return (uint16_t) (BSP_ADC_GetJoystickRaw() >> 4U);
}
float BSP_ADC_GetJoystickVoltage(void)
{
return (float) BSP_ADC_GetJoystickRaw() * 3.3f / 65535.0f;
}

View File

@@ -26,9 +26,20 @@ extern "C"
/* Includes ------------------------------------------------------------------*/
#include "adc.h"
#include <stdint.h>
#define BSP_ADC_CHANNEL_COUNT 2U
#define BSP_ADC_BOARD_VOLTAGE_INDEX 0U
#define BSP_ADC_JOYSTICK_INDEX 1U
extern volatile uint16_t ADC_Voltage_Val[BSP_ADC_CHANNEL_COUNT];
/* Externs ---------------------------------------------*/
void BSP_ADC_Init(void);
float USER_ADC_Voltage_Update(void);
uint16_t BSP_ADC_GetRaw(uint32_t index);
uint16_t BSP_ADC_GetJoystickRaw(void);
uint16_t BSP_ADC_GetJoystickRaw12(void);
float BSP_ADC_GetJoystickVoltage(void);
#endif //BSP_ADC_H