Skip to main content

device_envoy_rp/
lib.rs

1#![doc = include_str!("../README.md")]
2//!
3//! # Glossary
4//!
5//! Resources available on the Pico 1 and Pico 2:
6//!
7//! - **PIO ([Programmable I/O](https://medium.com/data-science/nine-pico-pio-wats-with-rust-part-1-9d062067dc25)):** Pico 1 has 2. Pico 2 has 3.
8//! - **DMA ([Direct Memory Access](https://en.wikipedia.org/wiki/Direct_memory_access)):** Both Pico 1 and 2 have 12 channels.
9//! - **PWM ([Pulse Width Modulation](https://en.wikipedia.org/wiki/Pulse-width_modulation)) Slices:** Both  Pico 1 and 2 have 8 slices (& 16 channels). These "slices"
10//!   are unrelated Rust slices.
11//! - **I2C ([Inter-Integrated Circuit](https://en.wikipedia.org/wiki/I%C2%B2C)):** Serial control bus used by abstractions like `lcd_text`. Pico 1 and Pico 2 each provide 2 controllers (`I2C0`, `I2C1`).
12#![cfg_attr(target_os = "none", no_std)]
13#![cfg_attr(target_os = "none", no_main)]
14#![cfg_attr(docsrs, feature(doc_cfg))]
15#![allow(async_fn_in_trait, reason = "single-threaded embedded")]
16
17// Compile-time checks: exactly one board must be selected (unless testing with host feature)
18#[cfg(all(target_os = "none", not(any(feature = "pico1", feature = "pico2"))))]
19compile_error!("Must enable exactly one board feature: 'pico1' or 'pico2'");
20
21#[cfg(all(target_os = "none", feature = "pico1", feature = "pico2"))]
22compile_error!("Cannot enable both 'pico1' and 'pico2' features simultaneously");
23
24// Compile-time checks: exactly one architecture must be selected (unless testing with host feature)
25#[cfg(all(target_os = "none", not(any(feature = "arm", feature = "riscv"))))]
26compile_error!("Must enable exactly one architecture feature: 'arm' or 'riscv'");
27
28#[cfg(all(target_os = "none", feature = "arm", feature = "riscv"))]
29compile_error!("Cannot enable both 'arm' and 'riscv' features simultaneously");
30
31// Compile-time check: pico1 only supports ARM
32#[cfg(all(target_os = "none", feature = "pico1", feature = "riscv"))]
33compile_error!("Pico 1 (RP2040) only supports ARM architecture, not RISC-V");
34
35// PIO interrupt bindings - shared by led_strip::strip and led_strip
36#[cfg(target_os = "none")]
37#[doc(hidden)]
38pub mod pio_irqs;
39// Embedded-only in normal builds, but compiled for host unit tests.
40#[cfg(any(target_os = "none", all(test, feature = "host")))]
41pub mod audio_player;
42#[cfg(target_os = "none")]
43pub mod button;
44#[cfg(all(feature = "wifi", target_os = "none"))]
45pub mod clock_sync;
46mod error;
47#[cfg(target_os = "none")]
48pub mod flash_block;
49#[cfg(target_os = "none")]
50pub mod ir;
51#[cfg(target_os = "none")]
52pub mod lcd_text;
53#[cfg(target_os = "none")]
54pub mod led;
55pub mod led2d;
56#[cfg(target_os = "none")]
57pub mod led4;
58pub mod led_strip;
59#[cfg(target_os = "none")]
60pub mod rfid;
61#[cfg(target_os = "none")]
62pub mod servo;
63#[cfg(target_os = "none")]
64mod servo_player;
65#[cfg(all(feature = "wifi", target_os = "none"))]
66pub mod wifi_auto;
67
68#[cfg(doc)]
69pub mod docs {
70    //! Documentation-only pages for this crate.
71    #[doc = include_str!("docs/development_guide.md")]
72    pub mod development_guide {}
73}
74
75// Re-export error types and result (used throughout)
76pub use crate::error::{Error, Result};
77pub use device_envoy_core::tone;
78/// Used internally by other macros.
79#[doc(hidden)]
80pub use paste::paste as __paste;
81
82/// Public for macro expansion in downstream crates.
83#[doc(hidden)]
84#[macro_export]
85macro_rules! __validate_keyword_fields_expr {
86    (
87        macro_name: $macro_name:literal,
88        allowed_macro: $allowed_macro:path,
89        fields: [ $( $field:ident : $value:expr ),* $(,)? ]
90    ) => {
91        const _: () = {
92            $( $allowed_macro!($field, $macro_name); )*
93            #[allow(non_snake_case)]
94            mod __device_envoy_keyword_fields_uniqueness {
95                $( pub(super) mod $field {} )*
96            }
97        };
98    };
99
100    (
101        macro_name: $macro_name:literal,
102        allowed_macro: $allowed_macro:path,
103        fields: [ $($fields:tt)* ]
104    ) => {
105        compile_error!(concat!($macro_name, " fields must use `name: value` syntax"));
106    };
107}