From 9b34516ae00a2cfe6c006535fc01085efed18cb6 Mon Sep 17 00:00:00 2001 From: doryan Date: Thu, 20 Mar 2025 21:45:48 +0400 Subject: [PATCH] refactor(small): rename method and trait --- static_pins/src/lib.rs | 8 ++++---- static_pins/static_pins_macros/src/lib.rs | 18 ++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/static_pins/src/lib.rs b/static_pins/src/lib.rs index d1fb30d..0f81fba 100644 --- a/static_pins/src/lib.rs +++ b/static_pins/src/lib.rs @@ -2,13 +2,13 @@ pub use static_pins_macros::*; -pub trait StaticPin { +pub trait StaticPinOps { type Port; const PIN_NUM: u8; fn into_input(); fn into_output(); - fn into_pullup_input(); + fn into_pull_up_input(); fn write(data: u8); fn read() -> u8; @@ -17,13 +17,13 @@ pub trait StaticPin { #[macro_export] macro_rules! impl_static_pins { ($($pin:expr), +) => { - pub trait StaticPin { + pub trait StaticPinOps { type Port; const PIN_NUM: u8; fn into_input(); fn into_output(); - fn into_pullup_input(); + fn into_pull_up_input(); fn write(data: u8); fn read() -> u8; diff --git a/static_pins/static_pins_macros/src/lib.rs b/static_pins/static_pins_macros/src/lib.rs index 15dd6d4..714a3d3 100644 --- a/static_pins/static_pins_macros/src/lib.rs +++ b/static_pins/static_pins_macros/src/lib.rs @@ -29,13 +29,11 @@ pub fn impl_static_pin(pin: TokenStream) -> TokenStream { _ => panic!("Register name is incorrect"), }; - let target_field_port = - proc_macro2::TokenStream::from_str(&port.to_ascii_lowercase()).unwrap(); - + let target_port = proc_macro2::TokenStream::from_str(&port.to_ascii_lowercase()).unwrap(); let target_pin = format_ident!("pin{}", port_register_name.to_ascii_lowercase()); let target_data_direction = format_ident!("ddr{}", port_register_name.to_ascii_lowercase()); - let trait_name = proc_macro2::TokenStream::from_str("StaticPin").unwrap(); + let trait_name = proc_macro2::TokenStream::from_str("StaticPinOps").unwrap(); let impl_trait = quote! { impl #trait_name for #pin { @@ -46,7 +44,7 @@ pub fn impl_static_pin(pin: TokenStream) -> TokenStream { fn write(data: u8) { unsafe { (*Self::Port::ptr()) - .#target_field_port + .#target_port .write(|w| w.bits(data)); } } @@ -68,7 +66,7 @@ pub fn impl_static_pin(pin: TokenStream) -> TokenStream { .#target_data_direction .modify(|_r, w| w.#writer_method().clear_bit()); (*Self::Port::ptr()) - .#target_field_port + .#target_port .modify(|_r, w| w.#writer_method().clear_bit()); } } @@ -80,20 +78,20 @@ pub fn impl_static_pin(pin: TokenStream) -> TokenStream { .#target_data_direction .modify(|_r, w| w.#writer_method().set_bit()); (*Self::Port::ptr()) - .#target_field_port + .#target_port .modify(|_r, w| w.#writer_method().clear_bit()); } } #[inline] - fn into_pullup_input() { + fn into_pull_up_input() { unsafe { (*Self::Port::ptr()) .#target_data_direction .modify(|_r, w| w.#writer_method().clear_bit()); (*Self::Port::ptr()) - .#target_field_port - .modify(|_r, w| w.#writer_method().set_bit()); + .#target_port + .modify(|r, w| w.#writer_method().set_bit()); } } }