Driver for the Wifi+bluetooth integrated circuit on the pico.
To run the blinky example:
tinygo flash -target=pico -stack-size=8kb -monitor ./examples/blinky
To run Wifi examples you must first set your wifi credentials: |
---|
-
Clone this repository
-
Rename
examples/common/secrets.go.template
to have the.go
extension and edit the contents withssid
andpass
strings set to your WIFI SSID and Password, respecively. Ifpass
is not set then an open network is assumed. -
Run any of the examples in the
examples
directoryExample of how to run the DHCP example:
tinygo flash -target=pico -stack-size=8kb -monitor ./examples/dhcp
The examples use the soypat/seqs
networking stack library. One can enable heap debugging by using the debugheaplog
build tag:
Example:
tinygo flash -target=pico -stack-size=8kb -monitor -tags=debugheaplog ./examples/dhcp
This will use a simpler logger implementation within the seqs
package that avoids all allocations and will also log heap increments on lines starting with the [ALLOC]
text.
PRs welcome! Please read most recent developments on this issue before contributing.
-
-
cyw43_driver/cyw43_bus_pio_spi.c
: Core driver for interfacing directly with the CYW43439. This is what this repo will target in the port. -
pico_cyw43_arch
: Architecture for integrating the CYW43 driver (for the wireless on Pico W) and lwIP (for TCP/IP stack) into the SDK. It is also necessary for accessing the on-board LED on Pico W.pico_cyw43_arch/include/pico/cyw43_arch.h
: Headers for the architecture driver. Has a very complete comment introducing the architecture library.
Examples:
- APA102 addressable LED strip.
- Here is the Go driver: well programmed and simple. Follows good practices like storing buffers in-struct as arrays (
buf
field) to avoid heap allocations and encouraging better CPU memory access patterns. - I could not find a high quality C or C++ driver, there seems to be a different driver for each microcontroller. Here's an ESP8266 driver for the APA102 which seemed reasonably well programmed.
- Here is the Go driver: well programmed and simple. Follows good practices like storing buffers in-struct as arrays (
- Wifinina SPI driver for ESP32 wifi with TCP/IP.
The CYW43439 driver will have minimal microcontroller side API code, though it does not hurt to read up a little bit on it.
It may be of interest to the reader to know a bit of how one ports microcontroller specific code from C to Go. This code is characterized by the heavy use of volatile memory registers and data structures that map peripheral functionality directly to these segments of volatile memory.
For the case of the RP2040 (the raspberry pi's pico microcontroller) one can find most of microcontroller specific code in the TinyGo machine
package- Look for filenames starting with machine_rp2040
. In the author's opinion one of the cleanest peripheral API's is the RP2040's I2C driver, which you may find in machine_rp2040_i2c.go
in said package.
The C counterparts are in the pico-sdk's rp2_common
directory. The I2C counterpart includes the header file with function signatures and type definitions... and more interestingly, the actual code under hardware_i2c/i2c.c
. Do note the port is almost direct. Some functions have been grouped differently and have slightly different signatures in the Go
version.
The PWM API is much more closely matched between the C and Go version, albeit much simpler.
go install golang.org/x/tools/cmd/stringer@latest