Add network device driver model, netdev

This commit is contained in:
Scott Feldman
2023-03-28 12:18:59 -07:00
committed by Ron Evans
parent 00b1b4fbfb
commit 276feecc20
128 changed files with 6389 additions and 15539 deletions
+23
View File
@@ -0,0 +1,23 @@
//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)
+92
View File
@@ -0,0 +1,92 @@
// This example opens a TCP connection and sends some data, for the purpose of
// testing speed and connectivity.
//
// You can open a server to accept connections from this program using:
//
// nc -lk 8080
package main
import (
"bytes"
"fmt"
"log"
"machine"
"net"
"time"
)
var (
ssid string
pass string
addr string = "10.0.0.100:8080"
)
var buf = &bytes.Buffer{}
func main() {
waitSerial()
if err := netdev.NetConnect(); err != nil {
log.Fatal(err)
}
for {
sendBatch()
time.Sleep(500 * time.Millisecond)
}
}
func sendBatch() {
// make TCP connection
message("---------------\r\nDialing TCP connection")
conn, err := net.Dial("tcp", addr)
for ; err != nil; conn, err = net.Dial("tcp", addr) {
message(err.Error())
time.Sleep(5 * time.Second)
}
n := 0
w := 0
start := time.Now()
// send data
message("Sending data")
for i := 0; i < 1000; i++ {
buf.Reset()
fmt.Fprint(buf,
"\r---------------------------- i == ", i, " ----------------------------"+
"\r---------------------------- i == ", i, " ----------------------------")
if w, err = conn.Write(buf.Bytes()); err != nil {
println("error:", err.Error(), "\r")
break
}
n += w
}
buf.Reset()
ms := time.Now().Sub(start).Milliseconds()
fmt.Fprint(buf, "\nWrote ", n, " bytes in ", ms, " ms\r\n")
message(buf.String())
if _, err := conn.Write(buf.Bytes()); err != nil {
println("error:", err.Error(), "\r")
}
println("Disconnecting TCP...")
conn.Close()
}
func message(msg string) {
println(msg, "\r")
}
// Wait for user to open serial console
func waitSerial() {
for !machine.Serial.DTR() {
time.Sleep(100 * time.Millisecond)
}
}
+29
View File
@@ -0,0 +1,29 @@
//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)
WatchdogTimeo: time.Duration(20 * time.Second),
}
var netdev = rtl8720dn.New(&cfg)
+33
View File
@@ -0,0 +1,33 @@
//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)
WatchdogTimeo: time.Duration(20 * time.Second),
}
var netdev = wifinina.New(&cfg)