mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-04 15:07:46 +00:00
8642886f73f4f85000773c2eafc02274d5bf2163
According to man page accept(2), accept returns new client sockfd and remote peer ip:port. This patch corrects the Accept() prototype in the netdever interface to not take in an ip:port arg, but rather return an ip:port for remote peer. Tested with examples/net/tcpecho on wioterminal and nano-rp2040. Here's a run with wioterminal: SERVER ============ sfeldma@nuc:~/work/drivers$ tinygo flash -monitor -target wioterminal -size short -stack-size=8kb ./examples/net/tcpecho code data bss | flash ram 110876 2552 11212 | 113428 13764 Connected to /dev/ttyACM2. Press Ctrl-C to exit. Realtek rtl8720dn Wifi network device driver (rtl8720dn) Driver version : 0.0.1 RTL8720 firmware version : 2.1.2 MAC address : 2c:f7:f1:1c:9b:2f Connecting to Wifi SSID 'test'...CONNECTED DHCP-assigned IP : 10.0.0.140 DHCP-assigned subnet : 255.255.255.0 DHCP-assigned gateway : 10.0.0.1 Starting TCP server listening on :8080 Client 10.0.0.190:50000 connected Client 10.0.0.190:50000 closed CLIENT ============= nc -p 50000 10.0.0.140 8080
TinyGo Drivers
This package provides a collection of 101 different hardware drivers for devices such as sensors and displays that can be used together with TinyGo.
For the complete list, please see: https://tinygo.org/docs/reference/devices/
Installing
go get tinygo.org/x/drivers
How to use
Here is an example in TinyGo that uses the BMP180 digital barometer:
package main
import (
"time"
"machine"
"tinygo.org/x/drivers/bmp180"
)
func main() {
machine.I2C0.Configure(machine.I2CConfig{})
sensor := bmp180.New(machine.I2C0)
sensor.Configure()
connected := sensor.Connected()
if !connected {
println("BMP180 not detected")
return
}
println("BMP180 detected")
for {
temp, _ := sensor.ReadTemperature()
println("Temperature:", float32(temp)/1000, "°C")
pressure, _ := sensor.ReadPressure()
println("Pressure", float32(pressure)/100000, "hPa")
time.Sleep(2 * time.Second)
}
}
Contributing
Your contributions are welcome!
Please take a look at our CONTRIBUTING.md document for details.
License
This project is licensed under the BSD 3-clause license, just like the Go project itself.
Releases
10
Languages
Go
99.1%
Shell
0.7%