pub unsafe fn pinmode_output_force(pin: (char, u8)) -> Result<Pin<Output>, ProgError> {
  let peripheral_ptr = stm32f4::stm32f446::Peripherals::steal();
  let rcc = &peripheral_ptr.RCC;

  if let Err(error) = check_pin(pin) {return Err(error);}

  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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    _   => unreachable!()
  };

  return Ok(Pin {
    block: pin.0,
    number: pin.1,
    inner: Output
  });
}
/// Configures a pin to be a digital output. Disregard if pin is already configured.
/// 
/// 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 valid pin.
/// 
/// # Safety
/// 
/// This function can be used to get more than one pin-structs of a configured pin. Keep in mind that the registers of
/// the pin will still be configured. This can easily break other functions for the pin.
Configures a pin to be a digital output. Disregard if pin is already configured.
Configures a pin to be a digital output . Disregard if pin is already configured .
pub unsafe fn pinmode_output_force(pin: (char, u8)) -> Result<Pin<Output>, ProgError> {
  let peripheral_ptr = stm32f4::stm32f446::Peripherals::steal();
  let rcc = &peripheral_ptr.RCC;
  if let Err(error) = check_pin(pin) {return Err(error);}
  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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    '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)) | (1 << (2 * pin.1)))});
    },
    _   => unreachable!()
  };
  return Ok(Pin {
    block: pin.0,
    number: pin.1,
    inner: Output
  });
}
pub unsafe fn pinmode_output_force ( pin : ( char , u8 ) ) -> Result < Pin < Output > , ProgError > { let peripheral_ptr = stm32f4 :: stm32f446 :: Peripherals :: steal ( ) ; let rcc = & peripheral_ptr . RCC ; if let Err ( error ) = check_pin ( pin ) { return Err ( error ) ; } 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 ) ) | ( 1 << ( 2 * pin . 1 ) ) ) } ) ; } , '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 ) ) | ( 1 << ( 2 * pin . 1 ) ) ) } ) ; } , '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 ) ) | ( 1 << ( 2 * pin . 1 ) ) ) } ) ; } , '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 ) ) | ( 1 << ( 2 * pin . 1 ) ) ) } ) ; } , '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 ) ) | ( 1 << ( 2 * pin . 1 ) ) ) } ) ; } , _ => unreachable ! ( ) } ; return Ok ( Pin { block : pin . 0 , number : pin . 1 , inner : Output } ) ; }
Configures a pin to be a digital output.
Configures a pin to be a digital output .
pin
(char, u8)
pin
(char, u8)
safety
This function can be used to get more than one pin-structs of a configured pin. Keep in mind that the registers of
the pin will still be configured. This can easily break other functions for the pin.
This function can be used to get more than one pin - structs of a configured pin . Keep in mind that the registers of the pin will still be configured . This can easily break other functions for the pin .