Crates.io | mcp794xx |
lib.rs | mcp794xx |
version | 0.3.0 |
source | src |
created_at | 2019-09-15 12:13:55.014554 |
updated_at | 2022-08-16 12:00:10.545213 |
description | Platform-agnostic Rust driver for the MCP794xx real-time clock / calendar (RTC) family. Compatible with MCP7940N, MCP7940M, MCP79400, MCP79401, MCP79402, MCP79410, MCP79411 and MCP79412. |
homepage | https://github.com/eldruin/mcp794xx-rs |
repository | https://github.com/eldruin/mcp794xx-rs |
max_upload_size | |
id | 164891 |
size | 133,633 |
This is a platform agnostic Rust driver for the MCP794xx real-time clock
/ calendar family, based on the embedded-hal
traits.
This driver allows you to:
datetime()
.date()
.time()
.year()
.enable()
.is_oscillator_running()
.is_leap_year()
.set_output_pin()
.enable_coarse_trim()
.set_trimming()
.has_power_failed()
.clear_power_failed()
.get_power_down_datetime()
.get_power_up_datetime()
.enable_backup_battery_power()
.read_sram_byte()
.read_sram_data()
.read_sram_current_byte()
.enable_alarm()
.set_alarm
.has_alarm_matched
.clear_alarm_matched_flag
.enable_square_wave
.set_square_wave_frequency
.read_protected_eeprom_byte()
.read_protected_eeprom_data()
.read_eui48()
.read_eui64()
.read_eeprom_byte()
.read_eeprom_data()
.set_eeprom_write_protection()
.read_eeprom_current_byte()
.This driver is compatible with the devices: MCP7940N, MCP7940M, MCP79400, MCP79401, MCP79402, MCP79410, MCP79411 and MCP79412.
The Real-Time Clock/Calendar (RTCC) tracks time using internal counters for hours, minutes, seconds, days, months, years, and day of week. Alarms can be configured on all counters up to and including months. For usage and configuration, the devices support I2C communications up to 400 kHz.
The open-drain, multi-functional output can be configured to assert on an alarm match, to output a selectable frequency square wave, or as a general purpose output.
The devices are designed to operate using a 32.768 kHz tuning fork crystal with external crystal load capacitors. On-chip digital trimming can be used to adjust for frequency variance caused by crystal tolerance and temperature.
SRAM and timekeeping circuitry are powered from the back-up supply when main power is lost, allowing the device to maintain accurate time and the SRAM contents. The times when the device switches over to the back-up supply and when primary power returns are both logged by the power-fail time-stamp.
Some of the devices feature 1 Kbit of internal non-volatile EEPROM with software write-protectable regions. There is an additional 64 bits of protected non-volatile memory which is only writable after an unlock sequence, making it ideal for storing a unique ID or other critical information.
Some of the devices offer a pre-programmed with EUI-48 and EUI-64 addresses. Custom programming is also available.
Datasheets:
To use this driver, import this crate and an embedded_hal
implementation,
then instantiate the appropriate device.
In the following example an instance of the device MCP7940N will be created.
Other devices can be created with similar methods like:
Mcp794xx::new_mcp79400(...)
.
Please find additional examples using hardware in this repository: driver-examples
use linux_embedded_hal::I2cdev;
use mcp794xx::{DateTimeAccess, Mcp794xx, NaiveDate, Rtcc};
fn main() {
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let mut rtc = Mcp794xx::new_mcp7940n(dev);
rtc.enable().unwrap();
let datetime = NaiveDate::from_ymd(2018, 8, 20).and_hms(19, 59, 58);
rtc.set_datetime(&datetime).unwrap();
rtc.enable().unwrap();
// do something else...
let seconds = rtc.seconds().unwrap();
println!("Seconds: {}", seconds);
let _dev = rtc.destroy();
}
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.