Module rtc

Module rtc 

Source
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 DateTime struct for representing calendar date and time.

§Usage Notes

  • Each RTC driver should implement its own error type conforming to the RtcError trait, allowing accurate hardware-specific error reporting.
  • Drivers are responsible for validating that all DateTime values 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.

§Example

use crate::{datetime::DateTime, error::RtcError, 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.