File tree Expand file tree Collapse file tree 2 files changed +119
-0
lines changed Expand file tree Collapse file tree 2 files changed +119
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "time"
6+
7+ "tinygo.org/x/drivers/examples/rtl8720dn"
8+ )
9+
10+ var (
11+ debug = false
12+ )
13+
14+ func main () {
15+ err := run ()
16+ for err != nil {
17+ fmt .Printf ("error: %s\r \n " , err .Error ())
18+ time .Sleep (5 * time .Second )
19+ }
20+ }
21+
22+ func run () error {
23+ //rtl8720dn.Debug(true)
24+ rtl , err := rtl8720dn .Setup ()
25+ if err != nil {
26+ return err
27+ }
28+
29+ ver , err := rtl .Version ()
30+ if err != nil {
31+ return nil
32+ }
33+
34+ for {
35+ fmt .Printf ("RTL8270DN Firmware Version: %s\r \n " , ver )
36+ time .Sleep (10 * time .Second )
37+ }
38+
39+ return nil
40+ }
Original file line number Diff line number Diff line change 1+ //go:build wioterminal
2+ // +build wioterminal
3+
4+ package rtl8720dn
5+
6+ import (
7+ "device/sam"
8+ "machine"
9+ "runtime/interrupt"
10+ "time"
11+
12+ "tinygo.org/x/drivers/rtl8720dn"
13+ )
14+
15+ var (
16+ uart UARTx
17+ debug bool
18+ )
19+
20+ func handleInterrupt (interrupt.Interrupt ) {
21+ // should reset IRQ
22+ uart .Receive (byte ((uart .Bus .DATA .Get () & 0xFF )))
23+ uart .Bus .INTFLAG .SetBits (sam .SERCOM_USART_INT_INTFLAG_RXC )
24+ }
25+
26+ func Setup () (* rtl8720dn.RTL8720DN , error ) {
27+ machine .RTL8720D_CHIP_PU .Configure (machine.PinConfig {Mode : machine .PinOutput })
28+ machine .RTL8720D_CHIP_PU .Low ()
29+ time .Sleep (100 * time .Millisecond )
30+ machine .RTL8720D_CHIP_PU .High ()
31+ time .Sleep (1000 * time .Millisecond )
32+ if debug {
33+ waitSerial ()
34+ }
35+
36+ uart = UARTx {
37+ UART : & machine.UART {
38+ Buffer : machine .NewRingBuffer (),
39+ Bus : sam .SERCOM0_USART_INT ,
40+ SERCOM : 0 ,
41+ },
42+ }
43+
44+ uart .Interrupt = interrupt .New (sam .IRQ_SERCOM0_2 , handleInterrupt )
45+ uart .Configure (machine.UARTConfig {TX : machine .PB24 , RX : machine .PC24 , BaudRate : 614400 })
46+
47+ rtl := rtl8720dn .New (uart )
48+ rtl .Debug (debug )
49+
50+ _ , err := rtl .Rpc_tcpip_adapter_init ()
51+ if err != nil {
52+ return nil , err
53+ }
54+
55+ return rtl , nil
56+ }
57+
58+ // Wait for user to open serial console
59+ func waitSerial () {
60+ for ! machine .Serial .DTR () {
61+ time .Sleep (100 * time .Millisecond )
62+ }
63+ }
64+
65+ type UARTx struct {
66+ * machine.UART
67+ }
68+
69+ func (u UARTx ) Read (p []byte ) (n int , err error ) {
70+ if u .Buffered () == 0 {
71+ time .Sleep (1 * time .Millisecond )
72+ return 0 , nil
73+ }
74+ return u .UART .Read (p )
75+ }
76+
77+ func Debug (b bool ) {
78+ debug = b
79+ }
You can’t perform that action at this time.
0 commit comments