mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-11 02:13:42 +00:00
move netdev and netlink into their own packages and out of drivers
This moves the netdev/netlink namespace out of drivers and into their own packages. Also, defines netdev and netlink as L3/L4 and L2 OSI layers, respectively. Move some L3 functionality from netlink to netdev (GetIPAddr). For netlink, add ConnectParams for NetConnect to pass in L2 connection parameters (ssid, pass, auth_type, etc). Also adds connection mode (STA, AP, etc). For netlink, add SendEth and RecvEthFunc funcs to handle L2 send/recv of Ethernet pkts.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
//go:build challenger_rp2040
|
||||
|
||||
// +build: challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/espat"
|
||||
)
|
||||
|
||||
var cfg = espat.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// UART
|
||||
Uart: machine.UART1,
|
||||
Tx: machine.UART1_TX_PIN,
|
||||
Rx: machine.UART1_RX_PIN,
|
||||
}
|
||||
|
||||
var netdev = espat.New(&cfg)
|
||||
@@ -4,6 +4,8 @@
|
||||
//
|
||||
// nc -lk 8080
|
||||
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4 || wioterminal || challenger_rp2040
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -15,7 +17,9 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
"tinygo.org/x/drivers/netdev"
|
||||
"tinygo.org/x/drivers/netlink"
|
||||
"tinygo.org/x/drivers/netlink/probe"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -25,12 +29,20 @@ var (
|
||||
)
|
||||
|
||||
var buf = &bytes.Buffer{}
|
||||
var link netlink.Netlinker
|
||||
var dev netdev.Netdever
|
||||
|
||||
func main() {
|
||||
|
||||
waitSerial()
|
||||
|
||||
if err := netdev.NetConnect(); err != nil {
|
||||
link, dev = probe.Probe()
|
||||
|
||||
err := link.NetConnect(&netlink.ConnectParams{
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -48,9 +60,9 @@ func sendBatch() {
|
||||
|
||||
// make TCP connection
|
||||
message("---------------\r\nDialing TCP connection")
|
||||
fd, _ := netdev.Socket(drivers.AF_INET, drivers.SOCK_STREAM, drivers.IPPROTO_TCP)
|
||||
err := netdev.Connect(fd, "", ip, port)
|
||||
for ; err != nil; err = netdev.Connect(fd, "", ip, port) {
|
||||
fd, _ := dev.Socket(netdev.AF_INET, netdev.SOCK_STREAM, netdev.IPPROTO_TCP)
|
||||
err := dev.Connect(fd, "", ip, port)
|
||||
for ; err != nil; err = dev.Connect(fd, "", ip, port) {
|
||||
message(err.Error())
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
@@ -67,7 +79,7 @@ func sendBatch() {
|
||||
fmt.Fprint(buf,
|
||||
"\r---------------------------- i == ", i, " ----------------------------"+
|
||||
"\r---------------------------- i == ", i, " ----------------------------")
|
||||
if w, err = netdev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
if w, err = dev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
println("error:", err.Error(), "\r")
|
||||
break
|
||||
}
|
||||
@@ -79,12 +91,12 @@ func sendBatch() {
|
||||
fmt.Fprint(buf, "\nWrote ", n, " bytes in ", ms, " ms\r\n")
|
||||
message(buf.String())
|
||||
|
||||
if _, err := netdev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
if _, err := dev.Send(fd, buf.Bytes(), 0, time.Time{}); err != nil {
|
||||
println("error:", err.Error(), "\r")
|
||||
}
|
||||
|
||||
println("Disconnecting TCP...")
|
||||
netdev.Close(fd)
|
||||
dev.Close(fd)
|
||||
}
|
||||
|
||||
func message(msg string) {
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
//go:build wioterminal
|
||||
|
||||
// +build: wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var cfg = rtl8720dn.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Device
|
||||
En: machine.RTL8720D_CHIP_PU,
|
||||
// UART
|
||||
Uart: machine.UART3,
|
||||
Tx: machine.PB24,
|
||||
Rx: machine.PC24,
|
||||
Baudrate: 614400,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = rtl8720dn.New(&cfg)
|
||||
@@ -1,33 +0,0 @@
|
||||
//go:build pyportal || arduino_nano33 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
|
||||
|
||||
// +build: pyportal arduino_nano33 nano_rp2040 metro_m4_airlift arduino_mkrwifi1010 matrixportal_m4
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var cfg = wifinina.Config{
|
||||
// WiFi AP credentials
|
||||
Ssid: ssid,
|
||||
Passphrase: pass,
|
||||
// Configure SPI for 8Mhz, Mode 0, MSB First
|
||||
Spi: machine.NINA_SPI,
|
||||
Freq: 8 * 1e6,
|
||||
Sdo: machine.NINA_SDO,
|
||||
Sdi: machine.NINA_SDI,
|
||||
Sck: machine.NINA_SCK,
|
||||
// Device pins
|
||||
Cs: machine.NINA_CS,
|
||||
Ack: machine.NINA_ACK,
|
||||
Gpio0: machine.NINA_GPIO0,
|
||||
Resetn: machine.NINA_RESETN,
|
||||
// Watchdog (set to 0 to disable)
|
||||
WatchdogTimeout: time.Duration(20 * time.Second),
|
||||
}
|
||||
|
||||
var netdev = wifinina.New(&cfg)
|
||||
Reference in New Issue
Block a user