mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 19:37:45 +08:00
feat: speed up PRTS LCD refresh
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user