rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
682 stars 149 forks source link

The usage of `take()` and `critical-section` should be added #679

Closed duskmoon314 closed 1 year ago

duskmoon314 commented 1 year ago

After merging #651, Peripherals::take() is not callable unless the user of pac provides an implementation. So we should add how to use it in the document.


Usage I have tried

The following part is mentioned in the matrix chatting room.

I have tried some ways and found two ways of using take():

1 User provide implementation

Users can add implement on their own or use the implementation provided by the target or hal crate. An example will be like this:

# Cargo.toml
# version and other info are ignored
some-pac = { features = ["critical-section"] }
riscv = { features = ["critical-section-single-hart"] }

Then adding a dummy use:

use rust as _;

2 Provide implementation in PAC

We can also provide the implementation in PAC through the target crate.

// lib.rs
#[cfg(feature = "critical-section-single-hart")]
use riscv as _;
# Cargo.toml
[features]
critical-section-single-hart = ["critical-section", "riscv/critical-section-single-hart"]

Then users can add pac like this:

some-pac = { features = ["critical-section-single-hart"] }

Discussion

There may be other usages that I haven't found out. I think it may not be PAC's purpose to provide the implementation. So there should have a section of this in the documentation.