Skip to content

Commit

Permalink
Create a basic transport layer
Browse files Browse the repository at this point in the history
  • Loading branch information
dflemstr committed Mar 14, 2020
1 parent 47d0d3c commit ce1e42a
Show file tree
Hide file tree
Showing 9 changed files with 1,548 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "wifi-nina"
version = "0.1.0"
authors = ["David Flemström <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
embedded-hal = { version = "0.2.3", features = ["unproven"] }
log = { version = "0.4.8", default-features = false }
nb = { version = "0.1.2", default-features = false }
no-std-net = { version = "0.3.0", default-features = false }
num_enum = { version = "0.4.2", default-features = false }
56 changes: 56 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#[derive(Clone, Copy, Debug, Eq, PartialEq, num_enum::IntoPrimitive, num_enum::TryFromPrimitive)]
#[repr(u8)]
pub enum Command {
SetNetCmd = 0x10,
SetPassphraseCmd = 0x11,
SetKeyCmd = 0x12,
SetIpConfigCmd = 0x14,
SetDnsConfigCmd = 0x15,
SetHostnameCmd = 0x16,
SetPowerModeCmd = 0x17,
SetApNetCmd = 0x18,
SetApPassphraseCmd = 0x19,
SetDebugCmd = 0x1A,
GetTemperatureCmd = 0x1B,

GetConnStatusCmd = 0x20,
GetIpaddrCmd = 0x21,
GetMacaddrCmd = 0x22,
GetCurrSsidCmd = 0x23,
GetCurrBssidCmd = 0x24,
GetCurrRssiCmd = 0x25,
GetCurrEnctCmd = 0x26,
ScanNetworks = 0x27,
StartServerTcpCmd = 0x28,
GetStateTcpCmd = 0x29,
DataSentTcpCmd = 0x2A,
AvailDataTcpCmd = 0x2B,
GetDataTcpCmd = 0x2C,
StartClientTcpCmd = 0x2D,
StopClientTcpCmd = 0x2E,
GetClientStateTcpCmd = 0x2F,
DisconnectCmd = 0x30,
GetIdxRssiCmd = 0x32,
GetIdxEnctCmd = 0x33,
ReqHostByNameCmd = 0x34,
GetHostByNameCmd = 0x35,
StartScanNetworks = 0x36,
GetFwVersionCmd = 0x37,
SendDataUdpCmd = 0x39,
GetRemoteDataCmd = 0x3A,
GetTimeCmd = 0x3B,
GetIdxBssid = 0x3C,
GetIdxChannelCmd = 0x3D,
PingCmd = 0x3E,
GetSocketCmd = 0x3F,

// All command with DATA_FLAG 0x40 send a 16bit Len
SendDataTcpCmd = 0x44,
GetDatabufTcpCmd = 0x45,
InsertDatabufCmd = 0x46,

// regular format commands
SetPinMode = 0x50,
SetDigitalWrite = 0x51,
SetAnalogWrite = 0x52,
}
25 changes: 25 additions & 0 deletions src/full_duplex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub trait FullDuplexExt<Word>: embedded_hal::spi::FullDuplex<Word>
where
Word: core::fmt::LowerHex + Copy + Default,
{
fn send_exchange(&mut self, word: Word) -> Result<(), Self::Error> {
nb::block!(self.send(word))?;
log::trace!("send {:#04x}", word);
nb::block!(self.read())?;
Ok(())
}

fn recv_exchange(&mut self) -> Result<Word, Self::Error> {
nb::block!(self.send(Word::default()))?;
let byte = nb::block!(self.read())?;
log::trace!("recv {:#04x}", byte);
Ok(byte)
}
}

impl<T, Word> FullDuplexExt<Word> for T
where
T: embedded_hal::spi::FullDuplex<Word>,
Word: core::fmt::LowerHex + Copy + Default,
{
}
Loading

0 comments on commit ce1e42a

Please sign in to comment.