From dd032be5857b4d0db36876f9f5a6b06bb174e774 Mon Sep 17 00:00:00 2001 From: Per <Per Lindgren> Date: Thu, 13 Dec 2018 16:25:04 +0100 Subject: [PATCH] examples and documentation --- README.md | 5 +++++ examples/example.rs | 31 ++++++++++++++++++------------- examples/example2.rs | 5 +++++ src/lib.rs | 5 ++--- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index efa2f79..b45d4e1 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,11 @@ Adds debug to volatile register when compiled with `--features debug-fmt`. +## Caveats + +Notice, the current implementation requres a nightly toolchain (`feature(specilization`)). +This can be + ``` rust extern crate volatile_register; use std::mem; diff --git a/examples/example.rs b/examples/example.rs index c0e601c..411c646 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -1,20 +1,25 @@ +//! Example to show the use of debug output for small register arrays +//! +//! > cargo run --example example2 --features debug-fmt +//! + extern crate volatile_register; use std::mem; -use volatile_register::{RW}; +use volatile_register::RW; - #[repr(C)] - #[derive(Debug)] - pub struct Nvic { - /// Interrupt Set-Enable - pub iser: [RW<u32>; 8], - reserved0: [u32; 24], - /// Interrupt Clear-Enable - pub icer: [RW<u32>; 8], - reserved1: [u32; 24], - // .. more registers .. +#[repr(C)] +#[derive(Debug)] +pub struct Nvic { + /// Interrupt Set-Enable + pub iser: [RW<u32>; 8], + reserved0: [u32; 24], + /// Interrupt Clear-Enable + pub icer: [RW<u32>; 8], + reserved1: [u32; 24], + // .. more registers .. } fn main() { - let r : Nvic = unsafe {mem::uninitialized() }; + let r: Nvic = unsafe { mem::uninitialized() }; println!("{:?}", r); -} \ No newline at end of file +} diff --git a/examples/example2.rs b/examples/example2.rs index 8241dea..1970e6a 100644 --- a/examples/example2.rs +++ b/examples/example2.rs @@ -1,3 +1,8 @@ +//! Example to show the use of debug output for big register arrays +//! +//! > cargo run --example example2 --features debug-fmt +//! + extern crate array_debug; extern crate volatile_register; diff --git a/src/lib.rs b/src/lib.rs index b5cffc8..99522ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,14 +27,13 @@ #![deny(missing_docs)] #![no_std] -#![feature(specialization)] +#![cfg_attr(feature = "debug-fmt", feature(specialization))] extern crate vcell; #[cfg(feature = "debug-fmt")] -use core::fmt; +use core::fmt::{self, Debug, UpperHex}; #[cfg(feature = "debug-fmt")] -use core::fmt::{Debug, UpperHex}; use vcell::VolatileCell; /// Read-Only register -- GitLab