#![cfg_attr(not(any(test, feature = "std")), no_std)]
#[macro_use]
pub(crate) mod fmt;
use thiserror::Error;
device_driver::create_device!(device_name: Pcf8563LowLevel, manifest: "device.yaml");
pub const PCF8563_I2C_ADDR: u8 = 0x51;
#[derive(Debug, Error)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum RtcError<I2cErr> {
#[error("I2C error")]
I2c(I2cErr),
#[error("Invalid input data")]
InvalidInputData,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DateTime {
pub year: u8,
pub month: u8,
pub day: u8,
pub weekday: u8,
pub hours: u8,
pub minutes: u8,
pub seconds: u8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Time {
pub hours: u8,
pub minutes: u8,
pub seconds: u8,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Alarm {
pub minute: Option<u8>,
pub hour: Option<u8>,
pub day: Option<u8>,
pub weekday: Option<u8>,
}
pub struct Pcf8563Interface<I2CBus> {
i2c_bus: I2CBus,
}
impl<I2CBus> Pcf8563Interface<I2CBus> {
pub fn new(i2c_bus: I2CBus) -> Self {
Self { i2c_bus }
}
}
#[path = "."]
mod asynchronous {
use bisync::asynchronous::*;
use device_driver::AsyncRegisterInterface as RegisterInterface;
use embedded_hal_async::i2c::I2c;
mod driver;
pub use driver::*;
}
pub use asynchronous::Pcf8563 as Pcf8563Async;
#[path = "."]
mod blocking {
use bisync::synchronous::*;
use device_driver::RegisterInterface;
use embedded_hal::i2c::I2c;
#[allow(clippy::duplicate_mod)]
mod driver;
pub use driver::*;
}
pub use blocking::Pcf8563;
#[inline]
pub(crate) fn bcd_to_dec(bcd: u8) -> u8 {
(bcd & 0x0F) + ((bcd >> 4) * 10)
}
#[inline]
pub(crate) fn dec_to_bcd(dec: u8) -> u8 {
((dec / 10) << 4) | (dec % 10)
}