stm32-rs / stm32f1xx-hal

A Rust embedded-hal HAL impl for the STM32F1 family based on japarics stm32f103xx-hal
Apache License 2.0
550 stars 173 forks source link

Enable/disable Tsen/Vref_int via API #474

Open katyo opened 7 months ago

katyo commented 7 months ago

I would like to read internal Vref channel using DMA but seems currently I cannot enable aux channels on ADC1 via API.

As a workaround I used dirty hack to get access to ADC1 registers and enable it:

unsafe { &*(&adc as *const _ as *const ADC1) }.cr2.modify(|_, w| w.tsvrefe().set_bit());

As a simple solution I could add functions for testing and changing corresponding bit like the following:

impl Adc<ADC1> {
  pub fn aux_enabled(&self) -> bool;
  pub fn enable_aux(&mut self);
  pub fn disable_aux(&mut self);
}

Have anybody any suggestions about API design?