From d557e2542db703524f06eaba5947fe3fd689f17e Mon Sep 17 00:00:00 2001 From: occheung Date: Mon, 25 Jan 2021 10:47:21 +0800 Subject: [PATCH] Modify changes: - Revert unwrap() addition to examples - Remove redundant bracket * Changed closure variable to delay_ns for clarity --- examples/tcp_stm32f407.rs | 6 +++--- examples/tx_stm32f407.rs | 8 ++++---- src/lib.rs | 4 ++-- src/spi.rs | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/tcp_stm32f407.rs b/examples/tcp_stm32f407.rs index d734160..10e4e7a 100644 --- a/examples/tcp_stm32f407.rs +++ b/examples/tcp_stm32f407.rs @@ -180,7 +180,7 @@ const APP: () = { // Read MAC let mut eth_mac_addr: [u8; 6] = [0; 6]; - spi_eth.read_from_mac(&mut eth_mac_addr).unwrap(); + spi_eth.read_from_mac(&mut eth_mac_addr); for i in 0..6 { let byte = eth_mac_addr[i]; match i { @@ -192,8 +192,8 @@ const APP: () = { } // Init Rx/Tx buffers - spi_eth.init_rxbuf().unwrap(); - spi_eth.init_txbuf().unwrap(); + spi_eth.init_rxbuf(); + spi_eth.init_txbuf(); iprintln!(stim0, "Ethernet controller initialized"); // Init smoltcp interface diff --git a/examples/tx_stm32f407.rs b/examples/tx_stm32f407.rs index 6c36402..93d6ab9 100644 --- a/examples/tx_stm32f407.rs +++ b/examples/tx_stm32f407.rs @@ -102,7 +102,7 @@ const APP: () = { // Read MAC let mut eth_mac_addr: [u8; 6] = [0; 6]; - spi_eth.read_from_mac(&mut eth_mac_addr).unwrap(); + spi_eth.read_from_mac(&mut eth_mac_addr); for i in 0..6 { let byte = eth_mac_addr[i]; match i { @@ -114,8 +114,8 @@ const APP: () = { } // Init Rx/Tx buffers - spi_eth.init_rxbuf().unwrap(); - spi_eth.init_txbuf().unwrap(); + spi_eth.init_rxbuf(); + spi_eth.init_txbuf(); iprintln!(stim0, "Ethernet controller initialized"); init::LateResources { @@ -157,7 +157,7 @@ const APP: () = { _ => () }; } - c.resources.spi_eth.send_raw_packet(ð_tx_packet).unwrap(); + c.resources.spi_eth.send_raw_packet(ð_tx_packet); iprintln!(stim0, "Packet sent"); c.resources.delay.delay_ms(100_u32); } diff --git a/src/lib.rs b/src/lib.rs index e99cefa..71e6e7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,9 +54,9 @@ pub struct SpiEth, impl , NSS: OutputPin, F: FnMut(u32) -> ()> SpiEth { - pub fn new(spi: SPI, nss: NSS, f: F) -> Self { + pub fn new(spi: SPI, nss: NSS, delay_ns: F) -> Self { SpiEth { - spi_port: spi::SpiPort::new(spi, nss, f), + spi_port: spi::SpiPort::new(spi, nss, delay_ns), rx_buf: rx::RxBuffer::new(), tx_buf: tx::TxBuffer::new() } diff --git a/src/spi.rs b/src/spi.rs index 6bb1d37..a5dd23c 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -1,5 +1,5 @@ use embedded_hal::{ - blocking::{spi::Transfer}, + blocking::spi::Transfer, digital::v2::OutputPin, }; @@ -68,13 +68,13 @@ impl , NSS: OutputPin, F: FnMut(u32) -> ()> SpiPort { // TODO: return as Result() - pub fn new(spi: SPI, mut nss: NSS, f: F) -> Self { + pub fn new(spi: SPI, mut nss: NSS, delay_ns: F) -> Self { nss.set_high(); SpiPort { spi, nss, - delay_ns: f, + delay_ns, } }