X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=boards%2Fstm32-p103%2Fhw%2Fhw_adc.h;h=8e0f0deecc9b448362207baf047bf2650ae96426;hb=f30870b670b3bf27f28a219d58c852db15ca64a9;hp=3c6e4bbce7952c59026c2fa94b2818e83468f550;hpb=066883340bb685b1dfce449cd538418579d3d0ce;p=bertos.git diff --git a/boards/stm32-p103/hw/hw_adc.h b/boards/stm32-p103/hw/hw_adc.h index 3c6e4bbc..8e0f0dee 100644 --- a/boards/stm32-p103/hw/hw_adc.h +++ b/boards/stm32-p103/hw/hw_adc.h @@ -42,15 +42,28 @@ #include +/* + * Return the Vrefint voltage in mV. + */ INLINE uint16_t hw_readVrefint(void) { - return ADC_RANGECONV(adc_read(ADC_VREFINT_CH), 0, 3.3); + return ADC_RANGECONV(adc_read(ADC_VREFINT_CH), 0, 3300); +} + +/* + * Return the cpu core temperature in degrees * 100. + */ +INLINE uint16_t hw_readIntTemp(void) +{ + uint16_t vsens = ADC_RANGECONV(adc_read(ADC_TEMP_CH), 0, 3300); + + uint16_t temp = (((ADC_TEMP_V25 - vsens) * 1000)/ ADC_TEMP_SLOPE) + ADC_TEMP_CONST; + return (temp / 10); } -INLINE float hw_readIntTemp(void) +INLINE uint16_t hw_readRawTemp(void) { - float vsens = ADC_RANGECONV(adc_read(ADC_TEMP_CH), 0, 3.3); - return (float)(((ADC_TEMP_V25 - vsens) / ADC_TEMP_SLOPE) + ADC_TEMP_CONST); + return (uint16_t)ADC_RANGECONV(adc_read(ADC_TEMP_CH), 0, 3300); } #endif /* HW_ADC_H */