From 49594dfb3b8dbe1b1aa5ed0f2e31c7af1beac3bf Mon Sep 17 00:00:00 2001 From: occheung Date: Mon, 31 Aug 2020 11:36:05 +0800 Subject: [PATCH] urukul: very bad constructor --- src/lib.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1e0b61e..74c676f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,13 @@ #![no_std] extern crate embedded_hal; - -use core::cell; +use embedded_hal::{ + digital::v2::OutputPin, + blocking::spi::Transfer, +}; +use core::{ + cell, + marker::PhantomData, +}; use cortex_m; use cortex_m_semihosting::hprintln; @@ -10,13 +16,23 @@ use cortex_m_semihosting::hprintln; pub mod bitmask_macro; pub mod spi_slave; -use crate::spi_slave::Parts; +// use crate::spi_slave::{ +// Parts, +// SPISlave, +// }; pub mod cpld; +use crate::cpld::CPLD; 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; /* @@ -31,3 +47,39 @@ pub enum Error { IOUpdateError, DDSError, } + +/* + * Struct for Urukul master device + */ +pub struct Urukul { + config_register: ConfigRegister, + attenuator: Attenuator, + dds: [DDS; 4], +} + +impl Urukul +where + SPI: Transfer, +{ + /* + * Master constructor for the entire Urukul device + */ + pub fn new(spi1: SPI, spi2: SPI, spi3: SPI, spi4: SPI, spi5: SPI, spi6: SPI, spi7: SPI, f_ref_clks: [u64; 4]) -> Self { + // Construct cpld and get parts + // let switch = CPLD::new(spi, chip_select, io_update); + // let parts = switch.split(); + + // 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]), + ], + // _phantom: PhantomData, + } + } +} \ No newline at end of file