Formatting

This commit is contained in:
Ryan Summers 2020-11-03 09:41:45 +01:00
parent adaca88a50
commit 4e5459433e
4 changed files with 76 additions and 49 deletions

1
Cargo.lock generated
View File

@ -567,6 +567,7 @@ dependencies = [
[[package]] [[package]]
name = "stm32h7xx-hal" name = "stm32h7xx-hal"
version = "0.8.0" version = "0.8.0"
source = "git+https://github.com/quartiq/stm32h7xx-hal?branch=feature/stabilizer-dma#5fbbfa9352f720994c210e5c21601f3acf9dc40c"
dependencies = [ dependencies = [
"bare-metal 1.0.0", "bare-metal 1.0.0",
"cast", "cast",

View File

@ -1,5 +1,7 @@
use super::{hal, DmaConfig, PeripheralToMemory, MemoryToPeripheral, TargetAddress, Transfer, DMAReq, use super::{
Stream}; hal, DMAReq, DmaConfig, MemoryToPeripheral, PeripheralToMemory, Stream,
TargetAddress, Transfer,
};
const INPUT_BUFFER_SIZE: usize = 1; const INPUT_BUFFER_SIZE: usize = 1;
@ -62,7 +64,8 @@ pub struct Adc0Input {
hal::dma::dma::Stream1<hal::stm32::DMA1>, hal::dma::dma::Stream1<hal::stm32::DMA1>,
hal::spi::Spi<hal::stm32::SPI2, hal::spi::Disabled, u16>, hal::spi::Spi<hal::stm32::SPI2, hal::spi::Disabled, u16>,
PeripheralToMemory, PeripheralToMemory,
&'static mut [u16; INPUT_BUFFER_SIZE]>, &'static mut [u16; INPUT_BUFFER_SIZE],
>,
} }
impl Adc0Input { impl Adc0Input {
@ -76,12 +79,14 @@ impl Adc0Input {
.peripheral_increment(false) .peripheral_increment(false)
.circular_buffer(true); .circular_buffer(true);
let mut trigger_transfer: Transfer<_, _, MemoryToPeripheral, _ > = Transfer::init( let mut trigger_transfer: Transfer<_, _, MemoryToPeripheral, _> =
Transfer::init(
trigger_stream, trigger_stream,
&SPI2::new(), &SPI2::new(),
unsafe { &mut SPI_START }, unsafe { &mut SPI_START },
None, None,
trigger_config); trigger_config,
);
let data_config = DmaConfig::default() let data_config = DmaConfig::default()
.memory_increment(true) .memory_increment(true)
@ -91,12 +96,14 @@ impl Adc0Input {
let mut spi = spi.disable(); let mut spi = spi.disable();
spi.listen(hal::spi::Event::Error); spi.listen(hal::spi::Event::Error);
let mut data_transfer: Transfer<_, _, PeripheralToMemory, _ > = Transfer::init( let mut data_transfer: Transfer<_, _, PeripheralToMemory, _> =
Transfer::init(
data_stream, data_stream,
&spi, &spi,
unsafe { &mut ADC0_BUF0 }, unsafe { &mut ADC0_BUF0 },
None, None,
data_config); data_config,
);
spi.enable_dma_rx(); spi.enable_dma_rx();
spi.enable_dma_tx(); spi.enable_dma_tx();
@ -115,7 +122,8 @@ impl Adc0Input {
pub fn transfer_complete_handler(&mut self) -> &[u16; INPUT_BUFFER_SIZE] { pub fn transfer_complete_handler(&mut self) -> &[u16; INPUT_BUFFER_SIZE] {
let next_buffer = self.next_buffer.take().unwrap(); let next_buffer = self.next_buffer.take().unwrap();
let (prev_buffer, _) = self.transfer.next_transfer(next_buffer).unwrap(); let (prev_buffer, _) =
self.transfer.next_transfer(next_buffer).unwrap();
self.next_buffer.replace(prev_buffer); self.next_buffer.replace(prev_buffer);
self.next_buffer.as_ref().unwrap() self.next_buffer.as_ref().unwrap()
} }
@ -127,7 +135,8 @@ pub struct Adc1Input {
hal::dma::dma::Stream3<hal::stm32::DMA1>, hal::dma::dma::Stream3<hal::stm32::DMA1>,
hal::spi::Spi<hal::stm32::SPI3, hal::spi::Disabled, u16>, hal::spi::Spi<hal::stm32::SPI3, hal::spi::Disabled, u16>,
PeripheralToMemory, PeripheralToMemory,
&'static mut [u16; INPUT_BUFFER_SIZE]>, &'static mut [u16; INPUT_BUFFER_SIZE],
>,
} }
impl Adc1Input { impl Adc1Input {
@ -141,12 +150,14 @@ impl Adc1Input {
.peripheral_increment(false) .peripheral_increment(false)
.circular_buffer(true); .circular_buffer(true);
let mut trigger_transfer: Transfer<_, _, MemoryToPeripheral, _ > = Transfer::init( let mut trigger_transfer: Transfer<_, _, MemoryToPeripheral, _> =
Transfer::init(
trigger_stream, trigger_stream,
&SPI3::new(), &SPI3::new(),
unsafe { &mut SPI_START }, unsafe { &mut SPI_START },
None, None,
trigger_config); trigger_config,
);
let data_config = DmaConfig::default() let data_config = DmaConfig::default()
.memory_increment(true) .memory_increment(true)
@ -156,12 +167,14 @@ impl Adc1Input {
let mut spi = spi.disable(); let mut spi = spi.disable();
spi.listen(hal::spi::Event::Error); spi.listen(hal::spi::Event::Error);
let mut data_transfer: Transfer<_, _, PeripheralToMemory, _ > = Transfer::init( let mut data_transfer: Transfer<_, _, PeripheralToMemory, _> =
Transfer::init(
data_stream, data_stream,
&spi, &spi,
unsafe { &mut ADC1_BUF0 }, unsafe { &mut ADC1_BUF0 },
None, None,
data_config); data_config,
);
spi.enable_dma_rx(); spi.enable_dma_rx();
spi.enable_dma_tx(); spi.enable_dma_tx();
@ -180,7 +193,8 @@ impl Adc1Input {
pub fn transfer_complete_handler(&mut self) -> &[u16; INPUT_BUFFER_SIZE] { pub fn transfer_complete_handler(&mut self) -> &[u16; INPUT_BUFFER_SIZE] {
let next_buffer = self.next_buffer.take().unwrap(); let next_buffer = self.next_buffer.take().unwrap();
let (prev_buffer, _) = self.transfer.next_transfer(next_buffer).unwrap(); let (prev_buffer, _) =
self.transfer.next_transfer(next_buffer).unwrap();
self.next_buffer.replace(prev_buffer); self.next_buffer.replace(prev_buffer);
self.next_buffer.as_ref().unwrap() self.next_buffer.as_ref().unwrap()
} }

View File

@ -1,4 +1,3 @@
use super::hal; use super::hal;
use heapless::consts; use heapless::consts;
@ -8,9 +7,14 @@ pub struct Dac0Output {
} }
impl Dac0Output { impl Dac0Output {
pub fn new(spi: hal::spi::Spi<hal::stm32::SPI4, hal::spi::Enabled, u16>) -> Self { pub fn new(
spi: hal::spi::Spi<hal::stm32::SPI4, hal::spi::Enabled, u16>,
) -> Self {
spi.inner().cr1.modify(|_, w| w.cstart().started()); spi.inner().cr1.modify(|_, w| w.cstart().started());
Self { spi, outputs: heapless::spsc::Queue::new() } Self {
spi,
outputs: heapless::spsc::Queue::new(),
}
} }
pub fn push(&mut self, value: u16) { pub fn push(&mut self, value: u16) {
@ -20,13 +24,16 @@ impl Dac0Output {
pub fn update(&mut self) { pub fn update(&mut self) {
match self.outputs.dequeue() { match self.outputs.dequeue() {
Some(value) => self.write(value), Some(value) => self.write(value),
None => {}, None => {}
} }
} }
pub fn write(&mut self, value: u16) { pub fn write(&mut self, value: u16) {
unsafe { unsafe {
core::ptr::write_volatile(&self.spi.inner().txdr as *const _ as *mut u16, value); core::ptr::write_volatile(
&self.spi.inner().txdr as *const _ as *mut u16,
value,
);
} }
} }
} }
@ -42,7 +49,10 @@ impl Dac1Output {
) -> Self { ) -> Self {
spi.inner().cr1.modify(|_, w| w.cstart().started()); spi.inner().cr1.modify(|_, w| w.cstart().started());
Self { spi, outputs: heapless::spsc::Queue::new() } Self {
spi,
outputs: heapless::spsc::Queue::new(),
}
} }
pub fn push(&mut self, value: u16) { pub fn push(&mut self, value: u16) {
@ -52,13 +62,16 @@ impl Dac1Output {
pub fn update(&mut self) { pub fn update(&mut self) {
match self.outputs.dequeue() { match self.outputs.dequeue() {
Some(value) => self.write(value), Some(value) => self.write(value),
None => {}, None => {}
} }
} }
pub fn write(&mut self, value: u16) { pub fn write(&mut self, value: u16) {
unsafe { unsafe {
core::ptr::write_volatile(&self.spi.inner().txdr as *const _ as *mut u16, value); core::ptr::write_volatile(
&self.spi.inner().txdr as *const _ as *mut u16,
value,
);
} }
} }
} }

View File

@ -36,13 +36,9 @@ use embedded_hal::digital::v2::{InputPin, OutputPin};
use hal::{ use hal::{
dma::{ dma::{
Transfer, dma::{DMAReq, DmaConfig},
PeripheralToMemory, MemoryToPeripheral,
traits::{Stream, TargetAddress}, traits::{Stream, TargetAddress},
dma::{ MemoryToPeripheral, PeripheralToMemory, Transfer,
DmaConfig,
DMAReq,
},
}, },
ethernet::{self, PHY}, ethernet::{self, PHY},
}; };
@ -53,16 +49,16 @@ use heapless::{consts::*, String};
#[link_section = ".sram3.eth"] #[link_section = ".sram3.eth"]
static mut DES_RING: ethernet::DesRing = ethernet::DesRing::new(); static mut DES_RING: ethernet::DesRing = ethernet::DesRing::new();
mod dac;
mod adc; mod adc;
mod afe; mod afe;
mod dac;
mod eeprom; mod eeprom;
mod iir; mod iir;
mod pounder; mod pounder;
mod server; mod server;
use dac::{Dac0Output, Dac1Output};
use adc::{Adc0Input, Adc1Input}; use adc::{Adc0Input, Adc1Input};
use dac::{Dac0Output, Dac1Output};
#[cfg(not(feature = "semihosting"))] #[cfg(not(feature = "semihosting"))]
fn init_log() {} fn init_log() {}
@ -257,7 +253,8 @@ const APP: () = {
afe::ProgrammableGainAmplifier::new(a0_pin, a1_pin) afe::ProgrammableGainAmplifier::new(a0_pin, a1_pin)
}; };
let dma_streams = hal::dma::dma::StreamsTuple::new(dp.DMA1, ccdr.peripheral.DMA1); let dma_streams =
hal::dma::dma::StreamsTuple::new(dp.DMA1, ccdr.peripheral.DMA1);
// Configure the SPI interfaces to the ADCs and DACs. // Configure the SPI interfaces to the ADCs and DACs.
let adc0 = { let adc0 = {
@ -714,7 +711,8 @@ const APP: () = {
let mut last_result: u16 = 0; let mut last_result: u16 = 0;
for sample in samples { for sample in samples {
let x0 = f32::from(*sample as i16); let x0 = f32::from(*sample as i16);
let y0 = c.resources.iir_ch[1].update(&mut c.resources.iir_state[1], x0); let y0 =
c.resources.iir_ch[1].update(&mut c.resources.iir_state[1], x0);
last_result = y0 as i16 as u16 ^ 0x8000; last_result = y0 as i16 as u16 ^ 0x8000;
//c.resources.dac0.push(last_result); //c.resources.dac0.push(last_result);
} }
@ -729,7 +727,8 @@ const APP: () = {
let mut last_result: u16 = 0; let mut last_result: u16 = 0;
for sample in samples { for sample in samples {
let x0 = f32::from(*sample as i16); let x0 = f32::from(*sample as i16);
let y0 = c.resources.iir_ch[0].update(&mut c.resources.iir_state[0], x0); let y0 =
c.resources.iir_ch[0].update(&mut c.resources.iir_state[0], x0);
last_result = y0 as i16 as u16 ^ 0x8000; last_result = y0 as i16 as u16 ^ 0x8000;
//c.resources.dac0.push(last_result); //c.resources.dac0.push(last_result);
} }