Skip to content

Commit

Permalink
Merge pull request #173 from yuhang-ingchips/111
Browse files Browse the repository at this point in the history
updata ADC FtInit
  • Loading branch information
zjli-2019 authored May 6, 2023
2 parents 8d69136 + fb3580e commit e370469
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/FWlib/peripheral_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ void ADC_ftInit(void)
{
if (ftCali) return;
uint8_t readFlg = 0;
uint8_t addrType = 0;
uint8_t ret = flash_prepare_factory_data();
const factory_calib_data_t *p_factoryCali = flash_get_factory_calib_data();
const uint16_t *p_adcCali = (const uint16_t *)flash_get_adc_calib_data();
Expand All @@ -472,12 +471,13 @@ void ADC_ftInit(void)
ftCali = malloc(sizeof(SADC_ftCali_t));
memset(ftCali, 0, sizeof(SADC_ftCali_t));

uint8_t ver;
uint32_t flg;
if (readFlg)
flg = read_flash_security(0x1170);
else
flg = p_factoryCali->adc_calib_ver;
addrType = flg & ADC_MK_MASK(16);
ver = flg & ADC_MK_MASK(16);
flg = (flg >> 16) & ADC_MK_MASK(16);
uint32_t V1, V2;
uint32_t V1_diff, V2_diff;
Expand Down Expand Up @@ -520,7 +520,7 @@ void ADC_ftInit(void)
Cin1 = V1 * 16384 / ftCali->Vp;
Cin2 = V2 / 10 * 16384 / (ftCali->Vp / 10);
for (i = 0; i < 8; ++i) {
if (addrType) {
if (ver) {
if (readFlg) {
Cout1 = read_flash_security(0x2000 + 4 * i) & ADC_MK_MASK(16);
Cout2 = (read_flash_security(0x2000 + 4 * i) >> 16) & ADC_MK_MASK(16);
Expand All @@ -543,7 +543,7 @@ void ADC_ftInit(void)
Cin2 = (V2_diff - V1_diff) / 10 * 16384 / (ftCali->Vp / 10) + 8192;
Cin1 = 16384 - Cin2;
for (i = 0; i < 4; ++i) {
if (addrType) {
if (ver) {
if (readFlg) {
Cout1 = read_flash_security(0x2020 + 4 * i) & ADC_MK_MASK(16);
Cout2 = (read_flash_security(0x2020 + 4 * i) >> 16) & ADC_MK_MASK(16);
Expand All @@ -567,6 +567,8 @@ void ADC_ftInit(void)
ftCali->V12Data = read_flash_security(0x1144) & ADC_MK_MASK(16);
else
ftCali->V12Data = p_factoryCali->v12_adc[0];
if (ver == 1)
ftCali->V12Data -= 14;
ftCali->f = ADC_FtCal;
ADC_VrefRegister(ftCali->Vp * 0.00001f, 0.f);
}
Expand Down Expand Up @@ -622,6 +624,7 @@ void ADC_Calibration(SADC_adcIputMode mode)
ADC_SetAdcMode(CONVERSION_MODE);
ADC_EnableChannel(ADC_CH_0, 0);
ADC_RegClr(SADC_CFG_0, 17, 1);
ADC_ClrFifo();
}

void ADC_ConvCfg(SADC_adcCtrlMode ctrlMode,
Expand Down

0 comments on commit e370469

Please sign in to comment.