Skip to content

Commit e4fc4f2

Browse files
committed
zephyr: Clean up docs
Now that we have doc generation, improve the docs to make the generated docs useful. Signed-off-by: David Brown <[email protected]>
1 parent cdb5b46 commit e4fc4f2

File tree

4 files changed

+51
-13
lines changed

4 files changed

+51
-13
lines changed

zephyr/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ fn panic(info :&PanicInfo) -> ! {
118118
}
119119
}
120120

121-
/// Re-export of zephyr-sys as `zephyr::raw`.
121+
/// Re-export of zephyr-sys as `zephyr::raw`. Generally, most users of zephyr will use
122+
/// `zephyr::raw` instead of directly importing the zephyr-sys crate.
122123
pub mod raw {
123124
pub use zephyr_sys::*;
124125
}

zephyr/src/printk.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ macro_rules! printk {
3535
}};
3636
}
3737

38-
/// Print to Zephyr's console.
38+
/// Print to Zephyr's console, with a newline.
39+
///
40+
/// This macro uses the same syntax as std's
41+
/// [`format!`](https://doc.rust-lang.org/std/macro.format.html), but writes to the Zephyr console
42+
/// instead. See `std::fmt` for more information.
43+
///
44+
/// If `CONFIG_PRINTK_SYNC` is enabled, this locks during printing. However, to avoid allocation,
45+
/// and due to private accessors in the Zephyr printk implementation, the lock is only over groups
46+
/// of a small buffer size. This buffer must be kept fairly small, as it resides on the stack.
3947
///
4048
/// TODO
4149
#[macro_export]
@@ -112,6 +120,8 @@ impl Write for Context {
112120
}
113121
}
114122

123+
/// Implementation of printk, invoked by the printk macro.
124+
#[doc(hidden)]
115125
pub fn printk(args: Arguments<'_>) {
116126
let mut context = Context {
117127
count: 0,
@@ -121,6 +131,8 @@ pub fn printk(args: Arguments<'_>) {
121131
context.flush();
122132
}
123133

134+
/// Implementation of printkln, invoked by the printkln macro.
135+
#[doc(hidden)]
124136
pub fn printkln(args: Arguments<'_>) {
125137
let mut context = Context {
126138
count: 0,

zephyr/src/sys.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,15 @@ use zephyr_sys::k_timeout_t;
1414
// These two constants are not able to be captured by bindgen. It is unlikely that these values
1515
// would change in the Zephyr headers, but there will be an explicit test to make sure they are
1616
// correct.
17+
18+
/// Represents a timeout with an infinite delay.
19+
///
20+
/// Low-level Zephyr constant. Calls using this value will wait as long as necessary to perform
21+
/// the requested operation.
1722
pub const K_FOREVER: k_timeout_t = k_timeout_t { ticks: -1 };
23+
24+
/// Represents a null timeout delay.
25+
///
26+
/// Low-level Zephyr Constant. Calls using this value will not wait if the operation cannot be
27+
/// performed immediately.
1828
pub const K_NO_WAIT: k_timeout_t = k_timeout_t { ticks: 0 };

zephyr/src/time.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@ use core::fmt::Debug;
3434
compile_error!("Rust does not (yet) support dynamic frequency timer");
3535

3636
// Given the above not defined, the system time base comes from a kconfig.
37-
/// The system time base. The system clock has this many ticks per second.
37+
/// The system time base. The system clock has this many ticks per second. Values such as
38+
/// timeouts are defined as some number of these ticks.
3839
pub const SYS_FREQUENCY: u32 = crate::kconfig::CONFIG_SYS_CLOCK_TICKS_PER_SEC as u32;
3940

40-
/// Zephyr can be configured for either 64-bit or 32-bit time values. Use the appropriate type
41-
/// internally to match. This should end up the same size as `k_ticks_t`, but unsigned instead of
42-
/// signed.
41+
// Zephyr can be configured for either 64-bit or 32-bit time values. Use the appropriate type
42+
// internally to match. This should end up the same size as `k_ticks_t`, but unsigned instead of
43+
// signed.
44+
45+
/// Represnts a count of time ticks. Matches Zephyr's `crate::raw::k_ticks_t`, but as an unsigned
46+
/// value, to match Fugit's time requirements.
4347
#[cfg(CONFIG_TIMEOUT_64BIT)]
4448
pub type Tick = u64;
49+
50+
/// Represnts a count of time ticks. Matches Zephyr's `crate::raw::k_ticks_t`, but as an unsigned
51+
/// value, to match Fugit's time requirements.
4552
#[cfg(not(CONFIG_TIMEOUT_64BIT))]
4653
pub type Tick = u32;
4754

@@ -66,7 +73,11 @@ pub type Instant = fugit::Instant<Tick, 1, SYS_FREQUENCY>;
6673
// The absolute time offset is only implemented when time is a 64-bit value. This also means that
6774
// "Instant" isn't available when time is defined as a 32-bit value.
6875

69-
// Wrapper around the timeout type, so we can implement From/Info.
76+
/// Wrapper around the timeout type, so we can implement From/Info.
77+
///
78+
/// This wrapper allows us to implement `From` and `Info` from the Fugit types into the Zephyr
79+
/// types. This allows various methods to accept either value, as well as the `Forever` and
80+
/// `NoWait` values defined here.
7081
pub struct Timeout(pub k_timeout_t);
7182

7283
// `From` allows methods to take a time of various types and convert it into a Zephyr timeout.
@@ -89,8 +100,9 @@ impl From<Instant> for Timeout {
89100
}
90101
}
91102

92-
/// A sleep that waits forever. This is its own type, that is `Into<Timeout>` and can be used
93-
/// anywhere a timeout is needed.
103+
/// A timeout that waits forever.
104+
///
105+
/// This is its own type, that is `Into<Timeout>` and can be used anywhere a timeout is needed.
94106
pub struct Forever;
95107

96108
impl From<Forever> for Timeout {
@@ -99,8 +111,9 @@ impl From<Forever> for Timeout {
99111
}
100112
}
101113

102-
/// A sleep that doesn't ever wait. This is its own type, that is `Info<Timeout>` and can be used
103-
/// anywhere a timeout is needed.
114+
/// A timeout that doesn't ever wait.
115+
///
116+
/// This is its own type, that is `Info<Timeout>` and can be used anywhere a timeout is needed.
104117
pub struct NoWait;
105118

106119
impl From<NoWait> for Timeout {
@@ -109,8 +122,10 @@ impl From<NoWait> for Timeout {
109122
}
110123
}
111124

112-
/// Put the current thread to sleep, for the given duration. Uses `k_sleep` for the actual sleep.
113-
/// Returns a duration roughly representing the remaining amount of time if the sleep was woken.
125+
/// Put the current thread to sleep, for the given duration.
126+
///
127+
/// Uses `k_sleep` for the actual sleep. Returns a duration roughly representing the remaining
128+
/// amount of time if the sleep was woken.
114129
pub fn sleep<T>(timeout: T) -> Duration
115130
where T: Into<Timeout>,
116131
{

0 commit comments

Comments
 (0)