Split adc_get_input_volt to make it clear what part is not part of the official SDK
This commit is contained in:
parent
ede7a327a6
commit
17480e895f
@ -312,7 +312,7 @@ void watch_peripherals_register_battery_controller_status_change_cb(BatteryContr
|
||||
uint16_t watch_peripherals_get_battery_voltage(battery_unit_e unit)
|
||||
{
|
||||
tls_gpio_write(BATTERY_VOLTAGE_DIVIDER_ENABLE, 1);
|
||||
int batteryVoltage = adc_get_inputVolt(BATTERY_VOLTAGE_ADC_CHANNEL, 1, 1) * 2 + _adc_offset;
|
||||
int batteryVoltage = adc_get_inputVolt_with_gains(BATTERY_VOLTAGE_ADC_CHANNEL, 1, 1) * 2 + _adc_offset;
|
||||
tls_gpio_write(BATTERY_VOLTAGE_DIVIDER_ENABLE, 0);
|
||||
|
||||
switch (unit)
|
||||
|
@ -270,7 +270,23 @@ int adc_get_interTemp(void);
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int adc_get_inputVolt(u8 channel, u8 gain1, u8 gain2);
|
||||
int adc_get_inputVolt(u8 channel);
|
||||
|
||||
/** NOT PART OF THE OFFICIAL SDK **/
|
||||
/**
|
||||
* @brief This function is used to read input voltage also allowing to
|
||||
* specify ADC gains.
|
||||
*
|
||||
* @param[in] channel adc channel,from 0 to 3 is single input;8 and 9 is differential input.
|
||||
* @param[in] gain1 ADC PGA gain 1
|
||||
* @param[in] gain2 ADC PGA gain 2
|
||||
*
|
||||
* @retval voltage unit:mV
|
||||
*
|
||||
* @note None
|
||||
*/
|
||||
int adc_get_inputVolt_with_gains(u8 channel, u8 gain1, u8 gain2);
|
||||
/**********************************/
|
||||
|
||||
/**
|
||||
* @brief This function is used to read internal voltage.
|
||||
|
@ -532,7 +532,7 @@ int adc_get_interTemp(void)
|
||||
return adc_temp();
|
||||
}
|
||||
|
||||
int adc_get_inputVolt(u8 channel, u8 gain1, u8 gain2)
|
||||
int adc_get_inputVolt(u8 channel)
|
||||
{
|
||||
int average = 0;
|
||||
double voltage = 0.0;
|
||||
@ -544,7 +544,7 @@ int adc_get_inputVolt(u8 channel, u8 gain1, u8 gain2)
|
||||
|
||||
tls_adc_init(0, 0);
|
||||
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
|
||||
tls_adc_set_pga(gain1, gain2);
|
||||
tls_adc_set_pga(1,1);
|
||||
tls_adc_set_clk(0x28);
|
||||
tls_adc_start_with_cpu(channel);
|
||||
|
||||
@ -567,6 +567,43 @@ int adc_get_inputVolt(u8 channel, u8 gain1, u8 gain2)
|
||||
return average;
|
||||
}
|
||||
|
||||
/** NOT PART OF THE OFFICIAL SDK **/
|
||||
int adc_get_inputVolt_with_gains(u8 channel, u8 gain1, u8 gain2)
|
||||
{
|
||||
int average = 0;
|
||||
double voltage = 0.0;
|
||||
|
||||
if(_polyfit_param.poly_n == 0 || (channel == 8) || (channel == 9))
|
||||
{
|
||||
adc_get_offset();
|
||||
}
|
||||
|
||||
tls_adc_init(0, 0);
|
||||
tls_adc_reference_sel(ADC_REFERENCE_INTERNAL);
|
||||
tls_adc_set_pga(gain1, gain2);
|
||||
tls_adc_set_clk(0x28);
|
||||
tls_adc_start_with_cpu(channel);
|
||||
|
||||
waitForAdcDone();
|
||||
average = tls_read_adc_result();
|
||||
signedToUnsignedData(&average);
|
||||
tls_adc_stop(0);
|
||||
|
||||
if ((channel == 8) || (channel == 9))
|
||||
{
|
||||
voltage = ((double)average - (double)adc_offset)/4.0;
|
||||
voltage = voltage*(126363/1000)/1000000;
|
||||
}
|
||||
else
|
||||
{
|
||||
return cal_voltage((double)average);
|
||||
}
|
||||
|
||||
average = (int)(voltage*1000);
|
||||
return average;
|
||||
}
|
||||
/**********************************/
|
||||
|
||||
u32 adc_get_interVolt(void)
|
||||
{
|
||||
u32 voltValue;
|
||||
|
@ -934,7 +934,7 @@ static int factory_atcmd_adc_vol_proc( struct factory_atcmd_token_t *tok, char *
|
||||
if (val & (1 << i))
|
||||
{
|
||||
wm_adc_config(i);
|
||||
voltage[i] = adc_get_inputVolt(i, 1, 1);
|
||||
voltage[i] = adc_get_inputVolt(i);
|
||||
}
|
||||
}
|
||||
*res_len = sprintf(res_resp, "+OK=%d,%d,%d,%d\r\n", voltage[0], voltage[1], voltage[2], voltage[3]);
|
||||
|
Loading…
Reference in New Issue
Block a user