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
+61
View File
@@ -0,0 +1,61 @@
// This example posts an URL using http.Post(). URL scheme can be http or https.
//
// Note: It may be necessary to increase the stack size when using "net/http".
// Use the -stack-size=4KB command line option.
//
// Some targets (Arduino Nano33 IoT) don't have enough SRAM to run http.Post().
// Use the following for those targets:
//
// examples/net/webclient (for HTTP)
// examples/net/tlsclient (for HTTPS)
package main
import (
"bytes"
"fmt"
"io"
"log"
"machine"
"net/http"
"time"
)
var (
ssid string
pass string
)
func main() {
waitSerial()
if err := netdev.NetConnect(); err != nil {
log.Fatal(err)
}
path := "https://httpbin.org/post"
data := []byte("{\"name\":\"John Doe\",\"occupation\":\"gardener\"}")
resp, err := http.Post(path, "application/json", bytes.NewBuffer(data))
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(body))
netdev.NetDisconnect()
}
// 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 || nano_rp2040 || metro_m4_airlift || arduino_mkrwifi1010 || matrixportal_m4
// +build: pyportal 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)