Commit f0729b19 authored by Dave Hylands's avatar Dave Hylands
Browse files

Fix netduino to build

Fix adc to work with resolution changes.
parent 9512e9e8
......@@ -238,18 +238,44 @@ uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t chan
return adc_read_channel(adcHandle);
}
int adc_get_resolution(ADC_HandleTypeDef *adcHandle) {
uint32_t res_reg = __HAL_ADC_GET_RESOLUTION(adcHandle);
switch (res_reg) {
case ADC_RESOLUTION6b: return 6;
case ADC_RESOLUTION8b: return 8;
case ADC_RESOLUTION10b: return 10;
}
return 12;
}
int adc_read_core_temp(ADC_HandleTypeDef *adcHandle) {
int32_t raw_value = adc_config_and_read_channel(adcHandle, ADC_CHANNEL_TEMPSENSOR);
// Note: constants assume 12-bit resolution, so we scale the raw value to
// be 12-bits.
raw_value <<= (12 - adc_get_resolution(adcHandle));
return ((raw_value - CORE_TEMP_V25) / CORE_TEMP_AVG_SLOPE) + 25;
}
float adc_read_core_vbat(ADC_HandleTypeDef *adcHandle) {
uint32_t raw_value = adc_config_and_read_channel(adcHandle, ADC_CHANNEL_VBAT);
// Note: constants assume 12-bit resolution, so we scale the raw value to
// be 12-bits.
raw_value <<= (12 - adc_get_resolution(adcHandle));
return raw_value * VBAT_DIV / 4096.0f * 3.3f;
}
float adc_read_core_vref(ADC_HandleTypeDef *adcHandle) {
uint32_t raw_value = adc_config_and_read_channel(adcHandle, ADC_CHANNEL_VREFINT);
// Note: constants assume 12-bit resolution, so we scale the raw value to
// be 12-bits.
raw_value <<= (12 - adc_get_resolution(adcHandle));
return raw_value * VBAT_DIV / 4096.0f * 3.3f;
}
......
......@@ -373,6 +373,9 @@ soft_reset:
}
}
}
#else
// Get rid of compiler warning if no SDCARD is configured.
(void)first_soft_reset;
#endif
#if defined(USE_HOST_MODE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment