2020-08-12 15:31:06 +08:00
|
|
|
use embedded_hal::blocking::spi::Transfer;
|
|
|
|
use cortex_m_semihosting::hprintln;
|
|
|
|
use crate::Error;
|
|
|
|
|
2020-08-13 17:17:21 +08:00
|
|
|
construct_bitmask!(CFR1Mask; u32;
|
|
|
|
LSB_FIRST, 0, 1,
|
|
|
|
SDIO_IN_ONLY, 1, 1,
|
|
|
|
EXT_POWER_DOWN_CTRL, 3, 1,
|
|
|
|
AUX_DAC_POWER_DOWN, 4, 1,
|
|
|
|
REFCLK_IN_POWER_DOWN, 5, 1,
|
|
|
|
DAC_POWER_DOWN, 6, 1,
|
|
|
|
DIGITAL_POWER_DOWN, 7, 1,
|
|
|
|
SEL_AUTO_OSK, 8, 1,
|
|
|
|
OSK_ENABLE, 9, 1,
|
|
|
|
LOAD_ARR_IO_UPDATE, 10, 1,
|
|
|
|
CLEAR_PHASE_ACU, 11, 1,
|
|
|
|
CLEAR_DIGITAL_RAMP_ACU, 12, 1,
|
|
|
|
AUTOCLEAR_PHASE_ACU, 13, 1,
|
|
|
|
AUTOCLEAR_DIGITAL_RAMP_ACU, 14, 1,
|
|
|
|
LOAD_LRR_IO_UPDATE, 15, 1,
|
|
|
|
SEL_DDS_SIN_OUT, 16, 1,
|
|
|
|
PROFILE_CTRL, 17, 4,
|
|
|
|
INV_SINC_FILTER_ENABLE, 22, 1,
|
|
|
|
MANUAL_OSK_EXT_CTRL, 23, 1,
|
|
|
|
RAM_PLAYBACK_DST, 29, 2,
|
|
|
|
RAM_ENABLE, 31, 1
|
|
|
|
);
|
|
|
|
|
2020-08-12 15:31:06 +08:00
|
|
|
pub struct DDS<SPI> {
|
|
|
|
spi: SPI,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<SPI, E> DDS<SPI>
|
|
|
|
where
|
|
|
|
SPI: Transfer<u8, Error= E>
|
|
|
|
{
|
|
|
|
pub fn new(spi: SPI) -> Self {
|
|
|
|
DDS {
|
|
|
|
spi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<SPI, E> Transfer<u8> for ConfigRegister<SPI>
|
|
|
|
where
|
|
|
|
SPI: Transfer<u8, Error = E>
|
|
|
|
{
|
|
|
|
type Error = Error<E>;
|
|
|
|
|
|
|
|
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
|
|
|
|
self.spi.transfer(words).map_err(Error::SPI)
|
|
|
|
}
|
|
|
|
}
|