refactor(small): rename method and trait
This commit is contained in:
parent
03b047f9af
commit
9b34516ae0
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue