mirror of https://github.com/eldruin/ds323x-rs
Fix clippy warnings
parent
a657eec8d6
commit
1930de500d
|
@ -132,8 +132,8 @@ fn get_matching_mask_alarm2(matching: Alarm2Matching) -> [u8; 3] {
|
||||||
fn is_hour_valid(hours: Hours) -> bool {
|
fn is_hour_valid(hours: Hours) -> bool {
|
||||||
match hours {
|
match hours {
|
||||||
Hours::H24(h) if h > 23 => true,
|
Hours::H24(h) if h > 23 => true,
|
||||||
Hours::AM(h) if h < 1 || h > 12 => true,
|
Hours::AM(h) if !(1..=12).contains(&h) => true,
|
||||||
Hours::PM(h) if h < 1 || h > 12 => true,
|
Hours::PM(h) if !(1..=12).contains(&h) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,9 +143,9 @@ fn amend_hour(hours: Hours) -> Hours {
|
||||||
match hours {
|
match hours {
|
||||||
Hours::H24(h) if h > 23 => Hours::H24(0),
|
Hours::H24(h) if h > 23 => Hours::H24(0),
|
||||||
Hours::H24(h) => Hours::H24(h),
|
Hours::H24(h) => Hours::H24(h),
|
||||||
Hours::AM(h) if h < 1 || h > 12 => Hours::AM(1),
|
Hours::AM(h) if !(1..=12).contains(&h) => Hours::AM(1),
|
||||||
Hours::AM(h) => Hours::AM(h),
|
Hours::AM(h) => Hours::AM(h),
|
||||||
Hours::PM(h) if h < 1 || h > 12 => Hours::PM(1),
|
Hours::PM(h) if !(1..=12).contains(&h) => Hours::PM(1),
|
||||||
Hours::PM(h) => Hours::PM(h),
|
Hours::PM(h) => Hours::PM(h),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,21 +127,21 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_weekday(&mut self, weekday: u8) -> Result<(), Self::Error> {
|
fn set_weekday(&mut self, weekday: u8) -> Result<(), Self::Error> {
|
||||||
if weekday < 1 || weekday > 7 {
|
if !(1..=7).contains(&weekday) {
|
||||||
return Err(Error::InvalidInputData);
|
return Err(Error::InvalidInputData);
|
||||||
}
|
}
|
||||||
self.iface.write_register(Register::DOW, weekday)
|
self.iface.write_register(Register::DOW, weekday)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_day(&mut self, day: u8) -> Result<(), Self::Error> {
|
fn set_day(&mut self, day: u8) -> Result<(), Self::Error> {
|
||||||
if day < 1 || day > 31 {
|
if !(1..=31).contains(&day) {
|
||||||
return Err(Error::InvalidInputData);
|
return Err(Error::InvalidInputData);
|
||||||
}
|
}
|
||||||
self.iface.write_register(Register::DOM, day)
|
self.iface.write_register(Register::DOM, day)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_month(&mut self, month: u8) -> Result<(), Self::Error> {
|
fn set_month(&mut self, month: u8) -> Result<(), Self::Error> {
|
||||||
if month < 1 || month > 12 {
|
if !(1..=12).contains(&month) {
|
||||||
return Err(Error::InvalidInputData);
|
return Err(Error::InvalidInputData);
|
||||||
}
|
}
|
||||||
// keep the century bit
|
// keep the century bit
|
||||||
|
@ -151,7 +151,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_year(&mut self, year: u16) -> Result<(), Self::Error> {
|
fn set_year(&mut self, year: u16) -> Result<(), Self::Error> {
|
||||||
if year < 2000 || year > 2100 {
|
if !(2000..=2100).contains(&year) {
|
||||||
return Err(Error::InvalidInputData);
|
return Err(Error::InvalidInputData);
|
||||||
}
|
}
|
||||||
let data = self.iface.read_register(Register::MONTH)?;
|
let data = self.iface.read_register(Register::MONTH)?;
|
||||||
|
|
|
@ -21,9 +21,9 @@ fn hours_to_register<CommE, PinE>(hours: Hours) -> Result<u8, Error<CommE, PinE>
|
||||||
match hours {
|
match hours {
|
||||||
Hours::H24(h) if h > 23 => Err(Error::InvalidInputData),
|
Hours::H24(h) if h > 23 => Err(Error::InvalidInputData),
|
||||||
Hours::H24(h) => Ok(decimal_to_packed_bcd(h)),
|
Hours::H24(h) => Ok(decimal_to_packed_bcd(h)),
|
||||||
Hours::AM(h) if h < 1 || h > 12 => Err(Error::InvalidInputData),
|
Hours::AM(h) if !(1..=12).contains(&h) => Err(Error::InvalidInputData),
|
||||||
Hours::AM(h) => Ok(BitFlags::H24_H12 | decimal_to_packed_bcd(h)),
|
Hours::AM(h) => Ok(BitFlags::H24_H12 | decimal_to_packed_bcd(h)),
|
||||||
Hours::PM(h) if h < 1 || h > 12 => Err(Error::InvalidInputData),
|
Hours::PM(h) if !(1..=12).contains(&h) => Err(Error::InvalidInputData),
|
||||||
Hours::PM(h) => Ok(BitFlags::H24_H12 | BitFlags::AM_PM | decimal_to_packed_bcd(h)),
|
Hours::PM(h) => Ok(BitFlags::H24_H12 | BitFlags::AM_PM | decimal_to_packed_bcd(h)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> {
|
fn write_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> {
|
||||||
self.i2c
|
self.i2c.write(DEVICE_ADDRESS, payload).map_err(Error::Comm)
|
||||||
.write(DEVICE_ADDRESS, &payload)
|
|
||||||
.map_err(Error::Comm)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +65,7 @@ where
|
||||||
fn write_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> {
|
fn write_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> {
|
||||||
self.cs.set_low().map_err(Error::Pin)?;
|
self.cs.set_low().map_err(Error::Pin)?;
|
||||||
payload[0] += 0x80;
|
payload[0] += 0x80;
|
||||||
let result = self.spi.write(&payload).map_err(Error::Comm);
|
let result = self.spi.write(payload).map_err(Error::Comm);
|
||||||
|
|
||||||
self.cs.set_high().map_err(Error::Pin)?;
|
self.cs.set_high().map_err(Error::Pin)?;
|
||||||
result
|
result
|
||||||
|
@ -119,9 +117,9 @@ where
|
||||||
Ok(result?[1])
|
Ok(result?[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_data(&mut self, mut payload: &mut [u8]) -> Result<(), Self::Error> {
|
fn read_data(&mut self, payload: &mut [u8]) -> Result<(), Self::Error> {
|
||||||
self.cs.set_low().map_err(Error::Pin)?;
|
self.cs.set_low().map_err(Error::Pin)?;
|
||||||
let result = self.spi.transfer(&mut payload).map_err(Error::Comm);
|
let result = self.spi.transfer(payload).map_err(Error::Comm);
|
||||||
self.cs.set_high().map_err(Error::Pin)?;
|
self.cs.set_high().map_err(Error::Pin)?;
|
||||||
result?;
|
result?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use ds323x::Ds323x;
|
//! use ds323x::Ds323x;
|
||||||
//! use linux_embedded_hal::{Pin, Spidev};
|
//! use linux_embedded_hal::{SysfsPin as Pin, Spidev};
|
||||||
//!
|
//!
|
||||||
//! let dev = Spidev::open("/dev/spidev0.0").unwrap();
|
//! let dev = Spidev::open("/dev/spidev0.0").unwrap();
|
||||||
//! let chip_select = Pin::new(24);
|
//! let chip_select = Pin::new(24);
|
||||||
|
|
Loading…
Reference in New Issue