Skip to content

Commit e7ee523

Browse files
committed
readAction warning
1 parent 90ea9f1 commit e7ee523

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Use `warning` class in docs
1011
- Refactor `Accessor`
1112

1213
## [v0.33.3] - 2024-05-10

src/generate/register.rs

+35-34
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ pub fn render(
109109
};
110110

111111
let mut alias_doc = format!(
112-
"{name} ({accs}) register accessor: {description}\n\n{}",
112+
"{name} ({accs}) register accessor: {description}{}{}",
113113
api_docs(
114114
access.can_read(),
115115
access.can_write(),
116116
register.properties.reset_value.is_some(),
117117
&mod_ty,
118118
false,
119-
register.read_action,
120-
)?
119+
)?,
120+
read_action_docs(access.can_read(), register.read_action),
121121
);
122122
alias_doc +=
123123
format!("\n\nFor information about available fields see [`mod@{mod_ty}`] module")
@@ -147,38 +147,43 @@ pub fn render(
147147
}
148148
}
149149

150+
fn read_action_docs(can_read: bool, read_action: Option<ReadAction>) -> String {
151+
let mut doc = String::new();
152+
if can_read {
153+
if let Some(action) = read_action {
154+
doc.push_str("\n\n<div class=\"warning\">");
155+
doc.push_str(match action {
156+
ReadAction::Clear => "The register is <b>cleared</b> (set to zero) following a read operation.",
157+
ReadAction::Set => "The register is <b>set</b> (set to ones) following a read operation.",
158+
ReadAction::Modify => "The register is <b>modified</b> in some way after a read operation.",
159+
ReadAction::ModifyExternal => "One or more dependent resources other than the current register are immediately affected by a read operation.",
160+
});
161+
doc.push_str("</div>");
162+
}
163+
}
164+
doc
165+
}
166+
150167
fn api_docs(
151168
can_read: bool,
152169
can_write: bool,
153170
can_reset: bool,
154171
module: &Ident,
155172
inmodule: bool,
156-
read_action: Option<ReadAction>,
157173
) -> Result<String, std::fmt::Error> {
158174
fn method(s: &str) -> String {
159175
format!("[`{s}`](crate::Reg::{s})")
160176
}
161177

162-
let mut doc = String::new();
178+
let mut doc = String::from("\n\n");
163179

164180
if can_read {
165181
write!(
166182
doc,
167-
"You can {} this register and get [`{module}::R`]{}.",
183+
"You can {} this register and get [`{module}::R`]{}. ",
168184
method("read"),
169185
if inmodule { "(R)" } else { "" },
170186
)?;
171-
172-
if let Some(action) = read_action {
173-
doc.push_str(" WARN: ");
174-
doc.push_str(match action {
175-
ReadAction::Clear => "The register is **cleared** (set to zero) following a read operation.",
176-
ReadAction::Set => "The register is **set** (set to ones) following a read operation.",
177-
ReadAction::Modify => "The register is **modified** in some way after a read operation.",
178-
ReadAction::ModifyExternal => "One or more dependent resources other than the current register are immediately affected by a read operation.",
179-
});
180-
}
181-
doc.push(' ');
182187
}
183188

184189
if can_write {
@@ -355,15 +360,9 @@ pub fn render_register_mod(
355360
}
356361

357362
let doc = format!(
358-
"{description}\n\n{}",
359-
api_docs(
360-
can_read,
361-
can_write,
362-
can_reset,
363-
&mod_ty,
364-
true,
365-
register.read_action,
366-
)?
363+
"{description}{}{}",
364+
api_docs(can_read, can_write, can_reset, &mod_ty, true)?,
365+
read_action_docs(access.can_read(), register.read_action),
367366
);
368367

369368
mod_items.extend(quote! {
@@ -951,12 +950,14 @@ pub fn fields(
951950
};
952951
let mut readerdoc = field_reader_brief.clone();
953952
if let Some(action) = f.read_action {
954-
readerdoc += match action {
955-
ReadAction::Clear => "\n\nThe field is **cleared** (set to zero) following a read operation.",
956-
ReadAction::Set => "\n\nThe field is **set** (set to ones) following a read operation.",
957-
ReadAction::Modify => "\n\nThe field is **modified** in some way after a read operation.",
958-
ReadAction::ModifyExternal => "\n\nOne or more dependent resources other than the current field are immediately affected by a read operation.",
959-
};
953+
readerdoc.push_str("\n\n<div class=\"warning\">");
954+
readerdoc.push_str(match action {
955+
ReadAction::Clear => "The field is <b>cleared</b> (set to zero) following a read operation.",
956+
ReadAction::Set => "The field is <b>set</b> (set to ones) following a read operation.",
957+
ReadAction::Modify => "The field is <b>modified</b> in some way after a read operation.",
958+
ReadAction::ModifyExternal => "One or more dependent resources other than the current field are immediately affected by a read operation.",
959+
});
960+
readerdoc.push_str("</div>");
960961
}
961962
mod_items.extend(quote! {
962963
#[doc = #readerdoc]
@@ -992,7 +993,7 @@ pub fn fields(
992993
let increment = de.dim_increment;
993994
let doc = description.expand_dim(&brief_suffix);
994995
let first_name = svd::array::names(f, de).next().unwrap();
995-
let note = format!("NOTE: `n` is number of field in register. `n == 0` corresponds to `{first_name}` field");
996+
let note = format!("<div class=\"warning\">`n` is number of field in register. `n == 0` corresponds to `{first_name}` field.</div>");
996997
let offset_calc = calculate_offset(increment, offset, true);
997998
let value = quote! { ((self.bits >> #offset_calc) & #hexmask) #cast };
998999
let dim = unsuffixed(de.dim);
@@ -1279,7 +1280,7 @@ pub fn fields(
12791280
let offset_calc = calculate_offset(increment, offset, false);
12801281
let doc = &description.expand_dim(&brief_suffix);
12811282
let first_name = svd::array::names(f, de).next().unwrap();
1282-
let note = format!("NOTE: `n` is number of field in register. `n == 0` corresponds to `{first_name}` field");
1283+
let note = format!("<div class=\"warning\">`n` is number of field in register. `n == 0` corresponds to `{first_name}` field.</div>");
12831284
let dim = unsuffixed(de.dim);
12841285
w_impl_items.extend(quote! {
12851286
#[doc = #doc]

0 commit comments

Comments
 (0)