stm32f1xx-hal icon indicating copy to clipboard operation
stm32f1xx-hal copied to clipboard

add temp/vref controls

Open fuchsnj opened this issue 2 years ago • 4 comments

Previously when an Adc is initialized, the temp/vref sensor was disabled. During an ADC read, the sensor has to be turned on and off, which significantly increases the time it takes for a read. Additionally, since there was no way to enable to sensor manually, I don't think it was possible to read VREF in DMA mode.

Now, there are 3 additional functions, enable_temp_vref, disable_temp_vref and is_temp_vref_enabled. These functions are optional, and will speed up reading from the ADC if it is enabled manually.

The read_aux function now also only enables the sensor if the temp or vref channel is being read.

I tested this with an STM32F103 (bluepill)

fuchsnj avatar Apr 25 '22 01:04 fuchsnj

Thanks for the PR, and sorry for the review delay! Looks good to me, I left a small note on the return value of enable_temp_vref for discussion.

Could you also add this change to CHANGELOG.md?

TheZoq2 avatar Jun 13 '22 11:06 TheZoq2

I'm not seeing the note on the enable_temp_vref function, but I don't have strong opinions on how the return value is decided.

The options:

  1. (current approach), return true if the function changed something, meaning the sensor was previously off.
  2. Returns if the sensor was previously on.

I'm fine switching the approach if that sounds better, the one I picked was mostly arbitrary.

fuchsnj avatar Jun 14 '22 01:06 fuchsnj

My question was more about if the function should return anything at all. Is there a use case for knowing if it was previously on (or off)?

TheZoq2 avatar Jun 15 '22 07:06 TheZoq2

My question was more about if the function should return anything at all. Is there a use case for knowing if it was previously on (or off)?

Possibly. If that's blocking this change I'm fine removing the return type though.

fuchsnj avatar Jan 04 '23 18:01 fuchsnj