98 lines
2.7 KiB
C
98 lines
2.7 KiB
C
#include "include.h"
|
|
|
|
adc_cb_t adc_cb AT(.buf.key.cb);
|
|
|
|
void bsp_qdec_adc_process(u8 adc_val);
|
|
|
|
AT(.com_text.saradc.process)
|
|
bool bsp_saradc_process(u32 auto_en)
|
|
{
|
|
if (!saradc_is_finish()) {
|
|
return false;
|
|
}
|
|
if (saradc_adc15_is_vrtc()) {
|
|
adc_cb.vrtc_val = saradc_get_value10(ADCCH_VRTC);
|
|
}
|
|
if (saradc_adc15_is_bg()) {
|
|
adc_cb.bg = saradc_get_value10(ADCCH_BGOP);
|
|
}
|
|
if (auto_en) {
|
|
saradc_adc15_analog_next();
|
|
saradc_kick_start(0, 0); //启动下一次ADC转换
|
|
}
|
|
return true;
|
|
}
|
|
|
|
#define DC_IN() ((RTCCON >> 20) & 0x01)
|
|
|
|
AT(.com_text.saradc.process)
|
|
static void bsp_saradc_kick_process(void)
|
|
{
|
|
if (!DC_IN()) {
|
|
saradc_kick_start(0, 0); //每5毫秒启动全部ADC通路转换一次
|
|
} else {
|
|
if ((adc_cb.tmr1ms_cnt % 200) == 0) { //充电状态, 每200ms采样一次VBAT
|
|
RTCCON8 |= BIT(1); //charge stop
|
|
adc_chstops_flag = true; //转换完成, 中断清变量
|
|
saradc_kick_start(0, 1); //全部ADC通路转换一次
|
|
} else {
|
|
saradc_kick_start_do(saradc_cb.channel & ~(BIT(ADCCH_VBAT) | BIT(ADCCH_VRTC)), 0, 0);
|
|
}
|
|
}
|
|
}
|
|
|
|
AT(.com_text.saradc.process)
|
|
void bsp_saradc_tmr1ms_process(void)
|
|
{
|
|
adc_cb.tmr1ms_cnt++;
|
|
#if USER_ADKEY_QDEC_EN
|
|
if (bsp_saradc_process(0)) {
|
|
if ((adc_cb.tmr1ms_cnt % 5) == 0) {
|
|
saradc_adc15_analog_next();
|
|
bsp_saradc_kick_process();
|
|
} else {
|
|
saradc_kick_start_do(BIT(USER_QDEC_ADCH), 0, 0); //仅QDEC ADC每毫秒采样一次
|
|
}
|
|
bsp_qdec_adc_process(saradc_get_value8(USER_QDEC_ADCH));
|
|
}
|
|
#else
|
|
if ((adc_cb.tmr1ms_cnt % 5) == 0) {
|
|
bsp_saradc_process(0);
|
|
saradc_adc15_analog_next();
|
|
bsp_saradc_kick_process();
|
|
}
|
|
#endif // USER_ADKEY_QDEC_EN
|
|
}
|
|
|
|
|
|
void bsp_saradc_init(void)
|
|
{
|
|
memset(&adc_cb, 0, sizeof(adc_cb));
|
|
saradc_init();
|
|
|
|
//始化时采一次BG电压
|
|
saradc_adc15_analog_select(ADCCH15_ANA_BG);
|
|
delay_us(600);
|
|
saradc_kick_start(0, 0);
|
|
while(!bsp_saradc_process(0));
|
|
|
|
//采集BG对应的VRTC电压
|
|
saradc_adc15_ana_set_channel(ADCCH15_ANA_VRTC);
|
|
saradc_adc15_analog_select(ADCCH15_ANA_VRTC);
|
|
delay_us(600);
|
|
saradc_kick_start(0, 0);
|
|
while(!bsp_saradc_process(1));
|
|
adc_cb.vrtc_first = adc_cb.vrtc_val;
|
|
|
|
#if VBAT_DETECT_EN
|
|
bsp_vbat_voltage_init();
|
|
#endif
|
|
}
|
|
|
|
uint16_t bsp_saradc_exit(void)
|
|
{
|
|
return saradc_exit();
|
|
}
|
|
|
|
|