forked from M-Labs/humpback-dds
134 lines
3.6 KiB
Rust
134 lines
3.6 KiB
Rust
#![no_std]
|
|
extern crate embedded_hal;
|
|
use embedded_hal::{
|
|
digital::v2::OutputPin,
|
|
blocking::spi::Transfer,
|
|
};
|
|
use core::{
|
|
cell,
|
|
marker::PhantomData,
|
|
};
|
|
use cortex_m;
|
|
use cortex_m_semihosting::hprintln;
|
|
|
|
#[macro_use]
|
|
pub mod bitmask_macro;
|
|
|
|
pub mod spi_slave;
|
|
use crate::spi_slave::{
|
|
Parts,
|
|
SPISlave,
|
|
};
|
|
|
|
pub mod cpld;
|
|
use crate::cpld::CPLD;
|
|
use crate::cpld::DoOnGetRefMutData;
|
|
|
|
pub mod config_register;
|
|
use crate::config_register::ConfigRegister;
|
|
|
|
pub mod attenuator;
|
|
use crate::attenuator::Attenuator;
|
|
|
|
pub mod dds;
|
|
use crate::dds::DDS;
|
|
|
|
pub mod scpi;
|
|
|
|
/*
|
|
* Enum for structuring error
|
|
*/
|
|
#[derive(Debug)]
|
|
pub enum Error<E> {
|
|
SPI(E),
|
|
CSError,
|
|
GetRefMutDataError,
|
|
AttenuatorError,
|
|
IOUpdateError,
|
|
DDSError,
|
|
}
|
|
|
|
/*
|
|
* Struct for Urukul master device
|
|
*/
|
|
pub struct Urukul<SPI> {
|
|
config_register: ConfigRegister<SPI>,
|
|
attenuator: Attenuator<SPI>,
|
|
dds: [DDS<SPI>; 4],
|
|
}
|
|
|
|
impl<SPI, E> Urukul<SPI>
|
|
where
|
|
SPI: Transfer<u8, Error = E>,
|
|
{
|
|
/*
|
|
* Master constructor for the entire Urukul device
|
|
* Supply 7 SPI channels to Urukul and 4 reference clock frequencies
|
|
*/
|
|
pub fn new(spi1: SPI, spi2: SPI, spi3: SPI, spi4: SPI, spi5: SPI, spi6: SPI, spi7: SPI, f_ref_clks: [u64; 4]) -> Self {
|
|
// Construct Urukul
|
|
Urukul {
|
|
config_register: ConfigRegister::new(spi1),
|
|
attenuator: Attenuator::new(spi2),
|
|
dds: [
|
|
DDS::new(spi4, f_ref_clks[1]),
|
|
DDS::new(spi5, f_ref_clks[1]),
|
|
DDS::new(spi6, f_ref_clks[2]),
|
|
DDS::new(spi7, f_ref_clks[3]),
|
|
],
|
|
}
|
|
}
|
|
}
|
|
|
|
// /*
|
|
// * Struct for a better Urukul master device
|
|
// */
|
|
// pub struct BetterUrukul<'a, SPI, CS0, CS1, CS2, GPIO> {
|
|
// cpld: CPLD<SPI, CS0, CS1, CS2, GPIO>,
|
|
// parts: Option<Parts<'a, CPLD<SPI, CS0, CS1, CS2, GPIO>, SPI, CS0, CS1, CS2, GPIO>>,
|
|
// config_register: Option<ConfigRegister<SPISlave<'a, CPLD<SPI, CS0, CS1, CS2, GPIO>, SPI, CS0, CS1, CS2, GPIO>>>,
|
|
// attenuator: Option<Attenuator<SPISlave<'a, CPLD<SPI, CS0, CS1, CS2, GPIO>, SPI, CS0, CS1, CS2, GPIO>>>,
|
|
// dds: [Option<DDS<SPISlave<'a, CPLD<SPI, CS0, CS1, CS2, GPIO>, SPI, CS0, CS1, CS2, GPIO>>>; 4],
|
|
// }
|
|
|
|
// impl<'a, SPI, CS0, CS1, CS2, GPIO> BetterUrukul<'a, SPI, CS0, CS1, CS2, GPIO>
|
|
// where
|
|
// SPI: Transfer<u8>,
|
|
// CS0: OutputPin,
|
|
// CS1: OutputPin,
|
|
// CS2: OutputPin,
|
|
// GPIO: OutputPin,
|
|
// {
|
|
// pub fn new(spi: SPI, chip_select: (CS0, CS1, CS2), io_update: GPIO) -> Self {
|
|
// // let switch = CPLD::new(spi, chip_select, io_update);
|
|
// // let parts = switch.split();
|
|
|
|
// // Construct Urukul
|
|
// BetterUrukul {
|
|
// cpld: CPLD::new(spi, chip_select, io_update),
|
|
// // parts: CPLD::new(spi, chip_select, io_update).split(),
|
|
// // config_register: ConfigRegister::new(self.parts.spi1),
|
|
// // attenuator: Attenuator::new(self.parts.spi2),
|
|
// // dds: [
|
|
// // DDS::new(self.parts.spi4, f_ref_clks[1]),
|
|
// // DDS::new(self.parts.spi5, f_ref_clks[1]),
|
|
// // DDS::new(self.parts.spi6, f_ref_clks[2]),
|
|
// // DDS::new(self.parts.spi7, f_ref_clks[3]),
|
|
// // ],
|
|
// parts: None,
|
|
// config_register: None,
|
|
// attenuator: None,
|
|
// dds: [None, None, None, None],
|
|
// }
|
|
// }
|
|
|
|
// pub fn init(&'a mut self, f_ref_clks:[u64; 4]) {
|
|
// self.parts = Some(self.cpld.split());
|
|
// self.config_register = Some(ConfigRegister::new(self.parts.unwrap().spi1));
|
|
// self.attenuator = Some(Attenuator::new(self.parts.unwrap().spi2));
|
|
// self.dds[0] = Some(DDS::new(self.parts.unwrap().spi4, f_ref_clks[0]));
|
|
// self.dds[1] = Some(DDS::new(self.parts.unwrap().spi5, f_ref_clks[1]));
|
|
// self.dds[2] = Some(DDS::new(self.parts.unwrap().spi6, f_ref_clks[2]));
|
|
// self.dds[3] = Some(DDS::new(self.parts.unwrap().spi7, f_ref_clks[3]));
|
|
// }
|
|
// }
|