pub fn analog_read(pin: &Pin<Analog>) -> u16 {
  let peripheral_ptr;
  unsafe {peripheral_ptr = stm32f4::stm32f446::Peripherals::steal();}

  let buffer = match pin.inner.core {
    1 => {
      let adc1 = &peripheral_ptr.ADC1;
      adc1.sqr3.modify(|_, w| unsafe {w.sq1().bits(pin.number)});
      adc1.cr2.write(|w| w.swstart().start());
      while adc1.sr.read().eoc().is_not_complete() {}
      adc1.dr.read().data().bits()
    },
    2 => {
      let adc2 = &peripheral_ptr.ADC2;
      adc2.sqr3.modify(|_, w| unsafe {w.sq1().bits(pin.number)});
      adc2.cr2.write(|w| w.swstart().start());
      while adc2.sr.read().eoc().is_not_complete() {}
      adc2.dr.read().data().bits()
    },
    3 => {
      let adc3 = &peripheral_ptr.ADC3;
      adc3.sqr3.modify(|_, w| unsafe {w.sq1().bits(pin.number)});
      adc3.cr2.write(|w| w.swstart().start());
      while adc3.sr.read().eoc().is_not_complete() {}
      adc3.dr.read().data().bits()
    },
    _ => unreachable!()
  };

  return buffer;
}
/// Performs an ADC conversion on the pin and gives back the analog value
/// 
/// # Examples
/// 
/// ```no_run
/// // Configure pin as an analog input
/// let pin = pinmode_analog(PA0).unwrap();
/// 
/// // Read the analog value on the pin
/// let mut value: u16 = analog_read(&pin);
/// ```
Performs an ADC conversion on the pin and gives back the analog value
Performs an ADC conversion on the pin and gives back the analog value
pub fn analog_read(pin: &Pin<Analog>) -> u16 {
  let peripheral_ptr;
  unsafe {peripheral_ptr = stm32f4::stm32f446::Peripherals::steal();}
  let buffer = match pin.inner.core {
    1 => {
      let adc1 = &peripheral_ptr.ADC1;
      adc1.sqr3.modify(|_, w| unsafe {w.sq1().bits(pin.number)});
      adc1.cr2.write(|w| w.swstart().start());
      while adc1.sr.read().eoc().is_not_complete() {}
      adc1.dr.read().data().bits()
    },
    2 => {
      let adc2 = &peripheral_ptr.ADC2;
      adc2.sqr3.modify(|_, w| unsafe {w.sq1().bits(pin.number)});
      adc2.cr2.write(|w| w.swstart().start());
      while adc2.sr.read().eoc().is_not_complete() {}
      adc2.dr.read().data().bits()
    },
    3 => {
      let adc3 = &peripheral_ptr.ADC3;
      adc3.sqr3.modify(|_, w| unsafe {w.sq1().bits(pin.number)});
      adc3.cr2.write(|w| w.swstart().start());
      while adc3.sr.read().eoc().is_not_complete() {}
      adc3.dr.read().data().bits()
    },
    _ => unreachable!()
  };
  return buffer;
}
pub fn analog_read ( pin : & Pin < Analog > ) -> u16 { let peripheral_ptr ; unsafe { peripheral_ptr = stm32f4 :: stm32f446 :: Peripherals :: steal ( ) ; } let buffer = match pin . inner . core { 1 => { let adc1 = & peripheral_ptr . ADC1 ; adc1 . sqr3 . modify ( | _ , w | unsafe { w . sq1 ( ) . bits ( pin . number ) } ) ; adc1 . cr2 . write ( | w | w . swstart ( ) . start ( ) ) ; while adc1 . sr . read ( ) . eoc ( ) . is_not_complete ( ) { } adc1 . dr . read ( ) . data ( ) . bits ( ) } , 2 => { let adc2 = & peripheral_ptr . ADC2 ; adc2 . sqr3 . modify ( | _ , w | unsafe { w . sq1 ( ) . bits ( pin . number ) } ) ; adc2 . cr2 . write ( | w | w . swstart ( ) . start ( ) ) ; while adc2 . sr . read ( ) . eoc ( ) . is_not_complete ( ) { } adc2 . dr . read ( ) . data ( ) . bits ( ) } , 3 => { let adc3 = & peripheral_ptr . ADC3 ; adc3 . sqr3 . modify ( | _ , w | unsafe { w . sq1 ( ) . bits ( pin . number ) } ) ; adc3 . cr2 . write ( | w | w . swstart ( ) . start ( ) ) ; while adc3 . sr . read ( ) . eoc ( ) . is_not_complete ( ) { } adc3 . dr . read ( ) . data ( ) . bits ( ) } , _ => unreachable ! ( ) } ; return buffer ; }
Performs an ADC conversion on the pin and gives back the analog value
Performs an ADC conversion on the pin and gives back the analog value
pin
&Pin<Analog>
pin
&Pin<Analog>
examples
```no_run
Configure pin as an analog input
let pin = pinmode_analog(PA0).unwrap().

Read the analog value on the pin
let mut value: u16 = analog_read(&pin);
```
` ` ` no_run Configure pin as an analog input let pin = pinmode_analog ( PA0 ) . unwrap () . Read the analog value on the pin let mut value : u16 = analog_read ( &pin ) ; ` ` `