aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-wiznet/src/chip/w5100s.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net-wiznet/src/chip/w5100s.rs')
-rw-r--r--embassy-net-wiznet/src/chip/w5100s.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/embassy-net-wiznet/src/chip/w5100s.rs b/embassy-net-wiznet/src/chip/w5100s.rs
new file mode 100644
index 000000000..07a840370
--- /dev/null
+++ b/embassy-net-wiznet/src/chip/w5100s.rs
@@ -0,0 +1,61 @@
1use embedded_hal_async::spi::{Operation, SpiDevice};
2
3const SOCKET_BASE: u16 = 0x400;
4const TX_BASE: u16 = 0x4000;
5const RX_BASE: u16 = 0x6000;
6
7pub enum W5100S {}
8
9impl super::Chip for W5100S {}
10impl super::sealed::Chip for W5100S {
11 type Address = u16;
12
13 const COMMON_MODE: Self::Address = 0x00;
14 const COMMON_MAC: Self::Address = 0x09;
15 const COMMON_SOCKET_INTR: Self::Address = 0x16;
16 const COMMON_PHY_CFG: Self::Address = 0x3c;
17
18 const SOCKET_MODE: Self::Address = SOCKET_BASE + 0x00;
19 const SOCKET_COMMAND: Self::Address = SOCKET_BASE + 0x01;
20 const SOCKET_RXBUF_SIZE: Self::Address = SOCKET_BASE + 0x1E;
21 const SOCKET_TXBUF_SIZE: Self::Address = SOCKET_BASE + 0x1F;
22 const SOCKET_TX_FREE_SIZE: Self::Address = SOCKET_BASE + 0x20;
23 const SOCKET_TX_DATA_WRITE_PTR: Self::Address = SOCKET_BASE + 0x24;
24 const SOCKET_RECVD_SIZE: Self::Address = SOCKET_BASE + 0x26;
25 const SOCKET_RX_DATA_READ_PTR: Self::Address = SOCKET_BASE + 0x28;
26 const SOCKET_INTR_MASK: Self::Address = SOCKET_BASE + 0x2C;
27 const SOCKET_INTR: Self::Address = SOCKET_BASE + 0x02;
28
29 const SOCKET_MODE_VALUE: u8 = (1 << 2) | (1 << 6);
30
31 const BUF_SIZE: u16 = 0x2000;
32 const AUTO_WRAP: bool = false;
33
34 fn rx_addr(addr: u16) -> Self::Address {
35 RX_BASE + addr
36 }
37
38 fn tx_addr(addr: u16) -> Self::Address {
39 TX_BASE + addr
40 }
41
42 async fn bus_read<SPI: SpiDevice>(
43 spi: &mut SPI,
44 address: Self::Address,
45 data: &mut [u8],
46 ) -> Result<(), SPI::Error> {
47 spi.transaction(&mut [
48 Operation::Write(&[0x0F, (address >> 8) as u8, address as u8]),
49 Operation::Read(data),
50 ])
51 .await
52 }
53
54 async fn bus_write<SPI: SpiDevice>(spi: &mut SPI, address: Self::Address, data: &[u8]) -> Result<(), SPI::Error> {
55 spi.transaction(&mut [
56 Operation::Write(&[0xF0, (address >> 8) as u8, address as u8]),
57 Operation::Write(data),
58 ])
59 .await
60 }
61}