mirror of https://github.com/eldruin/ds323x-rs
Add functions to set/get the day of the month
parent
85c1b6189a
commit
ba5213adf2
|
@ -10,6 +10,7 @@ This driver allows you to:
|
||||||
- Read/write the minutes.
|
- Read/write the minutes.
|
||||||
- Read/write the hours in 24h or AM/PM format.
|
- Read/write the hours in 24h or AM/PM format.
|
||||||
- Read/write the weekday.
|
- Read/write the weekday.
|
||||||
|
- Read/write the day.
|
||||||
|
|
||||||
## The devices
|
## The devices
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,11 @@ where
|
||||||
self.read_register_decimal(Register::DOW)
|
self.read_register_decimal(Register::DOW)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read the day of the month [1-31].
|
||||||
|
pub fn get_day(&mut self) -> Result<u8, Error<E>> {
|
||||||
|
self.read_register_decimal(Register::DOM)
|
||||||
|
}
|
||||||
|
|
||||||
fn read_register_decimal(&mut self, register: u8) -> Result<u8, Error<E>> {
|
fn read_register_decimal(&mut self, register: u8) -> Result<u8, Error<E>> {
|
||||||
let data = self.iface.read_register(register)?;
|
let data = self.iface.read_register(register)?;
|
||||||
Ok(packed_bcd_to_decimal(data))
|
Ok(packed_bcd_to_decimal(data))
|
||||||
|
@ -113,6 +118,16 @@ where
|
||||||
self.iface.write_register(Register::DOW, weekday)
|
self.iface.write_register(Register::DOW, weekday)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set the day of month [1-31].
|
||||||
|
///
|
||||||
|
/// Will return an `Error::InvalidInputData` if the day is out of range.
|
||||||
|
pub fn set_day(&mut self, day: u8) -> Result<(), Error<E>> {
|
||||||
|
if day < 1 || day > 7 {
|
||||||
|
return Err(Error::InvalidInputData);
|
||||||
|
}
|
||||||
|
self.iface.write_register(Register::DOM, day)
|
||||||
|
}
|
||||||
|
|
||||||
fn write_register_decimal(&mut self, register: u8, decimal_number: u8) -> Result<(), Error<E>> {
|
fn write_register_decimal(&mut self, register: u8, decimal_number: u8) -> Result<(), Error<E>> {
|
||||||
self.iface.write_register(register, decimal_to_packed_bcd(decimal_number))
|
self.iface.write_register(register, decimal_to_packed_bcd(decimal_number))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
//! - Read/write the minutes.
|
//! - Read/write the minutes.
|
||||||
//! - Read/write the hours in 24h or AM/PM format.
|
//! - Read/write the hours in 24h or AM/PM format.
|
||||||
//! - Read/write the weekday.
|
//! - Read/write the weekday.
|
||||||
|
//! - Read/write the day.
|
||||||
//!
|
//!
|
||||||
//! ## The devices
|
//! ## The devices
|
||||||
//!
|
//!
|
||||||
|
@ -183,6 +184,7 @@ impl Register {
|
||||||
const MINUTES : u8 = 0x01;
|
const MINUTES : u8 = 0x01;
|
||||||
const HOURS : u8 = 0x02;
|
const HOURS : u8 = 0x02;
|
||||||
const DOW : u8 = 0x03;
|
const DOW : u8 = 0x03;
|
||||||
|
const DOM : u8 = 0x04;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BitFlags;
|
struct BitFlags;
|
||||||
|
|
|
@ -13,6 +13,7 @@ impl Register {
|
||||||
pub const MINUTES : u8 = 0x01;
|
pub const MINUTES : u8 = 0x01;
|
||||||
pub const HOURS : u8 = 0x02;
|
pub const HOURS : u8 = 0x02;
|
||||||
pub const DOW : u8 = 0x03;
|
pub const DOW : u8 = 0x03;
|
||||||
|
pub const DOM : u8 = 0x04;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DummyOutputPin;
|
pub struct DummyOutputPin;
|
||||||
|
|
|
@ -98,3 +98,10 @@ mod weekday {
|
||||||
set_param_test!(set_weekday, DOW, 1, 1);
|
set_param_test!(set_weekday, DOW, 1, 1);
|
||||||
set_invalid_param_range_test!(set_weekday, 0, 8);
|
set_invalid_param_range_test!(set_weekday, 0, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod day {
|
||||||
|
use super::*;
|
||||||
|
get_param_test!(get_day, DOM, 1, 1);
|
||||||
|
set_param_test!(set_day, DOM, 1, 1);
|
||||||
|
set_invalid_param_range_test!(set_day, 0, 8);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue