Adding WIP refactor
This commit is contained in:
parent
84167c7f6f
commit
055c92c684
@ -549,3 +549,64 @@ impl<I: Interface> Ad9959<I> {
|
|||||||
Ok(serialized)
|
Ok(serialized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ProfileSerializer {
|
||||||
|
data: [u8; 16],
|
||||||
|
index: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ProfileSerializer {
|
||||||
|
fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
data: [0; 16],
|
||||||
|
index: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_write(&mut self, register: Register, value: &[u8]) {
|
||||||
|
let data = &mut self.data[self.index..];
|
||||||
|
assert!(value.len() + 1 <= data.len());
|
||||||
|
|
||||||
|
data[0] = register as u8;
|
||||||
|
data[1..][..value.len()].copy_from_slice(value);
|
||||||
|
self.index += value.len() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn finalize(self) -> [u32; 4] {
|
||||||
|
assert!(self.index == self.data.len());
|
||||||
|
unsafe { core::mem::transmute(self.data) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn serialize_profile(channel: Channel, ftw: u32, pow: u16, acr: Option<u16>) -> [u32; 4] {
|
||||||
|
let mut serializer = ProfileSerializer::new();
|
||||||
|
|
||||||
|
let csr: u8 = *0x00_u8
|
||||||
|
.set_bits(1..=2, Mode::FourBitSerial as u8)
|
||||||
|
.set_bit(4 + channel as usize, true);
|
||||||
|
|
||||||
|
let acr: [u8; 3] = {
|
||||||
|
let mut data = [0u8; 3];
|
||||||
|
if acr.is_some() {
|
||||||
|
data[2].set_bit(0, acr.is_some());
|
||||||
|
data[0..2].copy_from_slice(&acr.unwrap().to_be_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
data
|
||||||
|
};
|
||||||
|
|
||||||
|
// 4 bytes
|
||||||
|
serializer.add_write(Register::CSR, &[csr]);
|
||||||
|
serializer.add_write(Register::CSR, &[csr]);
|
||||||
|
|
||||||
|
// 5 bytes
|
||||||
|
serializer.add_write(Register::CFTW0, &ftw.to_be_bytes());
|
||||||
|
|
||||||
|
// 3 bytes
|
||||||
|
serializer.add_write(Register::CPOW0, &pow.to_be_bytes());
|
||||||
|
|
||||||
|
// 4 bytes
|
||||||
|
serializer.add_write(Register::ACR, &acr);
|
||||||
|
|
||||||
|
serializer.finalize()
|
||||||
|
}
|
||||||
|
21
src/main.rs
21
src/main.rs
@ -821,18 +821,15 @@ const APP: () = {
|
|||||||
y1 as i16 as u16 ^ 0x8000
|
y1 as i16 as u16 ^ 0x8000
|
||||||
};
|
};
|
||||||
|
|
||||||
let dds_output = &mut c.resources.dds_output;
|
if c.resources.pounder.is_some() {
|
||||||
if let Some(pounder) = c.resources.pounder {
|
let profile = ad9959::serialize_profile(
|
||||||
let profile = pounder
|
pounder::Channel::Out0.into(),
|
||||||
.ad9959
|
u32::MAX / 4,
|
||||||
.serialize_profile(
|
0,
|
||||||
pounder::Channel::Out0.into(),
|
None,
|
||||||
100_000_000_f32,
|
);
|
||||||
0.0_f32,
|
|
||||||
1.0_f32,
|
c.resources.dds_output.lock(|dds_output| {
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
dds_output.lock(|dds_output| {
|
|
||||||
dds_output.push(profile);
|
dds_output.push(profile);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ impl DdsOutput {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
timer.pause();
|
timer.pause();
|
||||||
timer.reset_counter();
|
timer.reset_counter();
|
||||||
|
timer.clear_uif_bit();
|
||||||
timer.listen(hal::timer::Event::TimeOut);
|
timer.listen(hal::timer::Event::TimeOut);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
Loading…
Reference in New Issue
Block a user