Expand description
§RTC Trait Interface
This module defines the core trait for Real-Time Clock (RTC) devices in embedded systems.
§Features
- Provides a platform-independent interface for reading and writing date/time values to hardware RTC chips.
- Compatible with the design patterns of
embedded-hal, focusing on trait-based abstraction. - Uses the hardware-agnostic
DateTimestruct for representing calendar date and time.
§Usage Notes
- Each RTC driver should implement its own error type conforming to the
Errortrait, allowing accurate hardware-specific error reporting. - Drivers are responsible for validating that all
DateTimevalues provided are within the supported range of their underlying hardware (for example, some chips only support years 2000-2099). - This trait is intended for use in platform implementors and applications needing unified RTC access across hardware targets.
§For driver authors
Drivers should take the Rtc instance as an argument to new(), and store it in their
struct. They should not take &mut Rtc, the trait has a blanket impl for all &mut T
so taking just Rtc ensures the user can still pass a &mut, but is not forced to.
Drivers should not try to enable sharing by taking &mut Rtc at every method.
This is much less ergonomic than owning the Rtc, which still allows the user to pass an
implementation that does sharing behind the scenes.
§Example
ⓘ
use crate::{datetime::DateTime, error::ErrorType, rtc::Rtc};
let mut rtc = Ds1307::new(i2c);
let now = rtc.get_datetime()?;
rtc.set_datetime(&DateTime::new(2024, 8, 16, 12, 0, 0)?)?;Traits§
- Rtc
- Core trait for Real-Time Clock (RTC) devices.