summaryrefslogtreecommitdiff
path: root/src/examples/_7_generics.rs
diff options
context:
space:
mode:
authorGravatar homunkulus <homunkulus@gmx.com> 2018-01-15 22:34:09 +0000
committerGravatar homunkulus <homunkulus@gmx.com> 2018-01-15 22:34:09 +0000
commitb73263e8fa534233e8c097c6b1e6e430ea160d13 (patch)
treec82e6f193e0bf9b842366e305056481d4d1666b2 /src/examples/_7_generics.rs
parent34edc41e9289e83468f68663a7f4a7f0f6cc2797 (diff)
parentdef4fc8079dcb646ef3cab446a4b160e09e169bf (diff)
downloadrtic-3253f719eb49a2d9ee359a087e4865fe6290d316.tar.gz
rtic-3253f719eb49a2d9ee359a087e4865fe6290d316.tar.zst
rtic-3253f719eb49a2d9ee359a087e4865fe6290d316.zip
Auto merge of #64 - japaric:v3, r=japaricv0.3.0
v0.3.0 None
Diffstat (limited to 'src/examples/_7_generics.rs')
-rw-r--r--src/examples/_7_generics.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/examples/_7_generics.rs b/src/examples/_7_generics.rs
new file mode 100644
index 00000000..22bb777a
--- /dev/null
+++ b/src/examples/_7_generics.rs
@@ -0,0 +1,78 @@
+//! Working with resources in a generic fashion
+//!
+//! ```
+//! #![deny(unsafe_code)]
+//! #![deny(warnings)]
+//! #![feature(proc_macro)]
+//! #![no_std]
+//!
+//! extern crate cortex_m_rtfm as rtfm;
+//! extern crate stm32f103xx;
+//!
+//! use rtfm::{app, Resource, Threshold};
+//! use stm32f103xx::{SPI1, GPIOA};
+//!
+//! app! {
+//! device: stm32f103xx,
+//!
+//! resources: {
+//! static GPIOA: GPIOA;
+//! static SPI1: SPI1;
+//! },
+//!
+//! tasks: {
+//! EXTI0: {
+//! path: exti0,
+//! priority: 1,
+//! resources: [GPIOA, SPI1],
+//! },
+//!
+//! EXTI1: {
+//! path: exti1,
+//! priority: 2,
+//! resources: [GPIOA, SPI1],
+//! },
+//! },
+//! }
+//!
+//! fn init(p: init::Peripherals) -> init::LateResources {
+//! init::LateResources {
+//! GPIOA: p.device.GPIOA,
+//! SPI1: p.device.SPI1,
+//! }
+//! }
+//!
+//! fn idle() -> ! {
+//! loop {
+//! rtfm::wfi();
+//! }
+//! }
+//!
+//! // A generic function that uses some resources
+//! fn work<G, S>(t: &mut Threshold, gpioa: &G, spi1: &S)
+//! where
+//! G: Resource<Data = GPIOA>,
+//! S: Resource<Data = SPI1>,
+//! {
+//! gpioa.claim(t, |_gpioa, t| {
+//! // drive NSS low
+//!
+//! spi1.claim(t, |_spi1, _| {
+//! // transfer data
+//! });
+//!
+//! // drive NSS high
+//! });
+//! }
+//!
+//! // This task needs critical sections to access the resources
+//! fn exti0(t: &mut Threshold, r: EXTI0::Resources) {
+//! work(t, &r.GPIOA, &r.SPI1);
+//! }
+//!
+//! // This task has direct access to the resources
+//! fn exti1(t: &mut Threshold, r: EXTI1::Resources) {
+//! work(t, &r.GPIOA, &r.SPI1);
+//! }
+//! ```
+// Auto-generated. Do not modify.