Skip to content

Commit d0cd2e0

Browse files
author
Jorge Aparicio
committed
tweak docs to include address offsets and bit positions
1 parent 3f5a667 commit d0cd2e0

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/lib.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ pub fn gen_peripheral(cx: &ExtCtxt, p: &Peripheral, d: &Defaults) -> Vec<P<Item>
6262
i += 1;
6363
}
6464

65-
let comment = &format!("/// {}", respace(&register.description))[..];
65+
let comment = &format!("/// 0x{:02x} - {}",
66+
register.address_offset,
67+
respace(&register.description))[..];
6668
fields.push(builder.struct_field(register.name.to_camel_case())
6769
.pub_()
6870
.attr()
@@ -241,7 +243,13 @@ pub fn gen_register_r(cx: &ExtCtxt, r: &Register, d: &Defaults) -> Vec<P<Item>>
241243
};
242244

243245
if let Some(description) = field.description.as_ref() {
244-
let comment = &format!("/// {}", respace(description))[..];
246+
let bits = if width == 1 {
247+
format!("Bit {}", field.bit_range.offset)
248+
} else {
249+
format!("Bits {}:{}", field.bit_range.offset, field.bit_range.offset + width - 1)
250+
};
251+
252+
let comment = &format!("/// {} - {}", bits, respace(description))[..];
245253
item.attrs.push(builder.attr().doc(comment));
246254
}
247255

@@ -319,7 +327,13 @@ pub fn gen_register_w(cx: &ExtCtxt, r: &Register, d: &Defaults) -> Vec<P<Item>>
319327
};
320328

321329
if let Some(description) = field.description.as_ref() {
322-
let comment = &format!("/// {}", respace(description))[..];
330+
let bits = if width == 1 {
331+
format!("Bit {}", field.bit_range.offset)
332+
} else {
333+
format!("Bits {}:{}", field.bit_range.offset, field.bit_range.offset + width - 1)
334+
};
335+
336+
let comment = &format!("/// {} - {}", bits, respace(description))[..];
323337
item.attrs.push(builder.attr().doc(comment));
324338
}
325339

0 commit comments

Comments
 (0)