test: fix _embdemo
This commit is contained in:
16
_embdemo/hello-esp32/main.go
Normal file
16
_embdemo/hello-esp32/main.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/goplus/lib/c"
|
||||||
|
|
||||||
|
func myprint(s *c.Char) {
|
||||||
|
for i := 0; i < int(c.Strlen(s)); i++ {
|
||||||
|
WriteByte(byte(c.Index(s, i)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
for {
|
||||||
|
myprint(c.Str("hello world"))
|
||||||
|
sleep(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
13
_embdemo/hello-esp32/uart.go
Normal file
13
_embdemo/hello-esp32/uart.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "unsafe"
|
||||||
|
|
||||||
|
"github.com/goplus/lib/c"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:linkname WriteByte C.board_uart_write_char
|
||||||
|
func WriteByte(b byte)
|
||||||
|
|
||||||
|
//go:linkname sleep sleep
|
||||||
|
func sleep(c c.Int)
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
func myprint(s string) {
|
|
||||||
for i := 0; i < len(s); i++ {
|
|
||||||
WriteByte(s[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
myprint("hello world")
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
//go:linkname WriteByte C.board_uart_write_char
|
|
||||||
func WriteByte(b byte)
|
|
||||||
12
_embdemo/write-esp32/main.go
Normal file
12
_embdemo/write-esp32/main.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/goplus/lib/c"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
buf := c.Malloc(6)
|
||||||
|
c.Memset(buf, 0, 6)
|
||||||
|
c.Strncpy((*c.Char)(buf), c.Str("abcde"), 5)
|
||||||
|
|
||||||
|
write(1, (*c.Char)(buf), 5)
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user