DS3231 Real-Time Clock Driver
A platform-agnostic Rust driver for the DS3231 Real-Time Clock, built on the embedded-hal ecosystem.
The DS3231 is a low-cost, extremely accurate I²C real-time clock (RTC) with an integrated
temperature-compensated crystal oscillator (TCXO).
- Both blocking and async I²C operation support
- Full register access (time/date, alarms, control, status)
- Optional logging support via
logordefmt - No
unsafecode - Comprehensive error handling
Usage
Add this to your Cargo.toml:
[]
= "0.3.0"
Blocking Example
use ;
// Create configuration
let config = Config ;
// Initialize device with I2C
let mut rtc = DS3231new;
// Configure the device
rtc.configure?;
// Get current date/time
let datetime = rtc.datetime?;
Async Example
Enable the async feature in your Cargo.toml and use with async/await:
use DS3231;
// Initialize device
let mut rtc = DS3231new;
// Configure asynchronously
rtc.configure.await?;
// Get current date/time asynchronously
let datetime = rtc.datetime.await?;
Features
The crate can be compiled with the following features:
async: Enables async I²C supportlog: Enables logging via thelogcratedefmt: Enables logging via thedefmtcratetemperature_f32- Enables temperature reading as f32
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.