Skip to content

Commit c58d1f2

Browse files
committed
zephyr: Expand top-level crate docs
Include a summary of functionality available, with links to the relevant pages. Signed-off-by: David Brown <[email protected]>
1 parent 37dc7fa commit c58d1f2

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

zephyr/src/lib.rs

+67-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,73 @@
44
//! Zephyr application support for Rust
55
//!
66
//! This crates provides the core functionality for applications written in Rust that run on top of
7-
//! Zephyr.
7+
//! Zephyr. The goal is to bridge the two worlds. The functionality provided here shouldn't be too
8+
//! distant from how Zephyr does things. But, it should be "rusty" enough that Rust developers feel
9+
//! comfortable using it.
10+
//!
11+
//! Some functionality:
12+
//!
13+
//! - [`time`]: The time module provides a [`Instant`] and [`Duration`] type that are similar to those
14+
//! in `std`, but are tailored for embedded systems. These are bridged through traits, so that most
15+
//! API calls that offer a timeout will accept either an `Instant` or a `Duration`.
16+
//! - [`sync`]: This crate provides various synchronization primitives that can be used to coordinate
17+
//! between threads. These include
18+
//! - [`sync::atomic`]: Provides the same functionality as [`std::sync::atomic`], but on targets
19+
//! with limited synchronization primtives, re-exports features from the 'portable-atomic'
20+
//! crate, which can emulate atomics using critical sections.
21+
//! - [`sync::channel`]: Channel based synchronization built around the `k_queue` channels
22+
//! provided by Zephyr. This provides both `alloc`-based unbounded channels, and bounded
23+
//! channels that pre-allocate.
24+
//! - [`sync::Mutex`]/[`sync::Condvar`]: `std`-style Mutexes and condition variables, where the
25+
//! Mutex protects some piece of data using Rust's features.
26+
//! - [`sync::SpinMutex`]: A Mutex that protects a piece of data, but does so using a spinlock.
27+
//! This is useful where data needs to be used exclusively, but without other types of
28+
//! synchronization.
29+
//! - [`sync::Arc`]: Atomic reference counted pointers. Mostly like [`std::sync::Arc`] but supports
30+
//! all targets that support Rust on Zephyr.
31+
//! - [`sys`]: More direct interfaces to Zephyr's primitives. Most of the operations in `sync` are
32+
//! built on these. These interfaces are 'safe', as in they can be used without the `unsafe`
33+
//! keyword, but the interfaces in `sync` are much more useful from Rust programs. Although most
34+
//! things here won\t typically be needed, two standout:
35+
//! - [`sys::thread`]: A fairly direct, but safe, interface to create Zephyr threads. At this
36+
//! point, this is the primary way to create threads in Rust code (see also [`work`] which
37+
//! supports multiple contexts using Zephyr's work queues.
38+
//! - [`sys::sync::Semaphore`]: The primitive Semaphore type from Zephyr. This is the one lower
39+
//! level operation that is still quite useful in regular code.
40+
//! - [`timer`]: Rust interfaces to Zephyr timers. These timers can be used either by registering a
41+
//! callback, or polled or waited for for an elapsed time.
42+
//! - [`work`]: Zephyr work queues for Rust. The [`work::WorkQueueBuilder`] and resulting
43+
//! [`work::WorkQueue`] allow creation of Zephyr work queues to be used from Rust. The
44+
//! [`work::Work`] item had an action that will be invoked by the work queue, and can be manually
45+
//! submitted when needed.
46+
//! - [`kio`]: An implementation of an async executor built around triggerable work queues in
47+
//! Zephyr. Although there is a bit more overhead to this executor, it is compatible with many of
48+
//! the Zephyr synchronization types, and many of these [`sys::sync::Semaphore`], and
49+
//! [`sync::channel`] will provide `_async` variants of most of the blocking operations. These
50+
//! will return a `Future`, and can be used from async code started by the [`spawn`] function.
51+
//! In addition, because Zephyr's work queues do not work well with Zephyr's Mutex type, this is
52+
//! also a [`kio::sync::Mutex`] type that works with async.
53+
//! - [`logging`]: A logging backend for Rust on Zephyr. This will log to either `printk` or
54+
//! through Zephyr's logging framework.
55+
//!
56+
//! [`Instant`]: time::Instant
57+
//! [`Duration`]: time::Duration
58+
//! [`std::sync::atomic`]: https://doc.rust-lang.org/std/sync/atomic/
59+
//! [`std::sync::Arc`]: https://doc.rust-lang.org/std/sync/struct.Arc.html
60+
//! [`spawn`]: kio::spawn
61+
//!
62+
//! In addition to the above, the [`kconfig`] and [`devicetree`] provide a reflection of the kconfig
63+
//! settings and device tree that were used for a specific build. As such, the documentation
64+
//! provided online is not likely to be that useful, and for these, it is best to generate the
65+
//! documentation for a specific build:
66+
//! ```bash
67+
//! $ west rustdoc
68+
//! ```
69+
//!
70+
//! Note, however, that the `kconfig` module only provides Kconfig **values**, and doesn't provide a
71+
//! mechanmism to base conditional compilation. For that, please see the
72+
//! [zephyr-build](../../std/zephyr_build/index.html) crate, which provides routines that can be
73+
//! called from a `build.rs` file to make these settings available.
874
975
#![no_std]
1076
#![allow(unexpected_cfgs)]

0 commit comments

Comments
 (0)