Skip to content

dts: only generate getters for okay nodes #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
37 changes: 22 additions & 15 deletions zephyr-build/src/devicetree/augment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,31 @@ impl RawInfo {
Self::Myself => {
let ord = node.ord;
let rawdev = format_ident!("__device_dts_ord_{}", ord);
quote! {
/// Get the raw `const struct device *` of the device tree generated node.
pub unsafe fn get_instance_raw() -> *const crate::raw::device {
&crate::raw::#rawdev
}
#[allow(dead_code)]
pub(crate) unsafe fn get_static_raw() -> &'static #static_type {
&STATIC
}
match node.get_single_string("status") {
Some("okay") | Some("ok") | None => {
quote! {
/// Get the raw `const struct device *` of the device tree generated node.
pub unsafe fn get_instance_raw() -> *const crate::raw::device {
&crate::raw::#rawdev
}
#[allow(dead_code)]
pub(crate) unsafe fn get_static_raw() -> &'static #static_type {
&STATIC
}

static UNIQUE: crate::device::Unique = crate::device::Unique::new();
static STATIC: #static_type = #static_type::new();
pub fn get_instance() -> Option<#device_id> {
unsafe {
let device = get_instance_raw();
#device_id::new(&UNIQUE, &STATIC, device)
static UNIQUE: crate::device::Unique = crate::device::Unique::new();
static STATIC: #static_type = #static_type::new();
pub fn get_instance() -> Option<#device_id> {
unsafe {
let device = get_instance_raw();
#device_id::new(&UNIQUE, &STATIC, device)
}
}
}
}
_ => {
quote! {}
}
}
}
Self::Phandle(pname) => {
Expand Down