#![allow(unused_variables)]
use super::*;
use crate::{
    gpio::*,
    pac::{UART4, UART5, USART1, USART2, USART3},
};

// table
// Do NOT manually modify the code.
// It's generated by scripts/generate_remap_table.py from scripts/table/stm32f1_remap_peripheral.csv

// Binder types ------------------

pub trait UartCkPin<REMAP> {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        true
    }
}
impl<T> UartCkPin<T> for NonePin {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        false
    }
}
pub trait UartCtsPin<REMAP> {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        true
    }
}
impl<T> UartCtsPin<T> for NonePin {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        false
    }
}
pub trait UartRtsPin<REMAP> {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        true
    }
}
impl<T> UartRtsPin<T> for NonePin {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        false
    }
}
pub trait UartRxPin<REMAP> {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        true
    }
}
impl<T> UartRxPin<T> for NonePin {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        false
    }
}
pub trait UartTxPin<REMAP> {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        true
    }
}
impl<T> UartTxPin<T> for NonePin {
    #[inline(always)]
    fn is_pin(&self) -> bool {
        false
    }
}

// Bind pins ---------------------

impl<PULL: UpMode> UartRxPin<RemapDefault<UART4>> for PC11<Input<PULL>> {}
impl UartTxPin<RemapDefault<UART4>> for PC10<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapDefault<UART5>> for PD2<Input<PULL>> {}
impl UartTxPin<RemapDefault<UART5>> for PC12<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapDefault<USART1>> for PA10<Input<PULL>> {}
impl UartTxPin<RemapDefault<USART1>> for PA9<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapFull<USART1>> for PB7<Input<PULL>> {}
impl UartTxPin<RemapFull<USART1>> for PB6<Alternate<PushPull>> {}
impl UartCkPin<RemapDefault<USART2>> for PA4<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapDefault<USART2>> for PA3<Input<PULL>> {}
impl UartTxPin<RemapDefault<USART2>> for PA2<Alternate<PushPull>> {}
impl UartCkPin<RemapFull<USART2>> for PD7<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapFull<USART2>> for PD6<Input<PULL>> {}
impl UartTxPin<RemapFull<USART2>> for PD5<Alternate<PushPull>> {}
impl UartCkPin<RemapDefault<USART3>> for PB12<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapDefault<USART3>> for PB11<Input<PULL>> {}
impl UartTxPin<RemapDefault<USART3>> for PB10<Alternate<PushPull>> {}
impl UartCkPin<RemapFull<USART3>> for PD10<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapFull<USART3>> for PD9<Input<PULL>> {}
impl UartTxPin<RemapFull<USART3>> for PD8<Alternate<PushPull>> {}
impl UartCkPin<RemapPartial1<USART3>> for PC12<Alternate<PushPull>> {}
impl<PULL: UpMode> UartRxPin<RemapPartial1<USART3>> for PC11<Input<PULL>> {}
impl UartTxPin<RemapPartial1<USART3>> for PC10<Alternate<PushPull>> {}

// Register operations ------------

impl RemapMode<UART4> for RemapDefault<UART4> {
    fn remap(afio: &mut Afio) {}
}
impl RemapMode<UART5> for RemapDefault<UART5> {
    fn remap(afio: &mut Afio) {}
}
impl RemapMode<USART1> for RemapDefault<USART1> {
    fn remap(afio: &mut Afio) {
        afio.mapr.modify_mapr(|_, w| w.usart1_remap().clear_bit());
    }
}
impl RemapMode<USART1> for RemapFull<USART1> {
    fn remap(afio: &mut Afio) {
        afio.mapr.modify_mapr(|_, w| w.usart1_remap().set_bit());
    }
}
impl RemapMode<USART2> for RemapDefault<USART2> {
    fn remap(afio: &mut Afio) {
        afio.mapr.modify_mapr(|_, w| w.usart2_remap().clear_bit());
    }
}
impl RemapMode<USART2> for RemapFull<USART2> {
    fn remap(afio: &mut Afio) {
        afio.mapr.modify_mapr(|_, w| w.usart2_remap().set_bit());
    }
}
impl RemapMode<USART3> for RemapDefault<USART3> {
    fn remap(afio: &mut Afio) {
        afio.mapr
            .modify_mapr(unsafe { |_, w| w.usart3_remap().bits(0b00) });
    }
}
impl RemapMode<USART3> for RemapFull<USART3> {
    fn remap(afio: &mut Afio) {
        afio.mapr
            .modify_mapr(unsafe { |_, w| w.usart3_remap().bits(0b11) });
    }
}
impl RemapMode<USART3> for RemapPartial1<USART3> {
    fn remap(afio: &mut Afio) {
        afio.mapr
            .modify_mapr(unsafe { |_, w| w.usart3_remap().bits(0b01) });
    }
}
