feat(static_pin): remove macro modules

This commit is contained in:
doryan 2025-04-22 22:42:21 +04:00
parent f39fa7b354
commit 6954ce14de
7 changed files with 0 additions and 143 deletions

View File

@ -1,46 +0,0 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "neopixel_macros"
version = "0.1.0"
dependencies = [
"proc-macro2",
"syn",
]
[[package]]
name = "proc-macro2"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "2.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034"

View File

@ -1,13 +0,0 @@
[package]
name = "neopixel_macros"
version = "0.1.0"
edition = "2021"
[lib]
proc_macro = true
[dependencies]
syn = "2.0.58"
[build-dependencies.proc-macro2]
version = "=1.0.79"

View File

@ -1,4 +0,0 @@
[toolchain]
channel = "nightly-2024-03-22"
components = [ "rust-src" ]
profile = "complete"

View File

@ -1,54 +0,0 @@
#![feature(proc_macro_quote)]
#![no_std]
use core::str::FromStr;
extern crate alloc;
use alloc::string::ToString;
use proc_macro::{quote, TokenStream};
use syn::parse;
#[proc_macro]
pub fn impl_static_pin(pin: TokenStream) -> TokenStream {
let parsing_result = parse::<syn::Ident>(pin.clone());
if let Ok(ident) = parsing_result {
let pin = TokenStream::from_str(ident.to_string().as_str()).unwrap();
let mut identifier = ident.to_string();
identifier.insert_str(1, "ORT");
let pin_num = identifier.pop().unwrap();
if pin_num.is_ascii_digit() {
let pin_num = TokenStream::from_str(&pin_num.to_string()).unwrap();
let port_field = TokenStream::from_str(&identifier.to_ascii_lowercase()).unwrap();
let port_ident = TokenStream::from_str(identifier.as_str()).unwrap();
let trait_ident = TokenStream::from_str("StaticPin").unwrap();
quote! {
impl $trait_ident for $pin {
type Port = $port_ident;
const PIN_NUM: u8 = $pin_num;
fn write(data: u8) {
unsafe {
(*Self::Port::ptr())
.$port_field
.write(|w| w.bits(data));
}
}
fn read() -> u8 {
unsafe { (*Self::Port::ptr()).$port_field.read().bits() }
}
}
}
} else {
unreachable!()
}
} else {
unreachable!()
}
}

View File

@ -1,8 +0,0 @@
#[macro_export]
macro_rules! impl_static_pins {
($($pin:ident),+) => {
$(
impl_static_pin!($pin);
)+
};
}

View File

@ -1,2 +0,0 @@
mod static_pin;
pub(crate) use static_pin::*;

View File

@ -1,16 +0,0 @@
use arduino_hal::{hal::port::*, pac::*};
use crate::{impl_static_pin, impl_static_pins};
pub trait StaticPin {
type Port;
const PIN_NUM: u8;
fn write(data: u8);
fn read() -> u8;
}
impl_static_pins!(
PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PC6, PC7, PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PE2,
PE6, PF0, PF1, PF4, PF5, PF6, PF7
);