diff options
author | 2017-11-22 09:27:14 +0100 | |
---|---|---|
committer | 2017-11-22 09:29:01 +0100 | |
commit | 948e1fd0fbd96f574c31909843b2ed3debabf6fc (patch) | |
tree | be8bb18bee86e726a52e19a4083fa0ae9386cdfb /examples/late-resources.rs | |
parent | c184f91e3c3993dacbd8425019cde6a3607478bc (diff) | |
download | rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.tar.gz rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.tar.zst rtic-948e1fd0fbd96f574c31909843b2ed3debabf6fc.zip |
v0.2.2v0.2.2
Diffstat (limited to '')
-rw-r--r-- | examples/late-resources.rs | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/examples/late-resources.rs b/examples/late-resources.rs index bc386584..337fbdfa 100644 --- a/examples/late-resources.rs +++ b/examples/late-resources.rs @@ -16,19 +16,21 @@ app! { // Usually, resources are initialized with a constant initializer: static ON: bool = false; - // However, there are cases where this is not possible or not desired. For example, there - // may not be a sensible value to use, or the type may not be constructible in a constant - // (like `Vec`). - // While it is possible to use an `Option` in some cases, that requires you to properly - // initialize it and `.unwrap()` it at every use. It also consumes more memory. + // However, there are cases where this is not possible or not desired. + // For example, there may not be a sensible value to use, or the type may + // not be constructible in a constant (like `Vec`). // - // To solve this, it is possible to defer initialization of resources to `init` by omitting - // the initializer. Doing that will require `init` to return the values of all "late" - // resources. + // While it is possible to use an `Option` in some cases, that requires + // you to properly initialize it and `.unwrap()` it at every use. It + // also consumes more memory. + // + // To solve this, it is possible to defer initialization of resources to + // `init` by omitting the initializer. Doing that will require `init` to + // return the values of all "late" resources. static IP_ADDRESS: u32; - // PORT is used by 2 tasks, making it a shared resource. This just tests another internal - // code path and is not important for the example. + // PORT is used by 2 tasks, making it a shared resource. This just tests + // another internal code path and is not important for the example. static PORT: u16; }, @@ -54,22 +56,24 @@ app! { // The signature of `init` is now required to have a specific return type. fn init(_p: init::Peripherals, _r: init::Resources) -> init::LateResourceValues { - // `init::Resources` does not contain `IP_ADDRESS`, since it is not yet initialized. + // `init::Resources` does not contain `IP_ADDRESS`, since it is not yet + // initialized. //_r.IP_ADDRESS; // doesn't compile // ...obtain value for IP_ADDRESS from EEPROM/DHCP... let ip_address = 0x7f000001; init::LateResourceValues { - // This struct will contain fields for all resources with omitted initializers. + // This struct will contain fields for all resources with omitted + // initializers. IP_ADDRESS: ip_address, PORT: 0, } } fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) { - // Other tasks can access late resources like any other, since they are guaranteed to be - // initialized when tasks are run. + // Other tasks can access late resources like any other, since they are + // guaranteed to be initialized when tasks are run. r.IP_ADDRESS; } |