diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index 93b20ab3..00000000 --- a/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[unstable] -namespaced-features = true \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f349f50a..219a5e36 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,4 +21,4 @@ jobs: target: thumbv7em-none-eabi override: true - name: Build - run: ./test-build.sh + run: ./ci.sh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..b0c62330 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.formatOnSave": true, + "rust-analyzer.procMacro.enable": true, + "rust-analyzer.cargo.loadOutDirsFromCheck": true, + "rust-analyzer.assist.importMergeBehavior": "last", +} \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 1b301282..7ab99c2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,4 +45,5 @@ overflow-checks = false embassy = { git = "https://github.com/akiles/embassy" } embassy-std = { git = "https://github.com/akiles/embassy" } embassy-macros = { git = "https://github.com/akiles/embassy" } +embassy-traits = { git = "https://github.com/akiles/embassy" } smoltcp = { git = "https://github.com/akiles/smoltcp" } \ No newline at end of file diff --git a/test-build.sh b/ci.sh similarity index 92% rename from test-build.sh rename to ci.sh index ec35f5da..385379de 100755 --- a/test-build.sh +++ b/ci.sh @@ -7,7 +7,7 @@ set -euxo pipefail # build for embedded (cd embassy-net; cargo build --target thumbv7em-none-eabi --features log) -(cd embassy-net; cargo build --target thumbv7em-none-eabi --features defmt) +(cd embassy-net; cargo build --target thumbv7em-none-eabi --features defmt,smoltcp/defmt) # build examples (cd embassy-net-examples; cargo build) diff --git a/embassy-net-examples/src/main.rs b/embassy-net-examples/src/main.rs index bc413f1a..dba1415b 100644 --- a/embassy-net-examples/src/main.rs +++ b/embassy-net-examples/src/main.rs @@ -1,8 +1,7 @@ #![feature(type_alias_impl_trait)] -use embassy::executor::{Spawner, task}; -use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; -use embassy::time::{Duration, Timer}; +use embassy::executor::{task, Spawner}; +use embassy::io::AsyncWriteExt; use embassy::util::Forever; use embassy_net::*; use embassy_std::Executor; diff --git a/embassy-net-examples/src/tuntap.rs b/embassy-net-examples/src/tuntap.rs index 5c138c06..b2117e81 100644 --- a/embassy-net-examples/src/tuntap.rs +++ b/embassy-net-examples/src/tuntap.rs @@ -1,11 +1,11 @@ use async_io::Async; use embassy::util::WakerRegistration; use libc; +use log::*; use smoltcp::wire::EthernetFrame; use std::io; use std::io::{Read, Write}; use std::os::unix::io::{AsRawFd, RawFd}; -use log::*; pub const SIOCGIFMTU: libc::c_ulong = 0x8921; pub const SIOCGIFINDEX: libc::c_ulong = 0x8933; @@ -142,8 +142,8 @@ impl TunTapDevice { } } -use embassy_net::{LinkState, DeviceCapabilities, Packet, PacketBox, PacketBuf}; use core::task::Waker; +use embassy_net::{DeviceCapabilities, LinkState, Packet, PacketBox, PacketBuf}; impl crate::Device for TunTapDevice { fn is_transmit_ready(&mut self) -> bool { @@ -197,4 +197,8 @@ impl crate::Device for TunTapDevice { fn link_state(&mut self) -> LinkState { LinkState::Up } + + fn ethernet_address(&mut self) -> [u8; 6] { + [0x02, 0x03, 0x04, 0x05, 0x06, 0x07] + } } diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 185992dd..de625018 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -11,11 +11,10 @@ defmt-debug = [] defmt-info = [] defmt-warn = [] defmt-error = [] -defmt = [ "dep:defmt", "smoltcp/defmt" ] [dependencies] -defmt = { version = "0.1.3", optional = true } +defmt = { version = "0.2.0", optional = true } log = { version = "0.4.11", optional = true } embassy = { version = "0.1.0" } diff --git a/embassy-net/src/config/dhcp.rs b/embassy-net/src/config/dhcp.rs index f5d598bd..0df67baf 100644 --- a/embassy-net/src/config/dhcp.rs +++ b/embassy-net/src/config/dhcp.rs @@ -1,13 +1,13 @@ use embassy::util::Forever; -use heapless::consts::*; use heapless::Vec; use smoltcp::dhcp::Dhcpv4Client; use smoltcp::socket::{RawPacketMetadata, RawSocketBuffer}; use smoltcp::time::Instant; -use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; +use smoltcp::wire::Ipv4Address; use super::*; -use crate::{device::LinkState, fmt::*}; +use crate::device::LinkState; +use crate::fmt::*; use crate::{Interface, SocketSet}; pub struct DhcpResources { diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 5a266f4e..32b56e5b 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -1,11 +1,11 @@ -use core::task::{Poll, Waker}; +use core::task::Waker; use smoltcp::phy::Device as SmolDevice; use smoltcp::phy::DeviceCapabilities; use smoltcp::time::Instant as SmolInstant; use crate::fmt::*; -use crate::{Packet, PacketBox, PacketBuf}; use crate::Result; +use crate::{Packet, PacketBox, PacketBuf}; #[derive(PartialEq, Eq, Clone, Copy)] pub enum LinkState { @@ -21,7 +21,7 @@ pub trait Device { fn register_waker(&mut self, waker: &Waker); fn capabilities(&mut self) -> DeviceCapabilities; fn link_state(&mut self) -> LinkState; - fn ethernet_address(&mut self) -> [u8;6]; + fn ethernet_address(&mut self) -> [u8; 6]; } pub struct DeviceAdapter { @@ -92,7 +92,7 @@ pub struct TxToken<'a> { } impl<'a> smoltcp::phy::TxToken for TxToken<'a> { - fn consume(mut self, _timestamp: SmolInstant, len: usize, f: F) -> Result + fn consume(self, _timestamp: SmolInstant, len: usize, f: F) -> Result where F: FnOnce(&mut [u8]) -> Result, { diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index 8f63db97..f8a945a5 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -1,7 +1,7 @@ +use core::cell::RefCell; use core::future::Future; use core::task::Context; use core::task::Poll; -use core::{cell::RefCell, future}; use embassy::time::{Instant, Timer}; use embassy::util::ThreadModeMutex; use embassy::util::{Forever, WakerRegistration}; @@ -110,7 +110,7 @@ impl Stack { self.waker.register(cx.waker()); let timestamp = instant_to_smoltcp(Instant::now()); - if let Err(e) = self.iface.poll(&mut self.sockets, timestamp) { + if let Err(_) = self.iface.poll(&mut self.sockets, timestamp) { // If poll() returns error, it may not be done yet, so poll again later. cx.waker().wake_by_ref(); return; @@ -174,6 +174,9 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf let sockets = SocketSet::new(&mut res.sockets[..]); + let local_port = LOCAL_PORT_MIN; + + /* let local_port = loop { let mut res = [0u8; 2]; embassy::rand::rand(&mut res); @@ -182,6 +185,7 @@ pub fn init(device: &'static mut dyn Device, configurator: &'static mut dyn Conf break port; } }; + */ let stack = Stack { iface, diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs index 84f09652..4f43bc61 100644 --- a/embassy-net/src/tcp_socket.rs +++ b/embassy-net/src/tcp_socket.rs @@ -111,7 +111,7 @@ impl<'a> TcpSocket<'a> { } } -fn to_ioerr(e: Error) -> io::Error { +fn to_ioerr(_err: Error) -> io::Error { // todo io::Error::Other }