Migrate USART to macro tables.
This commit is contained in:
parent
6958091b50
commit
00892c7362
@ -48,20 +48,20 @@ with open(output_file, 'w') as f:
|
|||||||
|
|
||||||
custom_singletons = False
|
custom_singletons = False
|
||||||
|
|
||||||
if block_mod == 'usart':
|
# if block_mod == 'usart':
|
||||||
f.write(f'impl_usart!({name});')
|
# f.write(f'impl_usart!({name});')
|
||||||
for pin, funcs in af.items():
|
# for pin, funcs in af.items():
|
||||||
if pin in pins:
|
# if pin in pins:
|
||||||
if (func := funcs.get(f'{name}_RX')) != None:
|
# if (func := funcs.get(f'{name}_RX')) != None:
|
||||||
f.write(f'impl_usart_pin!({name}, RxPin, {pin}, {func});')
|
# f.write(f'impl_usart_pin!({name}, RxPin, {pin}, {func});')
|
||||||
if (func := funcs.get(f'{name}_TX')) != None:
|
# if (func := funcs.get(f'{name}_TX')) != None:
|
||||||
f.write(f'impl_usart_pin!({name}, TxPin, {pin}, {func});')
|
# f.write(f'impl_usart_pin!({name}, TxPin, {pin}, {func});')
|
||||||
if (func := funcs.get(f'{name}_CTS')) != None:
|
# if (func := funcs.get(f'{name}_CTS')) != None:
|
||||||
f.write(f'impl_usart_pin!({name}, CtsPin, {pin}, {func});')
|
# f.write(f'impl_usart_pin!({name}, CtsPin, {pin}, {func});')
|
||||||
if (func := funcs.get(f'{name}_RTS')) != None:
|
# if (func := funcs.get(f'{name}_RTS')) != None:
|
||||||
f.write(f'impl_usart_pin!({name}, RtsPin, {pin}, {func});')
|
# f.write(f'impl_usart_pin!({name}, RtsPin, {pin}, {func});')
|
||||||
if (func := funcs.get(f'{name}_CK')) != None:
|
# if (func := funcs.get(f'{name}_CK')) != None:
|
||||||
f.write(f'impl_usart_pin!({name}, CkPin, {pin}, {func});')
|
# f.write(f'impl_usart_pin!({name}, CkPin, {pin}, {func});')
|
||||||
|
|
||||||
# if block_mod == 'rng':
|
# if block_mod == 'rng':
|
||||||
# for irq in chip['interrupts']:
|
# for irq in chip['interrupts']:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#[cfg_attr(usart_v1, path = "v1.rs")]
|
#[cfg_attr(usart_v1, path = "v1.rs")]
|
||||||
#[cfg_attr(usart_v2, path = "v2.rs")]
|
#[cfg_attr(usart_v2, path = "v2.rs")]
|
||||||
mod _version;
|
mod _version;
|
||||||
|
use crate::peripherals;
|
||||||
pub use _version::*;
|
pub use _version::*;
|
||||||
|
|
||||||
use crate::gpio::Pin;
|
use crate::gpio::Pin;
|
||||||
@ -51,24 +52,48 @@ pub trait CtsPin<T: Instance>: sealed::CtsPin<T> {}
|
|||||||
pub trait RtsPin<T: Instance>: sealed::RtsPin<T> {}
|
pub trait RtsPin<T: Instance>: sealed::RtsPin<T> {}
|
||||||
pub trait CkPin<T: Instance>: sealed::CkPin<T> {}
|
pub trait CkPin<T: Instance>: sealed::CkPin<T> {}
|
||||||
|
|
||||||
macro_rules! impl_usart {
|
crate::pac::peripherals!(
|
||||||
($inst:ident) => {
|
(usart, $inst:ident) => {
|
||||||
impl crate::usart::sealed::Instance for peripherals::$inst {
|
impl sealed::Instance for peripherals::$inst {
|
||||||
fn regs(&self) -> crate::pac::usart::Usart {
|
fn regs(&self) -> crate::pac::usart::Usart {
|
||||||
crate::pac::$inst
|
crate::pac::$inst
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl crate::usart::Instance for peripherals::$inst {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_usart_pin {
|
impl Instance for peripherals::$inst {}
|
||||||
($inst:ident, $func:ident, $pin:ident, $af:expr) => {
|
};
|
||||||
impl crate::usart::sealed::$func<peripherals::$inst> for peripherals::$pin {
|
);
|
||||||
|
|
||||||
|
macro_rules! impl_pin {
|
||||||
|
($inst:ident, $pin:ident, $signal:ident, $af:expr) => {
|
||||||
|
impl sealed::$signal<peripherals::$inst> for peripherals::$pin {
|
||||||
fn af_num(&self) -> u8 {
|
fn af_num(&self) -> u8 {
|
||||||
$af
|
$af
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl crate::usart::$func<peripherals::$inst> for peripherals::$pin {}
|
|
||||||
|
impl $signal<peripherals::$inst> for peripherals::$pin {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate::pac::peripheral_pins!(
|
||||||
|
($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => {
|
||||||
|
impl_pin!($inst, $pin, TxPin, $af);
|
||||||
|
};
|
||||||
|
|
||||||
|
($inst:ident, usart, USART, $pin:ident, RX, $af:expr) => {
|
||||||
|
impl_pin!($inst, $pin, RxPin, $af);
|
||||||
|
};
|
||||||
|
|
||||||
|
($inst:ident, usart, USART, $pin:ident, CTS, $af:expr) => {
|
||||||
|
impl_pin!($inst, $pin, CtsPin, $af);
|
||||||
|
};
|
||||||
|
|
||||||
|
($inst:ident, usart, USART, $pin:ident, RTS, $af:expr) => {
|
||||||
|
impl_pin!($inst, $pin, RtsPin, $af);
|
||||||
|
};
|
||||||
|
|
||||||
|
($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => {
|
||||||
|
impl_pin!($inst, $pin, CkPin, $af);
|
||||||
|
};
|
||||||
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user