mirror of
https://github.com/armel/uv-k1-k5v3-firmware-custom.git
synced 2026-10-02 03:15:37 +00:00
Port driver: ADC
This commit is contained in:
1 parent
632e841aae
commit
992a417e62
2 files changed
+33
-6
No files matched your search
@@ -6,7 +6,6 @@ target_compile_definitions(App INTERFACE PRINTF_INCLUDE_CONFIG_H)
|
||||
|
||||
target_sources(App INTERFACE
|
||||
# Drivers
|
||||
# driver/adc.c
|
||||
driver/backlight.c
|
||||
driver/bk4819.c
|
||||
driver/py25q16.c
|
||||
|
||||
+33
-5
@@ -23,9 +23,8 @@
|
||||
#include "board.h"
|
||||
#include "py32f071_ll_bus.h"
|
||||
#include "py32f071_ll_gpio.h"
|
||||
#include "bsp/dp32g030/saradc.h"
|
||||
#include "bsp/dp32g030/syscon.h"
|
||||
#include "driver/adc.h"
|
||||
#include "py32f071_ll_rcc.h"
|
||||
#include "py32f071_ll_adc.h"
|
||||
#include "driver/backlight.h"
|
||||
#ifdef ENABLE_FMRADIO
|
||||
#include "driver/bk1080.h"
|
||||
@@ -131,12 +130,41 @@ void BOARD_GPIO_Init(void)
|
||||
|
||||
void BOARD_ADC_Init(void)
|
||||
{
|
||||
|
||||
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
|
||||
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_0 | LL_GPIO_PIN_1, LL_GPIO_MODE_ANALOG);
|
||||
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1);
|
||||
LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_PCLK_DIV4);
|
||||
|
||||
LL_ADC_SetCommonPathInternalCh(ADC1_COMMON, LL_ADC_PATH_INTERNAL_NONE);
|
||||
LL_ADC_SetResolution(ADC1, LL_ADC_RESOLUTION_12B);
|
||||
LL_ADC_SetDataAlignment(ADC1, LL_ADC_DATA_ALIGN_RIGHT);
|
||||
LL_ADC_SetSequencersScanMode(ADC1, LL_ADC_SEQ_SCAN_DISABLE);
|
||||
LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_SOFTWARE);
|
||||
LL_ADC_REG_SetContinuousMode(ADC1, LL_ADC_REG_CONV_SINGLE);
|
||||
LL_ADC_REG_SetDMATransfer(ADC1, LL_ADC_REG_DMA_TRANSFER_NONE);
|
||||
LL_ADC_REG_SetSequencerLength(ADC1, LL_ADC_REG_SEQ_SCAN_DISABLE);
|
||||
LL_ADC_REG_SetSequencerDiscont(ADC1, LL_ADC_REG_SEQ_DISCONT_DISABLE);
|
||||
LL_ADC_REG_SetSequencerDiscont(ADC1, LL_ADC_REG_SEQ_DISCONT_DISABLE);
|
||||
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_8);
|
||||
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_8, LL_ADC_SAMPLINGTIME_41CYCLES_5);
|
||||
|
||||
LL_ADC_StartCalibration(ADC1);
|
||||
while (LL_ADC_IsCalibrationOnGoing(ADC1))
|
||||
;
|
||||
|
||||
LL_ADC_Enable(ADC1);
|
||||
}
|
||||
|
||||
void BOARD_ADC_GetBatteryInfo(uint16_t *pVoltage, uint16_t *pCurrent)
|
||||
{
|
||||
|
||||
LL_ADC_REG_StartConversionSWStart(ADC1);
|
||||
while (!LL_ADC_IsActiveFlag_EOS(ADC1))
|
||||
;
|
||||
LL_ADC_ClearFlag_JEOS(ADC1);
|
||||
|
||||
*pVoltage = LL_ADC_REG_ReadConversionData12(ADC1);
|
||||
*pCurrent = 0;
|
||||
}
|
||||
|
||||
void BOARD_Init(void)
|
||||
|
||||
Reference in new issue
Block a user