Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- SYSTIMER ETM functionality (#828)
- Adding async support for RSA peripheral(doesn't work properly for `esp32` chip - issue will be created)(#790)
- Added sleep support for ESP32-C3 with timer and GPIO wakeups (#795)
- Support for ULP-RISCV including Delay and GPIO (#840)
- Support for ULP-RISCV including Delay and GPIO (#840, #845)
- Add bare-bones SPI slave support, DMA only (#580, #843)
- Embassy `#[main]` convenience macro
- Embassy `#[main]` convenience macro (#841)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion esp-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fugit = "0.3.7"
log = { version = "0.4.20", optional = true }
nb = "1.1.0"
paste = "1.0.14"
procmacros = { version = "0.6.1", package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
procmacros = { version = "0.6.1", features = ["enum-dispatch", "ram"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
strum = { version = "0.25.0", default-features = false, features = ["derive"] }
void = { version = "1.0.2", default-features = false }
usb-device = { version = "0.2.9", optional = true }
Expand Down
49 changes: 25 additions & 24 deletions esp-hal-procmacros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
[package]
name = "esp-hal-procmacros"
version = "0.6.1"
authors = [
"Jesse Braham <[email protected]>",
"Björn Quentin <[email protected]>",
]
name = "esp-hal-procmacros"
version = "0.6.1"
edition = "2021"
rust-version = "1.67.0"
description = "Procedural macros for ESP-HAL"
repository = "https://github.com/esp-rs/esp-hal"
license = "MIT OR Apache-2.0"

[package.metadata.docs.rs]
features = ["esp32c3", "interrupt"]
features = ["esp32c3", "interrupt", "ram"]

[lib]
proc-macro = true

[dependencies]
darling = "0.20.3"
proc-macro-crate = "1.3.1"
litrs = "0.4.0"
object = { version = "0.32.1", optional = true }
proc-macro-crate = "2.0.0"
proc-macro-error = "1.0.4"
proc-macro2 = "1.0.66"
proc-macro2 = "1.0.69"
quote = "1.0.33"
syn = {version = "2.0.31", features = ["extra-traits", "full"]}
object = {version = "0.32.1", optional = true}
litrs = "0.4.0"
# toml_edit is a dependency of proc-macro-crate. Unfortunately they raised their MSRV on 0.19.15 so we pin the version for now
toml_edit = "=0.19.14"
syn = { version = "2.0.38", features = ["extra-traits", "full"] }

[features]
esp32 = []
esp32c2 = []
esp32c3 = []
esp32c6 = ["dep:object"]
esp32h2 = []
esp32s2 = ["dep:object"]
esp32s3 = ["dep:object"]
# Select a target device:
esp32 = []
esp32c2 = []
esp32c3 = []
esp32c6 = ["dep:object"]
esp32c6-lp = []
esp32h2 = []
esp32s2 = ["dep:object"]
esp32s2-ulp = []
esp32s3 = ["dep:object"]
esp32s3-ulp = []

interrupt = []
rtc_slow = []
embassy = []
# Gated features:
embassy = []
enum-dispatch = []
interrupt = []
ram = []
rtc_slow = []
56 changes: 56 additions & 0 deletions esp-hal-procmacros/src/enum_dispatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use proc_macro2::{Group, TokenTree};
use syn::{
parse::{Parse, ParseStream, Result},
Ident,
};

#[derive(Debug)]
pub(crate) struct MakeGpioEnumDispatchMacro {
pub name: String,
pub filter: Vec<String>,
pub elements: Vec<(String, usize)>,
}

impl Parse for MakeGpioEnumDispatchMacro {
fn parse(input: ParseStream) -> Result<Self> {
let name = input.parse::<Ident>()?.to_string();
let filter = input
.parse::<Group>()?
.stream()
.into_iter()
.map(|v| match v {
TokenTree::Group(_) => String::new(),
TokenTree::Ident(ident) => ident.to_string(),
TokenTree::Punct(_) => String::new(),
TokenTree::Literal(_) => String::new(),
})
.filter(|p| !p.is_empty())
.collect();

let mut elements = vec![];

let mut stream = input.parse::<Group>()?.stream().into_iter();
let mut element_name = String::new();
loop {
match stream.next() {
Some(v) => match v {
TokenTree::Ident(ident) => {
element_name = ident.to_string();
}
TokenTree::Literal(lit) => {
let index = lit.to_string().parse().unwrap();
elements.push((element_name.clone(), index));
}
_ => (),
},
None => break,
}
}

Ok(MakeGpioEnumDispatchMacro {
name,
filter,
elements,
})
}
}
62 changes: 62 additions & 0 deletions esp-hal-procmacros/src/interrupt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use proc_macro::{self, TokenStream};
use syn::{parse::Error, spanned::Spanned, AttrStyle, Attribute};

pub(crate) enum WhiteListCaller {
Interrupt,
}

pub(crate) fn check_attr_whitelist(
attrs: &[Attribute],
caller: WhiteListCaller,
) -> Result<(), TokenStream> {
let whitelist = &[
"doc",
"link_section",
"cfg",
"allow",
"warn",
"deny",
"forbid",
"cold",
"ram",
"inline",
];

'o: for attr in attrs {
for val in whitelist {
if eq(&attr, &val) {
continue 'o;
}
}

let err_str = match caller {
WhiteListCaller::Interrupt => {
"this attribute is not allowed on an interrupt handler controlled by esp-hal"
}
};

return Err(Error::new(attr.span(), &err_str).to_compile_error().into());
}

Ok(())
}

pub(crate) fn extract_cfgs(attrs: Vec<Attribute>) -> (Vec<Attribute>, Vec<Attribute>) {
let mut cfgs = vec![];
let mut not_cfgs = vec![];

for attr in attrs {
if eq(&attr, "cfg") {
cfgs.push(attr);
} else {
not_cfgs.push(attr);
}
}

(cfgs, not_cfgs)
}

/// Returns `true` if `attr.path` matches `name`
fn eq(attr: &Attribute, name: &str) -> bool {
attr.style == AttrStyle::Outer && attr.path().is_ident(name)
}
Loading