Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #201: Use NonZeroUsize to specify DMA transfer size #203

Merged
merged 3 commits into from
Jan 12, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use core::borrow::{Borrow, BorrowMut};
use core::cell::UnsafeCell;
use core::cmp::{max, min, Ordering};
use core::marker::PhantomData;
use core::num::NonZeroUsize;
use core::ptr;

use embedded_hal::spi::{SpiBus, SpiBusFlush, SpiBusRead, SpiBusWrite, SpiDevice};
Expand Down Expand Up @@ -62,9 +63,9 @@ pub trait SpiAnyPins: Spi {}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Dma {
Disabled,
Channel1(usize),
Channel2(usize),
Auto(usize),
Channel1(NonZeroUsize),
Channel2(NonZeroUsize),
Auto(NonZeroUsize),
}

impl From<Dma> for spi_dma_chan_t {
Expand All @@ -82,7 +83,7 @@ impl Dma {
pub const fn max_transfer_size(&self) -> usize {
let max_transfer_size = match self {
Dma::Disabled => TRANS_LEN,
Dma::Channel1(size) | Dma::Channel2(size) | Dma::Auto(size) => *size,
Dma::Channel1(size) | Dma::Channel2(size) | Dma::Auto(size) => (*size).get(),
};
if max_transfer_size % 4 != 0 {
panic!("The max transfer size must be a multiple of 4")
Expand Down