/// Configures a pin to be an analog input.
/// 
/// Takes pin identifier [A0, C5, etc.](crate::include::pins) as an argument and returns a [pin-struct](crate::gpio::Pin)
/// for other functions.
/// Panics if pin identifier is not a pin that can be used the the internal ADCs. To see witch pins are available for
/// analog functionality see the docs of [ADC_MAP](crate::include::ADC_MAP).
Configures a pin to be an analog input.
Configures a pin to be an analog input .
pub fn pinmode_analog(pin: (char, u8)) -> Result<Pin<Analog>, ProgError> {
  let peripheral_ptr;
  unsafe {peripheral_ptr = stm32f4::stm32f446::Peripherals::steal();} 
  let rcc = &peripheral_ptr.RCC;
  let channel_data: (u8, u8);
  if let Err(error) = check_pin(pin) {return Err(error);}
  unsafe {
    if !PIN_CONF.contains(&pin) {PIN_CONF.push(pin).unwrap();}
    else {
      rprintln!("P{}{} is already configured! | pin_mode()", pin.0.to_uppercase(), pin.1);
      return Err(ProgError::AlreadyConfigured);
    }
  }
  match pin.0 {
    'a' => {
      let gpioa = &peripheral_ptr.GPIOA;
      rcc.ahb1enr.modify(|_, w| w.gpioaen().enabled());
      gpioa.moder.modify(|r, w| unsafe {w.bits(r.bits() & !(3 << (2 * pin.1)) | (3 << (2 * pin.1)))});
      channel_data = match enable_channel(pin) {
        Ok(value) => value,
        Err(error) => return Err(error)
      };
    },
    'b' => {
      let gpiob = &peripheral_ptr.GPIOB;
      rcc.ahb1enr.modify(|_, w| w.gpioben().enabled());
      gpiob.moder.modify(|r, w| unsafe {w.bits(r.bits() & !(3 << (2 * pin.1)) | (3 << (2 * pin.1)))});
      channel_data = match enable_channel(pin) {
        Ok(value) => value,
        Err(error) => return Err(error)
      };
    },
    'c' => {
      let gpioc = &peripheral_ptr.GPIOC;
      rcc.ahb1enr.modify(|_, w| w.gpiocen().enabled());
      gpioc.moder.modify(|r, w| unsafe {w.bits(r.bits() & !(3 << (2 * pin.1)) | (3 << (2 * pin.1)))});
      channel_data = match enable_channel(pin) {
        Ok(value) => value,
        Err(error) => return Err(error)
      };
    },
    'd' => {
      let gpiod = &peripheral_ptr.GPIOD;
      rcc.ahb1enr.modify(|_, w| w.gpioden().enabled());
      gpiod.moder.modify(|r, w| unsafe {w.bits(r.bits() & !(3 << (2 * pin.1)) | (3 << (2 * pin.1)))});
      channel_data = match enable_channel(pin) {
        Ok(value) => value,
        Err(error) => return Err(error)
      };
    },
    'h' => {
      let gpioh = &peripheral_ptr.GPIOH;
      rcc.ahb1enr.modify(|_, w| w.gpiohen().enabled());
      gpioh.moder.modify(|r, w| unsafe {w.bits(r.bits() & !(3 << (2 * pin.1)) | (3 << (2 * pin.1)))});
      channel_data = match enable_channel(pin) {
        Ok(value) => value,
        Err(error) => return Err(error)
      };
    },
    _   => unreachable!()
  };
  return Ok(Pin {
    block: pin.0,
    number: pin.1,
    inner: Analog {
      core: channel_data.0,
      channel: channel_data.1
    }
  });
}
pub fn pinmode_analog ( pin : ( char , u8 ) ) -> Result < Pin < Analog > , ProgError > { let peripheral_ptr ; unsafe { peripheral_ptr = stm32f4 :: stm32f446 :: Peripherals :: steal ( ) ; } let rcc = & peripheral_ptr . RCC ; let channel_data : ( u8 , u8 ) ; if let Err ( error ) = check_pin ( pin ) { return Err ( error ) ; } unsafe { if ! PIN_CONF . contains ( & pin ) { PIN_CONF . push ( pin ) . unwrap ( ) ; } else { rprintln ! ( " " pin 0 to_uppercase ( ) pin 1 ) ; return Err ( ProgError :: AlreadyConfigured ) ; } } match pin . 0 { 'a' => { let gpioa = & peripheral_ptr . GPIOA ; rcc . ahb1enr . modify ( | _ , w | w . gpioaen ( ) . enabled ( ) ) ; gpioa . moder . modify ( | r , w | unsafe { w . bits ( r . bits ( ) & ! ( 3 << ( 2 * pin . 1 ) ) | ( 3 << ( 2 * pin . 1 ) ) ) } ) ; channel_data = match enable_channel ( pin ) { Ok ( value ) => value , Err ( error ) => return Err ( error ) } ; } , 'b' => { let gpiob = & peripheral_ptr . GPIOB ; rcc . ahb1enr . modify ( | _ , w | w . gpioben ( ) . enabled ( ) ) ; gpiob . moder . modify ( | r , w | unsafe { w . bits ( r . bits ( ) & ! ( 3 << ( 2 * pin . 1 ) ) | ( 3 << ( 2 * pin . 1 ) ) ) } ) ; channel_data = match enable_channel ( pin ) { Ok ( value ) => value , Err ( error ) => return Err ( error ) } ; } , 'c' => { let gpioc = & peripheral_ptr . GPIOC ; rcc . ahb1enr . modify ( | _ , w | w . gpiocen ( ) . enabled ( ) ) ; gpioc . moder . modify ( | r , w | unsafe { w . bits ( r . bits ( ) & ! ( 3 << ( 2 * pin . 1 ) ) | ( 3 << ( 2 * pin . 1 ) ) ) } ) ; channel_data = match enable_channel ( pin ) { Ok ( value ) => value , Err ( error ) => return Err ( error ) } ; } , 'd' => { let gpiod = & peripheral_ptr . GPIOD ; rcc . ahb1enr . modify ( | _ , w | w . gpioden ( ) . enabled ( ) ) ; gpiod . moder . modify ( | r , w | unsafe { w . bits ( r . bits ( ) & ! ( 3 << ( 2 * pin . 1 ) ) | ( 3 << ( 2 * pin . 1 ) ) ) } ) ; channel_data = match enable_channel ( pin ) { Ok ( value ) => value , Err ( error ) => return Err ( error ) } ; } , 'h' => { let gpioh = & peripheral_ptr . GPIOH ; rcc . ahb1enr . modify ( | _ , w | w . gpiohen ( ) . enabled ( ) ) ; gpioh . moder . modify ( | r , w | unsafe { w . bits ( r . bits ( ) & ! ( 3 << ( 2 * pin . 1 ) ) | ( 3 << ( 2 * pin . 1 ) ) ) } ) ; channel_data = match enable_channel ( pin ) { Ok ( value ) => value , Err ( error ) => return Err ( error ) } ; } , _ => unreachable ! ( ) } ; return Ok ( Pin { block : pin . 0 , number : pin . 1 , inner : Analog { core : channel_data . 0 , channel : channel_data . 1 } } ) ; }
Configures a pin to be an analog input.
Configures a pin to be an analog input .
pin
(char, u8)