1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! A device abstraction that combines NTP time synchronization with a local clock.
//!
//! See [`ClockSyncRp`] for constructors and [`ClockSync`] for clock operations.
//!
//! Constructor methods on `ClockSyncRp` come from `device-envoy-core` and return
//! [`CoreResult`] with [`CoreError`].
//!
//! You can create up to two concurrent `ClockSyncRp` instances per program; a third is expected to fail at runtime because the `clock_sync` task pool uses `pool_size = 2`.
//!
//! # Example: WiFi + ClockSync logging
//!
//! ```rust,no_run
//! # #![no_std]
//! # #![no_main]
//! # use defmt_rtt as _;
//! # use panic_probe as _;
//! use device_envoy_rp::{
//! Error,
//! Result,
//! button::PressedTo,
//! button_watch,
//! clock_sync::{ClockSync as _, ClockSyncRp, ClockSyncStaticRp, ONE_SECOND, h12_m_s},
//! flash_block::FlashBlockRp,
//! wifi_auto::fields::{TimezoneField, TimezoneFieldStatic},
//! wifi_auto::{WifiAuto as _, WifiAutoEvent, WifiAutoRp},
//! };
//! use defmt::info;
//!
//! button_watch! {
//! ButtonWatch13 {
//! pin: PIN_13,
//! }
//! }
//!
//! async fn run(
//! spawner: embassy_executor::Spawner,
//! p: embassy_rp::Peripherals,
//! ) -> Result<(), device_envoy_rp::Error> {
//! let [wifi_credentials_flash_block, timezone_flash_block] = FlashBlockRp::new_array::<2>(p.FLASH)?;
//!
//! static TIMEZONE_STATIC: TimezoneFieldStatic = TimezoneField::new_static();
//! let timezone_field = TimezoneField::new(&TIMEZONE_STATIC, timezone_flash_block);
//!
//! let button_watch13 = ButtonWatch13::new(p.PIN_13, PressedTo::Ground, spawner).await?;
//! let wifi_auto = WifiAutoRp::new(
//! p.PIN_23,
//! p.PIN_24,
//! p.PIN_25,
//! p.PIN_29,
//! p.PIO0,
//! p.DMA_CH0,
//! wifi_credentials_flash_block,
//! "ClockSync",
//! [timezone_field],
//! spawner,
//! )?;
//!
//! let stack = wifi_auto
//! .connect(&mut *button_watch13, |event| async move {
//! match event {
//! WifiAutoEvent::CaptivePortalReady => {
//! info!("WifiAutoRp: setup mode ready");
//! }
//! WifiAutoEvent::Connecting { .. } => {
//! info!("WifiAutoRp: connecting");
//! }
//! WifiAutoEvent::ConnectionFailed => {
//! info!("WifiAutoRp: connection failed");
//! }
//! }
//! Ok(())
//! })
//! .await?;
//!
//! let offset_minutes = timezone_field
//! .offset_minutes()?
//! .ok_or(Error::MissingCustomWifiAutoField)?;
//! static CLOCK_SYNC_STATIC: ClockSyncStaticRp = ClockSyncRp::new_static();
//! let clock_sync = ClockSyncRp::new(
//! &CLOCK_SYNC_STATIC,
//! stack,
//! offset_minutes,
//! Some(ONE_SECOND),
//! spawner,
//! )?;
//!
//! loop {
//! let tick = clock_sync.wait_for_tick().await;
//! let (hours, minutes, seconds) = h12_m_s(&tick.local_time);
//! info!(
//! "Time {:02}:{:02}:{:02}, since sync {}s",
//! hours,
//! minutes,
//! seconds,
//! tick.since_last_sync.as_secs()
//! );
//! }
//! }
//! ```
/// A device abstraction that combines NTP time synchronization with a local clock.
pub use ClockSyncRuntime as ClockSyncRp;
/// Resources needed to construct [`ClockSyncRp`].
pub use ClockSyncStatic as ClockSyncStaticRp;
pub use ;
pub use ;