dds: strictly enforce ~lsb_first and sdio_input_only

This commit is contained in:
occheung 2020-09-30 15:57:06 +08:00
parent 9d49afa5a8
commit b577c8b715

View File

@ -335,7 +335,7 @@ where
pub fn set_configurations(&mut self, mask_pairs: &mut[(DDSCFRMask, u32)]) -> Result<(), Error<E>> {
let mut data_array = self.get_all_configurations()?;
for index in 0..mask_pairs.len() {
// Reject any attempt to rewrite LSB_FIRST and SBIO_INPUT_ONLY
// Reject any attempt to rewrite LSB_FIRST and SDIO_INPUT_ONLY
if mask_pairs[index].0 == DDSCFRMask::LSB_FIRST || mask_pairs[index].0 == DDSCFRMask::SDIO_IN_ONLY {
continue;
}
@ -346,6 +346,9 @@ where
_ => panic!("Invalid DDSCFRMask!"),
};
}
// Deterministically maintain LSB_FIRST and SDIO_INPUT_ONLY
DDSCFRMask::LSB_FIRST.set_data_by_arg(&mut data_array[0], 0);
DDSCFRMask::SDIO_IN_ONLY.set_data_by_arg(&mut data_array[0], 1);
self.set_all_configurations(data_array.clone())
}
@ -862,7 +865,9 @@ macro_rules! impl_register_io {
}
self.spi.transfer(&mut arr)
.map(|_| ())
.map_err(Error::SPI)
.map_err(Error::SPI)?;
debug!("Write register: {:X}, Bytes: {:X?}", addr, bytes);
Ok(())
},
)*
_ => panic!("Bad address for DDS writing.")
@ -885,7 +890,9 @@ macro_rules! impl_register_io {
Ok(bytes)
},
Err(e) => Err(e),
}
};
debug!("Read register: {:X}, Bytes: {:X?}", addr, bytes);
Ok(bytes)
},
)*
_ => panic!("Bad address for DDS reading.")