urukul: very bad constructor

This commit is contained in:
occheung 2020-08-31 11:36:05 +08:00
parent 69761c4517
commit 49594dfb3b
1 changed files with 55 additions and 3 deletions

View File

@ -1,7 +1,13 @@
#![no_std] #![no_std]
extern crate embedded_hal; extern crate embedded_hal;
use embedded_hal::{
use core::cell; digital::v2::OutputPin,
blocking::spi::Transfer,
};
use core::{
cell,
marker::PhantomData,
};
use cortex_m; use cortex_m;
use cortex_m_semihosting::hprintln; use cortex_m_semihosting::hprintln;
@ -10,13 +16,23 @@ use cortex_m_semihosting::hprintln;
pub mod bitmask_macro; pub mod bitmask_macro;
pub mod spi_slave; pub mod spi_slave;
use crate::spi_slave::Parts; // use crate::spi_slave::{
// Parts,
// SPISlave,
// };
pub mod cpld; pub mod cpld;
use crate::cpld::CPLD;
pub mod config_register; pub mod config_register;
use crate::config_register::ConfigRegister;
pub mod attenuator; pub mod attenuator;
use crate::attenuator::Attenuator;
pub mod dds; pub mod dds;
use crate::dds::DDS;
pub mod scpi; pub mod scpi;
/* /*
@ -31,3 +47,39 @@ pub enum Error<E> {
IOUpdateError, IOUpdateError,
DDSError, 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
*/
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,
}
}
}