Crates.io | ds1307 |
lib.rs | ds1307 |
version | 0.6.0 |
source | src |
created_at | 2018-08-15 17:21:15.529076 |
updated_at | 2024-02-01 08:38:41.595753 |
description | Platform-agnostic Rust driver for the DS1307 real-time clock. |
homepage | https://github.com/eldruin/ds1307-rs |
repository | https://github.com/eldruin/ds1307-rs |
max_upload_size | |
id | 79608 |
size | 70,675 |
This is a platform agnostic Rust driver for the DS1307 real-time clock,
based on the embedded-hal
traits.
This driver allows you to:
datetime
set_running
read_ram
enable_square_wave_output
The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus.
The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator.
The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply.
Datasheet: DS1307
To use this driver, import this crate and an embedded_hal
implementation,
then instantiate the device.
Please find additional examples using hardware in this repository: driver-examples
use ds1307::{DateTimeAccess, Ds1307, NaiveDate};
use linux_embedded_hal::I2cdev;
fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut rtc = Ds1307::new(dev);
let datetime = NaiveDate::from_ymd_opt(2022, 1, 2)
.unwrap()
.and_hms_opt(19, 59, 58)
.unwrap();
rtc.set_datetime(&datetime).unwrap();
// ...
let datetime = rtc.datetime().unwrap();
println!("{datetime}");
// This will print something like: 2022-01-02 19:59:58
}
This crate is guaranteed to compile on stable Rust 1.62 and up. It might compile with older versions but that may change in any new patch release.
For questions, issues, feature requests, and other changes, please file an issue in the github project.
Licensed under either of
at your option.
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.