diff --git a/src/spi.rs b/src/spi.rs index ebd37478699..df7b6a6db38 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -84,12 +84,11 @@ impl Dma { Dma::Disabled => TRANS_LEN, Dma::Channel1(size) | Dma::Channel2(size) | Dma::Auto(size) => *size, }; - if max_transfer_size % 4 != 0 { - panic!("The max transfer size must be a multiple of 4") - } else if max_transfer_size > 4096 { - 4096 - } else { - max_transfer_size + match max_transfer_size { + x if x % 4 != 0 => panic!("The max transfer size must be a multiple of 4"), + x if x == 0 => panic!("The max transfer size must be greater than 0"), + x if x > 4096 => panic!("The max transfer size must be less than or equal to 4096"), + _ => max_transfer_size, } } }