mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-14 20:03:40 +00:00
examples/rtl8720dn: update all remaining examples for refactored API
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -7,16 +7,17 @@
|
|||||||
//
|
//
|
||||||
// You must also install the Paho MQTT package to build this program:
|
// You must also install the Paho MQTT package to build this program:
|
||||||
//
|
//
|
||||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||||
//
|
//
|
||||||
// You can check that mqttpub/mqttsub is running successfully with the following command.
|
// You can check that mqttpub/mqttsub is running successfully with the following command.
|
||||||
//
|
//
|
||||||
// mosquitto_sub -h test.mosquitto.org -t tinygo/tx
|
// mosquitto_sub -h test.mosquitto.org -t tinygo/tx
|
||||||
// mosquitto_pub -h test.mosquitto.org -t tinygo/rx -m "hello world"
|
// mosquitto_pub -h test.mosquitto.org -t tinygo/rx -m "hello world"
|
||||||
//
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
@@ -45,7 +46,7 @@ var buf [0x400]byte
|
|||||||
|
|
||||||
var lastRequestTime time.Time
|
var lastRequestTime time.Time
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
var adaptor *rtl8720dn.RTL8720DN
|
var adaptor *rtl8720dn.Driver
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := run()
|
err := run()
|
||||||
@@ -68,18 +69,16 @@ func subHandler(client mqtt.Client, msg mqtt.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
// change the UART and pins as needed for platforms other than the WioTerminal.
|
||||||
if err != nil {
|
adaptor = rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
return err
|
adaptor.Configure()
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
if debug {
|
|
||||||
waitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -4,12 +4,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/net"
|
||||||
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IP address of the server aka "hub". Replace with your own info.
|
// IP address of the server aka "hub". Replace with your own info.
|
||||||
@@ -41,18 +44,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
if err != nil {
|
adaptor.Configure()
|
||||||
return err
|
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -4,15 +4,17 @@
|
|||||||
// You can open a server to accept connections from this program using:
|
// You can open a server to accept connections from this program using:
|
||||||
//
|
//
|
||||||
// nc -w 5 -lk 8080
|
// nc -w 5 -lk 8080
|
||||||
//
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/net"
|
||||||
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// You can override the setting with the init() in another source code.
|
// You can override the setting with the init() in another source code.
|
||||||
@@ -41,18 +43,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
if err != nil {
|
adaptor.Configure()
|
||||||
return err
|
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -68,20 +70,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
if err != nil {
|
adaptor.Configure()
|
||||||
return err
|
|
||||||
}
|
adaptor.SetRootCA(&test_root_ca)
|
||||||
rtl.SetRootCA(&test_root_ca)
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
http.SetBuf(buf[:])
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/net"
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IP address of the server aka "hub". Replace with your own info.
|
// IP address of the server aka "hub". Replace with your own info.
|
||||||
@@ -36,19 +39,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
if err != nil {
|
adaptor.Configure()
|
||||||
return err
|
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
http.SetBuf(buf[:])
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -20,13 +22,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
//rtl8720dn.Debug(true)
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
rtl, err := rtl8720dn.Setup()
|
adaptor.Configure()
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ver, err := rtl.Version()
|
ver, err := adaptor.Version()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
|
|
||||||
"tinygo.org/x/tinyfont/proggy"
|
"tinygo.org/x/tinyfont/proggy"
|
||||||
"tinygo.org/x/tinyterm"
|
"tinygo.org/x/tinyterm"
|
||||||
)
|
)
|
||||||
@@ -30,6 +34,15 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
display = ili9341.NewSPI(
|
||||||
|
machine.SPI3,
|
||||||
|
machine.LCD_DC,
|
||||||
|
machine.LCD_SS_PIN,
|
||||||
|
machine.LCD_RESET,
|
||||||
|
)
|
||||||
|
|
||||||
|
backlight = machine.LCD_BACKLIGHT
|
||||||
|
|
||||||
terminal = tinyterm.NewTerminal(display)
|
terminal = tinyterm.NewTerminal(display)
|
||||||
|
|
||||||
black = color.RGBA{0, 0, 0, 255}
|
black = color.RGBA{0, 0, 0, 255}
|
||||||
@@ -66,21 +79,20 @@ func run() error {
|
|||||||
fmt.Fprintf(terminal, "Running in debug mode.\r\n")
|
fmt.Fprintf(terminal, "Running in debug mode.\r\n")
|
||||||
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
|
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
|
||||||
}
|
}
|
||||||
rtl, err := setupRTL8720DN()
|
|
||||||
if err != nil {
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
return err
|
adaptor.Configure()
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
http.SetBuf(buf[:])
|
||||||
|
|
||||||
fmt.Fprintf(terminal, "ConnectToAP()\r\n")
|
fmt.Fprintf(terminal, "ConnectToAP()\r\n")
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(terminal, "connected\r\n\r\n")
|
fmt.Fprintf(terminal, "connected\r\n\r\n")
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -134,3 +146,15 @@ func run() error {
|
|||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
machine.SPI3.Configure(machine.SPIConfig{
|
||||||
|
SCK: machine.LCD_SCK_PIN,
|
||||||
|
SDO: machine.LCD_SDO_PIN,
|
||||||
|
SDI: machine.LCD_SDI_PIN,
|
||||||
|
Frequency: 40000000,
|
||||||
|
})
|
||||||
|
display.Configure(ili9341.Config{})
|
||||||
|
|
||||||
|
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI3,
|
|
||||||
machine.LCD_DC,
|
|
||||||
machine.LCD_SS_PIN,
|
|
||||||
machine.LCD_RESET,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.LCD_BACKLIGHT
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
machine.SPI3.Configure(machine.SPIConfig{
|
|
||||||
SCK: machine.LCD_SCK_PIN,
|
|
||||||
SDO: machine.LCD_SDO_PIN,
|
|
||||||
SDI: machine.LCD_SDI_PIN,
|
|
||||||
Frequency: 40000000,
|
|
||||||
})
|
|
||||||
display.Configure(ili9341.Config{})
|
|
||||||
|
|
||||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
if debug {
|
|
||||||
waitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"machine"
|
||||||
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// You can override the setting with the init() in another source code.
|
// You can override the setting with the init() in another source code.
|
||||||
@@ -36,19 +38,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
if err != nil {
|
adaptor.Configure()
|
||||||
return err
|
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
http.SetBuf(buf[:])
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
// You can override the setting with the init() in another source code.
|
// You can override the setting with the init() in another source code.
|
||||||
@@ -37,18 +38,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||||
if err != nil {
|
adaptor.Configure()
|
||||||
return err
|
|
||||||
}
|
|
||||||
http.UseDriver(rtl)
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
http.UseDriver(adaptor)
|
||||||
|
|
||||||
|
err := adaptor.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
ip, subnet, gateway, err := adaptor.GetIP()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
if debug {
|
|
||||||
waitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package rtl8720dn
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
debug bool
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Setup() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
if debug {
|
|
||||||
waitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
func Debug(b bool) {
|
|
||||||
debug = b
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user