Skip to content

Commit

Permalink
DMA - Rename stream to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
usbalbin committed Nov 11, 2024
1 parent 145ba50 commit 4b61d29
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 294 deletions.
6 changes: 3 additions & 3 deletions examples/adc-continious-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::hal::{
AdcClaim, ClockSource, Temperature, Vref,
},
delay::SYSTDelayExt,
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
dma::{channel::DMAExt, config::DmaConfig, TransferExt},
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
Expand All @@ -36,7 +36,7 @@ fn main() -> ! {
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(Config::hsi(), pwr);

let streams = dp.DMA1.split(&rcc);
let channels = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
.transfer_complete_interrupt(false)
.circular_buffer(true)
Expand All @@ -62,7 +62,7 @@ fn main() -> ! {

info!("Setup DMA");
let first_buffer = cortex_m::singleton!(: [u16; 15] = [0; 15]).unwrap();
let mut transfer = streams.0.into_circ_peripheral_to_memory_transfer(
let mut transfer = channels.0.into_circ_peripheral_to_memory_transfer(
adc.enable_dma(AdcDma::Continuous),
&mut first_buffer[..],
config,
Expand Down
8 changes: 4 additions & 4 deletions examples/adc-one-shot-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::hal::{
AdcClaim, ClockSource, Temperature,
},
delay::SYSTDelayExt,
dma::{config::DmaConfig, stream::DMAExt, TransferExt},
dma::{channel::DMAExt, config::DmaConfig, TransferExt},
gpio::GpioExt,
pwr::PwrExt,
rcc::{Config, RccExt},
Expand Down Expand Up @@ -37,7 +37,7 @@ fn main() -> ! {
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(Config::hsi(), pwr);

let mut streams = dp.DMA1.split(&rcc);
let mut channels = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
.transfer_complete_interrupt(false)
.circular_buffer(false)
Expand All @@ -61,7 +61,7 @@ fn main() -> ! {

info!("Setup DMA");
let first_buffer = cortex_m::singleton!(: [u16; 2] = [0; 2]).unwrap();
let mut transfer = streams.0.into_peripheral_to_memory_transfer(
let mut transfer = channels.0.into_peripheral_to_memory_transfer(
adc.enable_dma(AdcDma::Single),
&mut first_buffer[..],
config,
Expand All @@ -77,7 +77,7 @@ fn main() -> ! {
let (s0, adc, first_buffer) = transfer.free();
let adc = adc.disable();

streams.0 = s0;
channels.0 = s0;

let millivolts = adc.sample_to_millivolts(first_buffer[0]);
info!("pa3: {}mV", millivolts);
Expand Down
13 changes: 7 additions & 6 deletions examples/spi-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use crate::hal::{

use cortex_m_rt::entry;
use stm32g4xx_hal as hal;
use stm32g4xx_hal::dma::channel::DMAExt;
use stm32g4xx_hal::dma::config::DmaConfig;
use stm32g4xx_hal::dma::stream::DMAExt;
use stm32g4xx_hal::dma::TransferExt;

#[macro_use]
Expand All @@ -50,7 +50,7 @@ fn main() -> ! {
let spi = dp
.SPI1
.spi((sclk, miso, mosi), spi::MODE_0, 400.kHz(), &mut rcc);
let streams = dp.DMA1.split(&rcc);
let channels = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
.transfer_complete_interrupt(false)
.circular_buffer(true)
Expand All @@ -62,10 +62,11 @@ fn main() -> ! {
*item = index as u8;
}
let dma_buf = cortex_m::singleton!(: [u8; BUFFER_SIZE] = buf).unwrap();
let mut transfer_dma =
streams
.0
.into_memory_to_peripheral_transfer(spi.enable_tx_dma(), &mut dma_buf[..], config);
let mut transfer_dma = channels.0.into_memory_to_peripheral_transfer(
spi.enable_tx_dma(),
&mut dma_buf[..],
config,
);
transfer_dma.start(|_spi| {});
loop {
delay_tim2.delay_ms(1000_u16);
Expand Down
6 changes: 3 additions & 3 deletions examples/uart-dma-rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

extern crate cortex_m_rt as rt;

use hal::dma::{config::DmaConfig, stream::DMAExt, TransferExt};
use hal::dma::{channel::DMAExt, config::DmaConfig, TransferExt};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::serial::*;
Expand All @@ -30,7 +30,7 @@ fn main() -> ! {
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(rcc::Config::hsi(), pwr);

let streams = dp.DMA1.split(&rcc);
let channels = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
.transfer_complete_interrupt(false)
.circular_buffer(true)
Expand Down Expand Up @@ -65,7 +65,7 @@ fn main() -> ! {

let (_tx, rx) = usart.split();

let mut transfer = streams.0.into_circ_peripheral_to_memory_transfer(
let mut transfer = channels.0.into_circ_peripheral_to_memory_transfer(
rx.enable_dma(),
&mut rx_buffer[..],
config,
Expand Down
6 changes: 3 additions & 3 deletions examples/uart-dma-tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate cortex_m_rt as rt;

use core::fmt::Write;

use hal::dma::{config::DmaConfig, stream::DMAExt, TransferExt};
use hal::dma::{channel::DMAExt, config::DmaConfig, TransferExt};
use hal::prelude::*;
use hal::pwr::PwrExt;
use hal::serial::*;
Expand All @@ -32,7 +32,7 @@ fn main() -> ! {
let pwr = dp.PWR.constrain().freeze();
let mut rcc = rcc.freeze(rcc::Config::hsi(), pwr);

let streams = dp.DMA1.split(&rcc);
let channels = dp.DMA1.split(&rcc);
let config = DmaConfig::default()
.transfer_complete_interrupt(false)
.circular_buffer(false)
Expand Down Expand Up @@ -65,7 +65,7 @@ fn main() -> ! {

// Setup DMA for USART2 TX with dma channel 1.
let mut transfer =
streams
channels
.0
.into_memory_to_peripheral_transfer(tx.enable_dma(), &mut tx_buffer[..], config);

Expand Down
6 changes: 3 additions & 3 deletions src/dma.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Direct Memory Access.
//!
//! [Transfer::init](struct.Transfer.html#method.init) is only implemented for
//! valid combinations of peripheral-stream-channel-direction, providing compile
//! valid combinations of peripheral-channel-direction, providing compile
//! time checking.
//!
//! This module implements Memory To Memory, Peripheral To Memory and Memory to
Expand All @@ -17,13 +17,13 @@

use core::fmt::Debug;

pub mod channel; // DMA MUX // DMA1 and DMA2
pub mod config;
pub(crate) mod mux;
pub mod stream; // DMA MUX // DMA1 and DMA2
pub mod traits;
pub mod transfer;

use traits::{sealed::Bits, Direction, Stream, TargetAddress};
use traits::{sealed::Bits, Channel, Direction, TargetAddress};
pub use transfer::{Transfer, TransferExt};

/// Errors.
Expand Down
Loading

0 comments on commit 4b61d29

Please sign in to comment.