rtl8720dn: refactor by bringing this driver more in line with wifinina and espat

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2022-08-28 10:40:36 +02:00
committed by Ron Evans
parent 6f05615f3e
commit 54ddb895cc
6 changed files with 171 additions and 199 deletions
+38 -6
View File
@@ -1,25 +1,57 @@
package rtl8720dn
import (
"machine"
"time"
"tinygo.org/x/drivers/net"
)
func (r *RTL8720DN) ConnectToAccessPoint(ssid, pass string, timeout time.Duration) error {
type Driver struct {
*RTL8720DN
}
// New returns a new RTL8720DN driver. The UART that is passed in
// will be reconfigured at the baud rate required by the device.
func New(uart *machine.UART, tx, rx, en machine.Pin) *Driver {
enable(en)
uart.Configure(machine.UARTConfig{TX: tx, RX: rx, BaudRate: 614400})
return &Driver{
RTL8720DN: &RTL8720DN{
port: &UARTx{UART: uart},
seq: 1,
sema: make(chan bool, 1),
debug: false,
},
}
}
func (d *Driver) Configure() error {
net.UseDriver(d)
_, err := d.Rpc_tcpip_adapter_init()
if err != nil {
return err
}
return nil
}
func (d *Driver) ConnectToAccessPoint(ssid, pass string, timeout time.Duration) error {
if len(ssid) == 0 {
return net.ErrWiFiMissingSSID
}
return r.ConnectToAP(ssid, pass)
return d.ConnectToAP(ssid, pass)
}
func (r *RTL8720DN) Disconnect() error {
_, err := r.Rpc_wifi_disconnect()
func (d *Driver) Disconnect() error {
_, err := d.Rpc_wifi_disconnect()
return err
}
func (r *RTL8720DN) GetClientIP() (string, error) {
ip, _, _, err := r.GetIP()
func (d *Driver) GetClientIP() (string, error) {
ip, _, _, err := d.GetIP()
return ip.String(), err
}