Merge pull request #375 from dhylands/stmhal-adc
Some changes that I forgot to push with my last pull request
This commit is contained in:
commit
24d527bf22
26
stmhal/adc.c
26
stmhal/adc.c
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user