2个版本
0.1.2 | 2021年10月17日 |
---|---|
0.1.1 |
|
0.1.0 | 2021年4月17日 |
在嵌入式开发类别中排名第513
43KB
591 代码行
Rust PCF8563实时时钟驱动程序
基于embedded-hal
traits的NXP PCF8563实时时钟的跨平台Rust驱动程序。
基于此RTC驱动程序
此驱动程序允许您:
- 读取和设置日期和时间。请参阅:
get_datetime
和set_datetime
- 仅设置时钟应用程序的时间(HH:MM:SS)而不具有日历功能
- 读取和设置闹钟的分钟、小时、日期和星期
- 分别启用闹钟组件
- 分别禁用闹钟组件或全部禁用
- 设置定时器和定时器频率
- 设置时钟输出频率并启用/禁用时钟输出
- 启用和禁用闹钟中断和定时器中断
- 读取和设置其他各种控制功能
待办事项
- 测试其他MCU
- 添加
get_timer_frequency
函数 - 添加
get_timer_interrupt_mode
函数 - 添加
get_clkout_frequency
函数 - 添加nRF示例
设备
PCF8563是一种优化的低功耗CMOS实时时钟(RTC)和日历。还提供了可编程时钟输出、中断输出和电压低检测器。所有地址和数据都通过两线双向I2C总线串行传输。最大总线速度为400 kbit/s。在每次写入或读取数据字节后,寄存器地址会自动增加。
根据32.768 kHz石英晶体提供年、月、日、星期、小时、分钟和秒。
- 世纪标志
- 低备用电流
- 为外围设备提供可编程时钟输出(32.768 kHz、1.024 kHz、32 Hz和1 Hz)
- 闹钟和定时器功能
- 开漏中断引脚
数据手册:PCF8563
用法
要使用此驱动程序,请导入此crate和一个embedded_hal
实现,然后实例化设备。
请在此仓库中查找使用硬件的附加示例:示例
#![no_main]
#![no_std]
use cortex_m;
use cortex_m_rt::entry;
use panic_halt as _;
use stm32l4xx_hal::{
delay::Delay,
prelude::*,
serial::{Config, Serial},
i2c::I2c,
};
use pcf8563::*;
use core::fmt::Write;
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32l4xx_hal::stm32::Peripherals::take().unwrap();
// set up the flash, reset & clock control, and power control
// set up the clocks
// set up GPIO ports
// set up LED for some blinking
// set up USART
// get the delay provider
// set up I2C bus
// set up the PCF8563 device
let mut rtc = PCF8563::new(i2c);
// prepare date and time to be set
let now = DateTime {
year: 21, // 2021
month: 4, // April
weekday: 0, // Sunday
day: 4,
hours: 16,
minutes: 52,
seconds: 00,
};
// set date and time in one go
rtc.set_datetime(&now).unwrap();
loop {
led.set_high().ok();
delay.delay_ms(500 as u32);
//get date and time in one go
let time = rtc.get_datetime().unwrap();
writeln!(tx, "{:02}/{:02}/{:02} {:02}:{:02}:{:02} day {}\r",
time.year, time.month, time.day,
time.hours, time.minutes, time.seconds,
time.weekday).unwrap();
led.set_low().ok();
delay.delay_ms(500 as u32);
}
}
支持
如有问题、问题、功能请求和其他更改,请通过在GitHub项目中提交一个问题。
许可证
许可协议为以下之一:
- Apache许可证,版本2.0(LICENSE-APACHE或https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证(LICENSE-MIT或http://opensource.org/licenses/MIT),您可根据需要选择。
贡献
除非您明确表示,否则您根据Apache-2.0许可证定义,有意提交以包含在工作中的任何贡献,都将按照上述方式双重许可,不附加任何额外条款或条件。
依赖关系
~71KB