mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-27 11:08:41 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f94ef9e535 |
@@ -1,68 +1,3 @@
|
||||
0.23.0
|
||||
---
|
||||
- **new devices**
|
||||
- Add GC9A01 Driver (#452)
|
||||
- Initial support for VL6180x sensor
|
||||
|
||||
- **enhancements**
|
||||
- **rtl8720dn**
|
||||
- refactor by bringing this driver more in line with wifinina and espat
|
||||
- **ssd1306**
|
||||
- add getter method to the current buffer
|
||||
- **makeybutton**
|
||||
- revise to better match the algorithm defined by the original
|
||||
- **espat,wifinina,rtl8720dn**
|
||||
- change ssid/pass from const to var
|
||||
|
||||
- **bugfixes**
|
||||
- **microbitmatrix**
|
||||
- fix inverted axis
|
||||
- **espat**
|
||||
- Trim quotes from IP returned by espat's GetDNS()
|
||||
- **all**
|
||||
- correct go fmt
|
||||
|
||||
- **examples**
|
||||
- **rtl8720dn**
|
||||
- remove wifi setting
|
||||
- add call to optional debug setting
|
||||
- update all remaining examples for refactored API
|
||||
|
||||
|
||||
0.22.0
|
||||
---
|
||||
- **new devices**
|
||||
- epd: add waveshare 2.9in (v1)
|
||||
- makeybutton: add driver for MakeyMakey-like button
|
||||
|
||||
- **enhancements**
|
||||
- **rtl8720dn**
|
||||
- add UDP close function
|
||||
- improve error handling
|
||||
- **net/http**
|
||||
- improve header parsing
|
||||
- add last-will-and-testament to MQTT
|
||||
- **net/mqtt**
|
||||
- adds keepalive pinging, disconnect, and graceful goroutine cleanup
|
||||
- support for cookies when https
|
||||
- add support for retained messsages
|
||||
|
||||
- **bugfixes**
|
||||
- irremote: Fix irremote reporting incorrect NEC addresses and command codes (#422)
|
||||
- net/http: Fix http.Get() with port specification
|
||||
|
||||
- **build**
|
||||
- Makefile recursively finds unit-tests
|
||||
- switching to GHA
|
||||
|
||||
- **updates**
|
||||
- update tinyfont to v0.3.0
|
||||
- update tinyfs to v0.2.0
|
||||
|
||||
- **examples**
|
||||
- rtl8720dn: add ./examples/rtl8720dn/version
|
||||
|
||||
|
||||
0.21.0
|
||||
---
|
||||
- **new devices**
|
||||
|
||||
@@ -53,8 +53,6 @@ smoke-test:
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/i2c/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/gps/uart/main.go
|
||||
@@ -103,8 +101,6 @@ smoke-test:
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/microbitmatrix/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit-v2 ./examples/microbitmatrix/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mma8653/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/mpu6050/main.go
|
||||
@@ -147,8 +143,6 @@ smoke-test:
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl53l1x/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/vl6180x/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=microbit ./examples/waveshare-epd/epd2in13x/main.go
|
||||
@@ -211,8 +205,6 @@ endif
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=xiao ./examples/pcf8563/timer/
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=pico ./examples/qmi8658c/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=feather-m0 ./examples/ina260/main.go
|
||||
@md5sum ./build/test.hex
|
||||
tinygo build -size short -o ./build/test.hex -target=nucleo-l432kc ./examples/aht20/main.go
|
||||
|
||||
@@ -52,7 +52,7 @@ func main() {
|
||||
|
||||
## Currently supported devices
|
||||
|
||||
The following 90 devices are supported.
|
||||
The following 81 devices are supported.
|
||||
|
||||
| Device Name | Interface Type |
|
||||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
|
||||
@@ -97,10 +97,10 @@ The following 90 devices are supported.
|
||||
| [LPS22HB MEMS nano pressure sensor](https://www.st.com/resource/en/datasheet/dm00140895.pdf) | I2C |
|
||||
| [LSM6DS3 accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3.pdf) | I2C |
|
||||
| [LSM6DSOX accelerometer](https://www.st.com/resource/en/datasheet/lsm6dsox.pdf) | I2C |
|
||||
| [LSM6DS3TR accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3tr.pdf) | I2C |
|
||||
| [LSM6DS3TR accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3tr.pdf) | I2C |
|
||||
| [LSM303AGR accelerometer](https://www.st.com/resource/en/datasheet/lsm303agr.pdf) | I2C |
|
||||
| [LSM9DS1 accelerometer](https://www.st.com/resource/en/datasheet/lsm9ds1.pdf) | I2C |
|
||||
| [Makey Button](https://makeymakey.com/) | GPIO |
|
||||
| [Makey Button](https://makeymakey.com/) | GPIO |
|
||||
| [MAG3110 magnetometer](https://www.nxp.com/docs/en/data-sheet/MAG3110.pdf) | I2C |
|
||||
| [MAX7219 & MAX7221 display driver](https://datasheets.maximintegrated.com/en/ds/MAX7219-MAX7221.pdf) | SPI |
|
||||
| [MCP2515 Stand-Alone CAN Controller with SPI Interface](https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Family-Data-Sheet-DS20001801K.pdf) | SPI |
|
||||
@@ -112,10 +112,9 @@ The following 90 devices are supported.
|
||||
| [P1AM-100 Base Controller](https://facts-engineering.github.io/modules/P1AM-100/P1AM-100.html) | SPI |
|
||||
| [PCD8544 display](http://eia.udg.edu/~forest/PCD8544_1.pdf) | SPI |
|
||||
| [PCF8563 real time clock](https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf) | I2C |
|
||||
| [QMI8658C accelerometer/gyroscope](https://www.qstcorp.com/upload/pdf/202202/%EF%BC%88%E5%B7%B2%E4%BC%A0%EF%BC%89QMI8658C%20datasheet%20rev%200.9.pdf) | I2C |
|
||||
| [Resistive Touchscreen (4-wire)](http://ww1.microchip.com/downloads/en/Appnotes/doc8091.pdf) | GPIO |
|
||||
| [RTL8720DN 2.4G/5G Dual Bands Wireless and BLE5.0](https://www.seeedstudio.com/Realtek8720DN-2-4G-5G-Dual-Bands-Wireless-and-BLE5-0-Combo-Module-p-4442.html) | UART |
|
||||
| [SCD4x CO2 Sensor](https://sensirion.com/media/documents/C4B87CE6/627C2DCD/CD_DS_SCD40_SCD41_Datasheet_D1.pdf) | I2C |
|
||||
| [SCD4x CO2 Sensor](https://sensirion.com/media/documents/C4B87CE6/627C2DCD/CD_DS_SCD40_SCD41_Datasheet_D1.pdf) | I2C |
|
||||
| [Semihosting](https://wiki.segger.com/Semihosting) | Debug |
|
||||
| [Servo](https://learn.sparkfun.com/tutorials/hobby-servo-tutorial/all) | PWM |
|
||||
| [Shift register (PISO)](https://en.wikipedia.org/wiki/Shift_register#Parallel-in_serial-out_\(PISO\)) | GPIO |
|
||||
@@ -133,15 +132,12 @@ The following 90 devices are supported.
|
||||
| [Thermistor](https://www.farnell.com/datasheets/33552.pdf) | ADC |
|
||||
| [TM1637 7-segment LED display](https://www.mcielectronics.cl/website_MCI/static/documents/Datasheet_TM1637.pdf) | I2C |
|
||||
| [TMP102 I2C Temperature Sensor](https://download.mikroe.com/documents/datasheets/tmp102-data-sheet.pdf) | I2C |
|
||||
| [UC8151 All-in-one driver IC for ESL](https://www.buydisplay.com/download/ic/UC8151C.pdf) | I2C |
|
||||
| [UC8151 All-in-one driver IC for ESL](https://www.buydisplay.com/download/ic/UC8151C.pdf) | I2C |
|
||||
| [VEML6070 UV light sensor](https://www.vishay.com/docs/84277/veml6070.pdf) | I2C |
|
||||
| [VL53L1X time-of-flight distance sensor](https://www.st.com/resource/en/datasheet/vl53l1x.pdf) | I2C |
|
||||
| [VL6180X time-of-flight distance sensor](https://www.st.com/resource/en/datasheet/vl6180x.pdf) | I2C |
|
||||
| [Waveshare 2.13" (B & C) e-paper display](https://www.waveshare.com/w/upload/d/d3/2.13inch-e-paper-b-Specification.pdf) | SPI |
|
||||
| [Waveshare 2.13" e-paper display](https://www.waveshare.com/w/upload/e/e6/2.13inch_e-Paper_Datasheet.pdf) | SPI |
|
||||
| [Waveshare 2.9" e-paper display (V1)](https://www.waveshare.com/w/upload/e/e6/2.9inch_e-Paper_Datasheet.pdf) | SPI |
|
||||
| [Waveshare 4.2" e-paper B/W display](https://www.waveshare.com/w/upload/6/6a/4.2inch-e-paper-specification.pdf) | SPI |
|
||||
| [Waveshare GC9A01 TFT round display](https://www.waveshare.com/w/upload/5/5e/GC9A01A.pdf) | SPI |
|
||||
| [WS2812 RGB LED](https://cdn-shop.adafruit.com/datasheets/WS2812.pdf) | GPIO |
|
||||
| [XPT2046 touch controller](http://grobotronics.com/images/datasheets/xpt2046-datasheet.pdf) | GPIO |
|
||||
| [Semtech SX126x Lora](https://www.semtech.com/products/wireless-rf/lora-transceiv-ers/sx1261) | SPI |
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package adt7410 provides a driver for the adt7410 I2C Temperature Sensor.
|
||||
//
|
||||
// Datasheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf
|
||||
//
|
||||
package adt7410 // import "tinygo.org/x/drivers/adt7410"
|
||||
|
||||
import (
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Datasheet EN: http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf
|
||||
//
|
||||
// Datasheet JP: http://www.analog.com/media/jp/technical-documentation/data-sheets/ADXL345_jp.pdf
|
||||
//
|
||||
package adxl345 // import "tinygo.org/x/drivers/adxl345"
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// a digital proximity, ambient light, RGB and gesture sensor.
|
||||
//
|
||||
// Datasheet: https://cdn.sparkfun.com/assets/learn_tutorials/3/2/1/Avago-APDS-9960-datasheet.pdf
|
||||
//
|
||||
package apds9960
|
||||
|
||||
import (
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
package apds9960
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
// Configure sets up the APDS-9960 device.
|
||||
func (d *Device) Configure(cfg Configuration) {
|
||||
// configure device
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// http://www.x-powers.com/en.php/Info/product_detail/article_id/29
|
||||
// Datasheet: https://github.com/m5stack/M5-Schematic/blob/master/Core/AXP192%20Datasheet_v1.1_en_draft_2211.pdf
|
||||
//
|
||||
package axp192 // import "tinygo.org/x/drivers/axp192"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//
|
||||
// Datasheet:
|
||||
// https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf
|
||||
//
|
||||
package bh1750 // import "tinygo.org/x/drivers/bh1750"
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package blinkm implements a driver for the BlinkM I2C RGB LED.
|
||||
//
|
||||
// Datasheet: http://thingm.com/fileadmin/thingm/downloads/BlinkM_datasheet.pdf
|
||||
//
|
||||
package blinkm // import "tinygo.org/x/drivers/blinkm"
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
+2
-2
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// Datasheet:
|
||||
// https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf
|
||||
//
|
||||
package bme280
|
||||
|
||||
import (
|
||||
@@ -148,8 +149,7 @@ func (d *Device) ReadHumidity() (int32, error) {
|
||||
// ReadAltitude returns the current altitude in meters based on the
|
||||
// current barometric pressure and estimated pressure at sea level.
|
||||
// Calculation is based on code from Adafruit BME280 library
|
||||
//
|
||||
// https://github.com/adafruit/Adafruit_BME280_Library
|
||||
// https://github.com/adafruit/Adafruit_BME280_Library
|
||||
func (d *Device) ReadAltitude() (alt int32, err error) {
|
||||
mPa, _ := d.ReadPressure()
|
||||
atmP := float32(mPa) / 100000
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// Datasheet:
|
||||
// https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
|
||||
//
|
||||
package bmp180 // import "tinygo.org/x/drivers/bmp180"
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Package buzzer provides a very simplistic driver for a connected buzzer or low-fidelity speaker.
|
||||
//
|
||||
package buzzer // import "tinygo.org/x/drivers/buzzer"
|
||||
|
||||
import (
|
||||
|
||||
+8
-7
@@ -3,22 +3,22 @@
|
||||
//
|
||||
// Here is an example in TinyGo that uses the BMP180 digital barometer:
|
||||
//
|
||||
// package main
|
||||
// package main
|
||||
//
|
||||
// import (
|
||||
// import (
|
||||
// "time"
|
||||
// "machine"
|
||||
//
|
||||
// "tinygo.org/x/drivers/bmp180"
|
||||
// )
|
||||
// "tinygo.org/x/drivers/bmp180"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
// func main() {
|
||||
// machine.I2C0.Configure(machine.I2CConfig{})
|
||||
// sensor := bmp180.New(machine.I2C0)
|
||||
// sensor.Configure()
|
||||
//
|
||||
// connected := sensor.Connected()
|
||||
// if !connected {
|
||||
// connected := sensor.Connected()
|
||||
// if !connected {
|
||||
// println("BMP180 not detected")
|
||||
// return
|
||||
// }
|
||||
@@ -38,4 +38,5 @@
|
||||
// Each individual driver is contained within its own sub-package within this package and
|
||||
// there are no interdependencies in order to minimize the final size of compiled code that
|
||||
// uses any of these drivers.
|
||||
//
|
||||
package drivers // import "tinygo.org/x/drivers"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//
|
||||
// Datasheet:
|
||||
// https://datasheets.maximintegrated.com/en/ds/DS1307.pdf
|
||||
//
|
||||
package ds1307 // import "tinygo.org/x/drivers/ds1307"
|
||||
|
||||
import (
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
//
|
||||
// AT command set:
|
||||
// https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
|
||||
//
|
||||
package espat // import "tinygo.org/x/drivers/espat"
|
||||
|
||||
import (
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ func (d *Device) GetDNS(domain string) (string, error) {
|
||||
return "", errors.New("Invalid domain lookup result")
|
||||
}
|
||||
res := strings.Split(r[1], "\r\n")
|
||||
return strings.Trim(res[0], `"`), nil
|
||||
return res[0], nil
|
||||
}
|
||||
|
||||
// ConnectTCPSocket creates a new TCP socket connection for the ESP8266/ESP32.
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
//
|
||||
// More information on the Espressif AT command set at:
|
||||
// https://www.espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -18,11 +19,9 @@ import (
|
||||
// change actAsAP to true to act as an access point instead of connecting to one.
|
||||
const actAsAP = false
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = "YOURSSID"
|
||||
const pass = "YOURPASS"
|
||||
|
||||
// these are the default pins for the Arduino Nano33 IoT.
|
||||
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// In other words:
|
||||
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266 <--> INTERNET
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -16,11 +17,9 @@ import (
|
||||
// change actAsAP to true to act as an access point instead of connecting to one.
|
||||
const actAsAP = false
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = "YOURSSID"
|
||||
const pass = "YOURPASS"
|
||||
|
||||
// these are the default pins for the Arduino Nano33 IoT.
|
||||
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// In other words:
|
||||
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,11 +14,9 @@ import (
|
||||
"tinygo.org/x/drivers/net"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = "YOURSSID"
|
||||
const pass = "YOURPASS"
|
||||
|
||||
// IP address of the listener aka "hub". Replace with your own info.
|
||||
const hubIP = "0.0.0.0"
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//
|
||||
// You must install the Paho MQTT package to build this program:
|
||||
//
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -19,11 +20,9 @@ import (
|
||||
"tinygo.org/x/drivers/net/mqtt"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = "YOURSSID"
|
||||
const pass = "YOURPASS"
|
||||
|
||||
// IP address of the MQTT broker to use. Replace with your own info.
|
||||
const server = "tcp://test.mosquitto.org:1883"
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//
|
||||
// You must also install the Paho MQTT package to build this program:
|
||||
//
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -20,11 +21,9 @@ import (
|
||||
"tinygo.org/x/drivers/net/mqtt"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = "YOURSSID"
|
||||
const pass = "YOURPASS"
|
||||
|
||||
// IP address of the MQTT broker to use. Replace with your own info.
|
||||
//const server = "tcp://test.mosquitto.org:1883"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// In other words:
|
||||
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,11 +14,9 @@ import (
|
||||
"tinygo.org/x/drivers/net"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = "YOURSSID"
|
||||
const pass = "YOURPASS"
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const serverIP = "0.0.0.0"
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"image/color"
|
||||
|
||||
"tinygo.org/x/drivers/gc9a01"
|
||||
)
|
||||
|
||||
func main() {
|
||||
machine.SPI0.Configure(machine.SPIConfig{
|
||||
Frequency: 80000000,
|
||||
})
|
||||
display := gc9a01.New(machine.SPI0, machine.P6, machine.P7, machine.P8, machine.P9)
|
||||
display.Configure(gc9a01.Config{Orientation: gc9a01.HORIZONTAL, Width: 240, Height: 240})
|
||||
|
||||
width, height := display.Size()
|
||||
|
||||
white := color.RGBA{255, 255, 255, 255}
|
||||
red := color.RGBA{255, 0, 0, 255}
|
||||
blue := color.RGBA{0, 0, 255, 255}
|
||||
green := color.RGBA{0, 255, 0, 255}
|
||||
black := color.RGBA{0, 0, 0, 255}
|
||||
|
||||
display.FillScreen(black)
|
||||
|
||||
display.FillRectangle(0, 0, width/2, height/2, white)
|
||||
display.FillRectangle(width/2, 0, width/2, height/2, red)
|
||||
display.FillRectangle(0, height/2, width/2, height/2, green)
|
||||
display.FillRectangle(width/2, height/2, width/2, height/2, blue)
|
||||
display.FillRectangle(width/4, height/4, width/2, height/2, black)
|
||||
|
||||
for {
|
||||
time.Sleep(time.Hour)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
"tinygo.org/x/drivers/ili9341"
|
||||
)
|
||||
|
||||
var ()
|
||||
|
||||
func InitDisplay() *ili9341.Device {
|
||||
machine.SPI0.Configure(machine.SPIConfig{
|
||||
SCK: machine.SPI0_SCK_PIN,
|
||||
|
||||
@@ -9,14 +9,14 @@ import (
|
||||
|
||||
var (
|
||||
led machine.Pin = machine.LED
|
||||
button machine.Pin = machine.D10
|
||||
button machine.Pin = machine.BUTTON
|
||||
key *makeybutton.Button
|
||||
)
|
||||
|
||||
func main() {
|
||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||||
key = makeybutton.NewButton(button)
|
||||
key.Configure()
|
||||
|
||||
for {
|
||||
switch key.Get() {
|
||||
@@ -25,7 +25,6 @@ func main() {
|
||||
case makeybutton.Released:
|
||||
led.Low()
|
||||
}
|
||||
// the more frequent the more responsive
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// to read data from the onboard MEMS microphone.
|
||||
//
|
||||
// Uses ideas from the https://github.com/adafruit/Adafruit_CircuitPlayground repo.
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
// Connects to an QMI8658C I2C accelerometer/gyroscope and print the read data.
|
||||
// This example was made with the "WaveShare RP2040 Round LCD 1.28in" in mind.
|
||||
// For more infor about this development board:
|
||||
// https://www.waveshare.com/wiki/RP2040-LCD-1.28
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
imu "tinygo.org/x/drivers/qmi8658c"
|
||||
)
|
||||
|
||||
func main() {
|
||||
i2c := machine.I2C1
|
||||
// This is the default pinout for the "WaveShare RP2040 Round LCD 1.28in"
|
||||
err := i2c.Configure(machine.I2CConfig{
|
||||
SDA: machine.GP6,
|
||||
SCL: machine.GP7,
|
||||
Frequency: 100000,
|
||||
})
|
||||
if err != nil {
|
||||
println("unable to configure I2C:", err)
|
||||
return
|
||||
}
|
||||
// Create a new device
|
||||
d := imu.New(i2c)
|
||||
|
||||
// Check if the device is connected
|
||||
if !d.Connected() {
|
||||
println("unable to connect to sensor")
|
||||
return
|
||||
}
|
||||
|
||||
// This IMU has multiple configurations like output data rate, multiple
|
||||
// measurements scales, low pass filters, low power modes, all the vailable
|
||||
// values can be found in the datasheet and were defined at registers file.
|
||||
// This is the default configuration which will be used if the `nil` value
|
||||
// is passed do the `Configure` method.
|
||||
config := imu.Config{
|
||||
SPIMode: imu.SPI_4_WIRE,
|
||||
SPIEndian: imu.SPI_BIG_ENDIAN,
|
||||
SPIAutoInc: imu.SPI_AUTO_INC,
|
||||
AccEnable: imu.ACC_ENABLE,
|
||||
AccScale: imu.ACC_8G,
|
||||
AccRate: imu.ACC_NORMAL_1000HZ,
|
||||
AccLowPass: imu.ACC_LOW_PASS_2_62,
|
||||
GyroEnable: imu.GYRO_FULL_ENABLE,
|
||||
GyroScale: imu.GYRO_512DPS,
|
||||
GyroRate: imu.GYRO_1000HZ,
|
||||
GyroLowPass: imu.GYRO_LOW_PASS_2_62,
|
||||
}
|
||||
d.Configure(config)
|
||||
|
||||
// Read the accelation, rotation and temperature data and print them.
|
||||
for {
|
||||
acc_x, acc_y, acc_z := d.ReadAcceleration()
|
||||
gyro_x, gyro_y, gyro_z := d.ReadRotation()
|
||||
temp, _ := d.ReadTemperature()
|
||||
println("-------------------------------")
|
||||
println("acc:", acc_x, acc_y, acc_z)
|
||||
println("gyro:", gyro_x, gyro_y, gyro_z)
|
||||
println("temp:", temp)
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
}
|
||||
}
|
||||
@@ -7,16 +7,15 @@
|
||||
//
|
||||
// You must install the Paho MQTT package to build this program:
|
||||
//
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
//
|
||||
// You can check that mqttpub is running successfully with the following command.
|
||||
//
|
||||
// mosquitto_sub -h test.mosquitto.org -t tinygo
|
||||
// mosquitto_sub -h test.mosquitto.org -t tinygo
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
@@ -29,23 +28,23 @@ import (
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// debug = true
|
||||
// server = "tinygo.org"
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
server string = "tcp://test.mosquitto.org:1883"
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
server string = "tcp://test.mosquitto.org:1883"
|
||||
debug = false
|
||||
)
|
||||
|
||||
var buf [0x400]byte
|
||||
|
||||
var lastRequestTime time.Time
|
||||
var conn net.Conn
|
||||
var adaptor *rtl8720dn.Driver
|
||||
var adaptor *rtl8720dn.RTL8720DN
|
||||
|
||||
func main() {
|
||||
err := run()
|
||||
@@ -60,17 +59,18 @@ var (
|
||||
)
|
||||
|
||||
func run() error {
|
||||
// change the UART and pins as needed for platforms other than the WioTerminal.
|
||||
adaptor = rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
rtl, err := setupRTL8720DN()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
net.UseDriver(rtl)
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
ip, subnet, gateway, err := rtl.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
uart UARTx
|
||||
)
|
||||
|
||||
func handleInterrupt(interrupt.Interrupt) {
|
||||
// should reset IRQ
|
||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
||||
}
|
||||
|
||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
machine.RTL8720D_CHIP_PU.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.RTL8720D_CHIP_PU.High()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
if debug {
|
||||
waitSerial()
|
||||
}
|
||||
|
||||
uart = UARTx{
|
||||
UART: &machine.UART{
|
||||
Buffer: machine.NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
},
|
||||
}
|
||||
|
||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
||||
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
func waitSerial() {
|
||||
for !machine.Serial.DTR() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
type UARTx struct {
|
||||
*machine.UART
|
||||
}
|
||||
|
||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
||||
if u.Buffered() == 0 {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return 0, nil
|
||||
}
|
||||
return u.UART.Read(p)
|
||||
}
|
||||
@@ -7,17 +7,16 @@
|
||||
//
|
||||
// You must also install the Paho MQTT package to build this program:
|
||||
//
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
//
|
||||
// You can check that mqttpub/mqttsub is running successfully with the following command.
|
||||
//
|
||||
// mosquitto_sub -h test.mosquitto.org -t tinygo/tx
|
||||
// mosquitto_pub -h test.mosquitto.org -t tinygo/rx -m "hello world"
|
||||
// mosquitto_sub -h test.mosquitto.org -t tinygo/tx
|
||||
// mosquitto_pub -h test.mosquitto.org -t tinygo/rx -m "hello world"
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
@@ -30,23 +29,23 @@ import (
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// debug = true
|
||||
// server = "tinygo.org"
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
server string = "tcp://test.mosquitto.org:1883"
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
server string = "tcp://test.mosquitto.org:1883"
|
||||
debug = false
|
||||
)
|
||||
|
||||
var buf [0x400]byte
|
||||
|
||||
var lastRequestTime time.Time
|
||||
var conn net.Conn
|
||||
var adaptor *rtl8720dn.Driver
|
||||
var adaptor *rtl8720dn.RTL8720DN
|
||||
|
||||
func main() {
|
||||
err := run()
|
||||
@@ -69,17 +68,18 @@ func subHandler(client mqtt.Client, msg mqtt.Message) {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
// change the UART and pins as needed for platforms other than the WioTerminal.
|
||||
adaptor = rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
rtl, err := setupRTL8720DN()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
net.UseDriver(rtl)
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
ip, subnet, gateway, err := rtl.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
uart UARTx
|
||||
)
|
||||
|
||||
func handleInterrupt(interrupt.Interrupt) {
|
||||
// should reset IRQ
|
||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
||||
}
|
||||
|
||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
machine.RTL8720D_CHIP_PU.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.RTL8720D_CHIP_PU.High()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
if debug {
|
||||
waitSerial()
|
||||
}
|
||||
|
||||
uart = UARTx{
|
||||
UART: &machine.UART{
|
||||
Buffer: machine.NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
},
|
||||
}
|
||||
|
||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
||||
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
func waitSerial() {
|
||||
for !machine.Serial.DTR() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
type UARTx struct {
|
||||
*machine.UART
|
||||
}
|
||||
|
||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
||||
if u.Buffered() == 0 {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return 0, nil
|
||||
}
|
||||
return u.UART.Read(p)
|
||||
}
|
||||
@@ -4,31 +4,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/net"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// ntpHost = "129.6.15.29"
|
||||
// debug = true
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
ntpHost = "129.6.15.29"
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
ntpHost = "129.6.15.29"
|
||||
debug = false
|
||||
)
|
||||
|
||||
const NTP_PACKET_SIZE = 48
|
||||
@@ -44,16 +41,18 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
rtl, err := setupRTL8720DN()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
net.UseDriver(rtl)
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
ip, subnet, gateway, err := rtl.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
uart UARTx
|
||||
)
|
||||
|
||||
func handleInterrupt(interrupt.Interrupt) {
|
||||
// should reset IRQ
|
||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
||||
}
|
||||
|
||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
machine.RTL8720D_CHIP_PU.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.RTL8720D_CHIP_PU.High()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
waitSerial()
|
||||
|
||||
uart = UARTx{
|
||||
UART: &machine.UART{
|
||||
Buffer: machine.NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
},
|
||||
}
|
||||
|
||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
||||
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
func waitSerial() {
|
||||
for !machine.Serial.DTR() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
type UARTx struct {
|
||||
*machine.UART
|
||||
}
|
||||
|
||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
||||
if u.Buffered() == 0 {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return 0, nil
|
||||
}
|
||||
return u.UART.Read(p)
|
||||
}
|
||||
@@ -4,30 +4,28 @@
|
||||
// You can open a server to accept connections from this program using:
|
||||
//
|
||||
// nc -w 5 -lk 8080
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/net"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// ssid = "sghome-gw"
|
||||
// password = "3af25537b4524"
|
||||
// serverIP = "192.168.1.119"
|
||||
// debug = true
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
password string
|
||||
serverIP = ""
|
||||
debug = false
|
||||
)
|
||||
@@ -43,16 +41,18 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
rtl, err := setupRTL8720DN()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
net.UseDriver(rtl)
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
ip, subnet, gateway, err := rtl.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
uart UARTx
|
||||
)
|
||||
|
||||
func handleInterrupt(interrupt.Interrupt) {
|
||||
// should reset IRQ
|
||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
||||
}
|
||||
|
||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
machine.RTL8720D_CHIP_PU.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.RTL8720D_CHIP_PU.High()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
waitSerial()
|
||||
|
||||
uart = UARTx{
|
||||
UART: &machine.UART{
|
||||
Buffer: machine.NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
},
|
||||
}
|
||||
|
||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
||||
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
func waitSerial() {
|
||||
for !machine.Serial.DTR() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
type UARTx struct {
|
||||
*machine.UART
|
||||
}
|
||||
|
||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
||||
if u.Buffered() == 0 {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return 0, nil
|
||||
}
|
||||
return u.UART.Read(p)
|
||||
}
|
||||
@@ -1,32 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/net"
|
||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||
"tinygo.org/x/drivers/net/http"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// debug = true
|
||||
// url = "https://www.example.com"
|
||||
// test_root_ca = "..."
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
url string = "https://www.example.com"
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
url string = "https://www.example.com"
|
||||
debug = false
|
||||
)
|
||||
|
||||
// Set the test_root_ca created by the following command
|
||||
@@ -55,11 +52,6 @@ CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
|
||||
-----END CERTIFICATE-----
|
||||
`
|
||||
|
||||
var buf [0x1000]byte
|
||||
|
||||
var lastRequestTime time.Time
|
||||
var conn net.Conn
|
||||
|
||||
func main() {
|
||||
err := run()
|
||||
for err != nil {
|
||||
@@ -69,25 +61,12 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
|
||||
adaptor.SetRootCA(&test_root_ca)
|
||||
http.SetBuf(buf[:])
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
rtl8720dn.Debug(debug)
|
||||
rtl, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("IP Address : %s\r\n", ip)
|
||||
fmt.Printf("Mask : %s\r\n", subnet)
|
||||
fmt.Printf("Gateway : %s\r\n", gateway)
|
||||
rtl.SetRootCA(&test_root_ca)
|
||||
|
||||
// You can send and receive cookies in the following way
|
||||
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
||||
|
||||
@@ -1,31 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/net"
|
||||
"tinygo.org/x/drivers/net/http"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// hubIP = "192.168.1.118"
|
||||
// debug = true
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
hubIP = ""
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
hubIP = ""
|
||||
debug = false
|
||||
)
|
||||
|
||||
var buf [0x400]byte
|
||||
@@ -39,18 +36,19 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
|
||||
rtl, err := setupRTL8720DN()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
net.UseDriver(rtl)
|
||||
http.SetBuf(buf[:])
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
ip, subnet, gateway, err := rtl.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
uart UARTx
|
||||
)
|
||||
|
||||
func handleInterrupt(interrupt.Interrupt) {
|
||||
// should reset IRQ
|
||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
||||
}
|
||||
|
||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
machine.RTL8720D_CHIP_PU.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.RTL8720D_CHIP_PU.High()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
waitSerial()
|
||||
|
||||
uart = UARTx{
|
||||
UART: &machine.UART{
|
||||
Buffer: machine.NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
},
|
||||
}
|
||||
|
||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
||||
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
func waitSerial() {
|
||||
for !machine.Serial.DTR() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
type UARTx struct {
|
||||
*machine.UART
|
||||
}
|
||||
|
||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
||||
if u.Buffered() == 0 {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return 0, nil
|
||||
}
|
||||
return u.UART.Read(p)
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -22,11 +20,13 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
//rtl8720dn.Debug(true)
|
||||
rtl, err := rtl8720dn.Setup()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ver, err := adaptor.Version()
|
||||
ver, err := rtl.Version()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"bufio"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/ili9341"
|
||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||
"tinygo.org/x/drivers/net/http"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
|
||||
"tinygo.org/x/tinyfont/proggy"
|
||||
"tinygo.org/x/tinyterm"
|
||||
)
|
||||
@@ -21,29 +17,20 @@ import (
|
||||
// If debug is enabled, a serial connection is required.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// debug = false // true
|
||||
// server = "tinygo.org"
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
url = "http://tinygo.org/"
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
url = "http://tinygo.org/"
|
||||
debug = false
|
||||
)
|
||||
|
||||
var (
|
||||
display = ili9341.NewSPI(
|
||||
machine.SPI3,
|
||||
machine.LCD_DC,
|
||||
machine.LCD_SS_PIN,
|
||||
machine.LCD_RESET,
|
||||
)
|
||||
|
||||
backlight = machine.LCD_BACKLIGHT
|
||||
|
||||
terminal = tinyterm.NewTerminal(display)
|
||||
terminal *tinyterm.Terminal
|
||||
|
||||
black = color.RGBA{0, 0, 0, 255}
|
||||
white = color.RGBA{255, 255, 255, 255}
|
||||
@@ -54,12 +41,10 @@ var (
|
||||
font = &proggy.TinySZ8pt7b
|
||||
)
|
||||
|
||||
var buf [0x400]byte
|
||||
|
||||
func main() {
|
||||
display.FillScreen(black)
|
||||
backlight.High()
|
||||
|
||||
terminal = tinyterm.NewTerminal(display)
|
||||
terminal.Configure(&tinyterm.Config{
|
||||
Font: font,
|
||||
FontHeight: 10,
|
||||
@@ -78,30 +63,14 @@ func run() error {
|
||||
if debug {
|
||||
fmt.Fprintf(terminal, "Running in debug mode.\r\n")
|
||||
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
|
||||
rtl8720dn.Debug(true)
|
||||
}
|
||||
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
|
||||
http.UseDriver(adaptor)
|
||||
http.SetBuf(buf[:])
|
||||
|
||||
fmt.Fprintf(terminal, "ConnectToAP()\r\n")
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
_, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(terminal, "connected\r\n\r\n")
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(terminal, "IP Address : %s\r\n", ip)
|
||||
fmt.Fprintf(terminal, "Mask : %s\r\n", subnet)
|
||||
fmt.Fprintf(terminal, "Gateway : %s\r\n", gateway)
|
||||
|
||||
// You can send and receive cookies in the following way
|
||||
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
||||
// jar, err := cookiejar.New(nil)
|
||||
@@ -148,15 +117,3 @@ func run() error {
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
machine.SPI3.Configure(machine.SPIConfig{
|
||||
SCK: machine.LCD_SCK_PIN,
|
||||
SDO: machine.LCD_SDO_PIN,
|
||||
SDI: machine.LCD_SDI_PIN,
|
||||
Frequency: 40000000,
|
||||
})
|
||||
display.Configure(ili9341.Config{})
|
||||
|
||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||
"tinygo.org/x/drivers/ili9341"
|
||||
)
|
||||
|
||||
var (
|
||||
display *ili9341.Device
|
||||
)
|
||||
|
||||
func init() {
|
||||
display = initdisplay.InitDisplay()
|
||||
display.SetRotation(ili9341.Rotation0)
|
||||
}
|
||||
@@ -1,34 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"bufio"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||
"tinygo.org/x/drivers/net/http"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// url = "http://tinygo.org/"
|
||||
// debug = true
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
url = "http://tinygo.org/"
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
url = "http://tinygo.org/"
|
||||
debug = false
|
||||
)
|
||||
|
||||
var buf [0x400]byte
|
||||
|
||||
func main() {
|
||||
err := run()
|
||||
for err != nil {
|
||||
@@ -38,26 +34,11 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
|
||||
http.UseDriver(adaptor)
|
||||
http.SetBuf(buf[:])
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
_, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("IP Address : %s\r\n", ip)
|
||||
fmt.Printf("Mask : %s\r\n", subnet)
|
||||
fmt.Printf("Gateway : %s\r\n", gateway)
|
||||
|
||||
// You can send and receive cookies in the following way
|
||||
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
||||
// jar, err := cookiejar.New(nil)
|
||||
|
||||
@@ -2,33 +2,34 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"machine"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||
"tinygo.org/x/drivers/net/http"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
"tinygo.org/x/tinyfont"
|
||||
"tinygo.org/x/tinyfont/freemono"
|
||||
)
|
||||
|
||||
// You can override the setting with the init() in another source code.
|
||||
// func init() {
|
||||
// ssid = "your-ssid"
|
||||
// pass = "your-password"
|
||||
// password = "your-password"
|
||||
// debug = true
|
||||
// }
|
||||
|
||||
var (
|
||||
ssid string
|
||||
pass string
|
||||
debug = false
|
||||
ssid string
|
||||
password string
|
||||
debug = false
|
||||
)
|
||||
|
||||
var led = machine.LED
|
||||
var backlight = machine.LCD_BACKLIGHT
|
||||
|
||||
func main() {
|
||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
backlight.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
|
||||
err := run()
|
||||
for err != nil {
|
||||
@@ -38,24 +39,22 @@ func main() {
|
||||
}
|
||||
|
||||
func run() error {
|
||||
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
|
||||
adaptor.Debug(debug)
|
||||
adaptor.Configure()
|
||||
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 5, 15, "setup...", color.RGBA{0x00, 0x00, 0x00, 0xFF})
|
||||
|
||||
http.UseDriver(adaptor)
|
||||
|
||||
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
rtl, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ip, subnet, gateway, err := adaptor.GetIP()
|
||||
ip, subnet, gateway, err := rtl.GetIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("IP Address : %s\r\n", ip)
|
||||
fmt.Printf("Mask : %s\r\n", subnet)
|
||||
fmt.Printf("Gateway : %s\r\n", gateway)
|
||||
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 5, 15, "setup...done", color.RGBA{0x00, 0x00, 0x00, 0xFF})
|
||||
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 5, 30, fmt.Sprintf("listen:\nhttp://%s/", ip), color.RGBA{0x00, 0x00, 0x00, 0xFF})
|
||||
|
||||
http.HandleFunc("/", root)
|
||||
http.HandleFunc("/hello", hello)
|
||||
@@ -155,14 +154,12 @@ func sixlines(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func LED_ON(w http.ResponseWriter, r *http.Request) {
|
||||
led.High()
|
||||
backlight.High()
|
||||
w.Header().Set(`Content-Type`, `text/plain; charset=UTF-8`)
|
||||
fmt.Fprintf(w, "led.High()")
|
||||
}
|
||||
|
||||
func LED_OFF(w http.ResponseWriter, r *http.Request) {
|
||||
led.Low()
|
||||
backlight.Low()
|
||||
w.Header().Set(`Content-Type`, `text/plain; charset=UTF-8`)
|
||||
fmt.Fprintf(w, "led.Low()")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||
"tinygo.org/x/drivers/ili9341"
|
||||
)
|
||||
|
||||
var (
|
||||
display *ili9341.Device
|
||||
)
|
||||
|
||||
func init() {
|
||||
display = initdisplay.InitDisplay()
|
||||
display.SetRotation(ili9341.Rotation270)
|
||||
|
||||
// override
|
||||
led = machine.LCD_BACKLIGHT
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
//go:build wioterminal
|
||||
// +build wioterminal
|
||||
|
||||
package rtl8720dn
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
"machine"
|
||||
"runtime/interrupt"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/net"
|
||||
"tinygo.org/x/drivers/net/http"
|
||||
"tinygo.org/x/drivers/rtl8720dn"
|
||||
)
|
||||
|
||||
var (
|
||||
uart UARTx
|
||||
debug bool
|
||||
buf [0x1000]byte
|
||||
)
|
||||
|
||||
func handleInterrupt(interrupt.Interrupt) {
|
||||
// should reset IRQ
|
||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
||||
}
|
||||
|
||||
func Setup() (*rtl8720dn.RTL8720DN, error) {
|
||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
machine.RTL8720D_CHIP_PU.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
machine.RTL8720D_CHIP_PU.High()
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
if debug {
|
||||
waitSerial()
|
||||
}
|
||||
|
||||
uart = UARTx{
|
||||
UART: &machine.UART{
|
||||
Buffer: machine.NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
},
|
||||
}
|
||||
|
||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
||||
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
func SetupAndConnectToAccessPoint(ssid, pass string, timeout time.Duration) (*rtl8720dn.RTL8720DN, error) {
|
||||
rtl, err := Setup()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = rtl.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||
if err != nil {
|
||||
return rtl, err
|
||||
}
|
||||
|
||||
net.UseDriver(rtl)
|
||||
http.UseDriver(rtl)
|
||||
http.SetBuf(buf[:])
|
||||
|
||||
return rtl, nil
|
||||
}
|
||||
|
||||
// Wait for user to open serial console
|
||||
func waitSerial() {
|
||||
for !machine.Serial.DTR() {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
type UARTx struct {
|
||||
*machine.UART
|
||||
}
|
||||
|
||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
||||
if u.Buffered() == 0 {
|
||||
time.Sleep(1 * time.Millisecond)
|
||||
return 0, nil
|
||||
}
|
||||
return u.UART.Read(p)
|
||||
}
|
||||
|
||||
func Debug(b bool) {
|
||||
debug = b
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
// +build gnse
|
||||
|
||||
/*
|
||||
Generic Node Sensor Edition
|
||||
RFSwitch
|
||||
Generic Node Sensor Edition
|
||||
RFSwitch
|
||||
|
||||
Disable Switch : PB8=OFF PA0=OFF PA1=OFF
|
||||
Enable RX : PB8=ON PA0=ON PA1=OFF
|
||||
Enable TX RFO LP : PB8=ON PA0=ON PA1=ON
|
||||
Enable TX RFO HP : PB8=ON PA0=OFF PA1=ON
|
||||
Disable Switch : PB8=OFF PA0=OFF PA1=OFF
|
||||
Enable RX : PB8=ON PA0=ON PA1=OFF
|
||||
Enable TX RFO LP : PB8=ON PA0=ON PA1=ON
|
||||
Enable TX RFO HP : PB8=ON PA0=OFF PA1=ON
|
||||
*/
|
||||
package rfswitch
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// +build nucleowl55jc
|
||||
|
||||
/*
|
||||
Nucleo WL55JC1
|
||||
RFSwitch
|
||||
Nucleo WL55JC1
|
||||
RFSwitch
|
||||
|
||||
+-----------+---------+------------+------------+
|
||||
| | FE_CTRL1 | FE_CTRL2 | FE_CTRL3 |
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"tinygo.org/x/drivers/vl6180x"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
time.Sleep(3 * time.Second)
|
||||
machine.I2C0.Configure(machine.I2CConfig{
|
||||
Frequency: 400000,
|
||||
})
|
||||
sensor := vl6180x.New(machine.I2C0)
|
||||
connected := sensor.Connected()
|
||||
if !connected {
|
||||
println("VL6180X device not found")
|
||||
return
|
||||
}
|
||||
println("VL6180X device found")
|
||||
sensor.Configure(true)
|
||||
var value uint16
|
||||
var status uint8
|
||||
for {
|
||||
value = sensor.Read()
|
||||
status = sensor.ReadStatus()
|
||||
println("Distance (mm):", value)
|
||||
println("Status:", status)
|
||||
println("---")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
|
||||
"image/color"
|
||||
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/waveshare-epd/epd2in9"
|
||||
)
|
||||
|
||||
var display epd2in9.Device
|
||||
|
||||
const (
|
||||
width = 128
|
||||
height = 296
|
||||
)
|
||||
|
||||
func main() {
|
||||
machine.SPI0.Configure(machine.SPIConfig{
|
||||
Frequency: 8000000,
|
||||
Mode: 0,
|
||||
})
|
||||
|
||||
display = epd2in9.New(machine.SPI0, machine.GPIO2, machine.GPIO3, machine.GPIO4, machine.GPIO5)
|
||||
display.Configure(epd2in9.Config{
|
||||
Width: width,
|
||||
LogicalWidth: width,
|
||||
Height: height,
|
||||
})
|
||||
|
||||
black := color.RGBA{1, 1, 1, 255}
|
||||
white := color.RGBA{0, 0, 0, 255}
|
||||
|
||||
display.ClearBuffer()
|
||||
println("Clear the display")
|
||||
display.ClearDisplay()
|
||||
display.WaitUntilIdle()
|
||||
println("Waiting for 2 seconds")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
// Show a checkered board
|
||||
for i := int16(0); i < width/8; i++ {
|
||||
for j := int16(0); j < height/8; j++ {
|
||||
if (i+j)%2 == 0 {
|
||||
showRect(i*8, j*8, 8, 8, black)
|
||||
}
|
||||
}
|
||||
}
|
||||
println("Show checkered board")
|
||||
display.Display()
|
||||
display.WaitUntilIdle()
|
||||
println("Waiting for 2 seconds")
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
println("Set partial lut")
|
||||
display.SetLUT(false) // partial updates (faster, but with some ghosting)
|
||||
println("Show smaller striped area")
|
||||
for i := int16(40); i < 88; i++ {
|
||||
for j := int16(83); j < 166; j++ {
|
||||
if (i+j)%4 == 0 || (i+j)%4 == 1 {
|
||||
display.SetPixel(i, j, black)
|
||||
} else {
|
||||
display.SetPixel(i, j, white)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
display.Display()
|
||||
display.WaitUntilIdle()
|
||||
|
||||
display.DeepSleep()
|
||||
|
||||
println("You could remove power now")
|
||||
}
|
||||
|
||||
func showRect(x int16, y int16, w int16, h int16, c color.RGBA) {
|
||||
for i := x; i < x+w; i++ {
|
||||
for j := y; j < y+h; j++ {
|
||||
display.SetPixel(i, j, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
// You can open a server to accept connections from this program using:
|
||||
//
|
||||
// nc -w 5 -lk 8080
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,11 +15,9 @@ import (
|
||||
"tinygo.org/x/drivers/net"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const serverIP = ""
|
||||
|
||||
@@ -9,11 +9,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// these are the default pins for the Arduino Nano33 IoT.
|
||||
// change these to connect to a different UART or pins for the ESP8266/ESP32
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
//
|
||||
// examples/wifinina/webclient
|
||||
// examples/wifinina/tlsclient
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -23,11 +24,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
// Can specify a URL starting with http or https
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//
|
||||
// You must install the Paho MQTT package to build this program:
|
||||
//
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -20,11 +21,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the MQTT broker to use. Replace with your own info.
|
||||
const server = "tcp://test.mosquitto.org:1883"
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
//
|
||||
// You must also install the Paho MQTT package to build this program:
|
||||
//
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
// go get -u github.com/eclipse/paho.mqtt.golang
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -20,11 +21,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the MQTT broker to use. Replace with your own info.
|
||||
const server = "tcp://test.mosquitto.org:1883"
|
||||
|
||||
@@ -14,11 +14,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const ntpHost = "129.6.15.29"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// You can open a server to accept connections from this program using:
|
||||
//
|
||||
// nc -w 5 -lk 8080
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -16,11 +17,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const serverIP = ""
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
// You shall see "strict-transport-security" header in the response,
|
||||
// this confirms communication is indeed over HTTPS
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -17,11 +18,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const server = "tinygo.org"
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// In other words:
|
||||
// Your computer <--> UART0 <--> MCU <--> SPI <--> ESP32
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,11 +15,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const hubIP = ""
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// Arduino example:
|
||||
//
|
||||
// https://github.com/arduino-libraries/WiFiNINA/blob/master/examples/WiFiWebClientRepeating/
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -14,11 +15,9 @@ import (
|
||||
"tinygo.org/x/drivers/wifinina"
|
||||
)
|
||||
|
||||
var (
|
||||
// access point info
|
||||
ssid string
|
||||
pass string
|
||||
)
|
||||
// access point info
|
||||
const ssid = ""
|
||||
const pass = ""
|
||||
|
||||
// IP address of the server aka "hub". Replace with your own info.
|
||||
const server = "tinygo.org"
|
||||
|
||||
+3
-3
@@ -2,6 +2,7 @@
|
||||
// panel controller.
|
||||
//
|
||||
// Datasheet: https://focuslcds.com/content/FT6236.pdf
|
||||
//
|
||||
package ft6336
|
||||
|
||||
import (
|
||||
@@ -41,9 +42,8 @@ func (d *Device) Configure(config Config) error {
|
||||
}
|
||||
|
||||
// SetGMode sets interrupt mode.
|
||||
//
|
||||
// 0x00 : Interrupt Polling mode
|
||||
// 0x01 : Interrupt Trigger mode (default)
|
||||
// 0x00 : Interrupt Polling mode
|
||||
// 0x01 : Interrupt Trigger mode (default)
|
||||
func (d *Device) SetGMode(v uint8) {
|
||||
d.write1Byte(RegGMode, v)
|
||||
}
|
||||
|
||||
@@ -1,567 +0,0 @@
|
||||
// Package gc9a01 implements a driver for the gc9a01 LCD round display
|
||||
//
|
||||
// Datasheet: https://www.waveshare.com/w/upload/5/5e/GC9A01A.pdf
|
||||
package gc9a01 // import "tinygo.org/x/drivers/gc9a01"
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"errors"
|
||||
|
||||
"tinygo.org/x/drivers"
|
||||
)
|
||||
|
||||
// Rotation controls the rotation used by the display.
|
||||
type Orientation uint8
|
||||
|
||||
// FrameRate controls the frame rate used by the display.
|
||||
type FrameRate uint8
|
||||
|
||||
// Device wraps an SPI connection.
|
||||
type Device struct {
|
||||
bus drivers.SPI
|
||||
dcPin machine.Pin
|
||||
resetPin machine.Pin
|
||||
csPin machine.Pin
|
||||
blPin machine.Pin
|
||||
width int16
|
||||
height int16
|
||||
columnOffsetCfg int16
|
||||
rowOffsetCfg int16
|
||||
columnOffset int16
|
||||
rowOffset int16
|
||||
frameRate FrameRate
|
||||
isBGR bool
|
||||
vSyncLines int16
|
||||
orientation Orientation
|
||||
batchLength int16
|
||||
batchData []uint8
|
||||
}
|
||||
|
||||
// Config is the configuration for the display
|
||||
type Config struct {
|
||||
Orientation Orientation
|
||||
RowOffset int16
|
||||
ColumnOffset int16
|
||||
FrameRate FrameRate
|
||||
VSyncLines int16
|
||||
Width int16
|
||||
Height int16
|
||||
}
|
||||
|
||||
// New creates a new ST7789 connection. The SPI wire must already be configured.
|
||||
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device {
|
||||
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
return Device{
|
||||
bus: bus,
|
||||
resetPin: resetPin,
|
||||
dcPin: dcPin,
|
||||
csPin: csPin,
|
||||
blPin: blPin,
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the Device
|
||||
func (d *Device) Reset() {
|
||||
d.resetPin.High()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.resetPin.Low()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
d.resetPin.High()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
}
|
||||
|
||||
// Sets Device configuration for screen orientation using the initialzation values
|
||||
func (d *Device) SetDeviceOrientation() {
|
||||
|
||||
var MemoryAccessReg uint8
|
||||
|
||||
//Get GRAM and LCD width and height
|
||||
if d.orientation == HORIZONTAL {
|
||||
MemoryAccessReg = 0xc8
|
||||
} else {
|
||||
MemoryAccessReg = 0x68
|
||||
}
|
||||
|
||||
// Set the read / write scan direction of the frame memory
|
||||
d.Command(MADCTR)
|
||||
//0x08 set RGB
|
||||
d.Command(MemoryAccessReg)
|
||||
}
|
||||
|
||||
// setWindow prepares the screen to be modified at a given rectangle
|
||||
func (d *Device) setWindow(x, y, w, h int16) {
|
||||
if d.orientation == HORIZONTAL {
|
||||
x += d.columnOffset
|
||||
y += d.rowOffset
|
||||
} else {
|
||||
x += d.rowOffset
|
||||
y += d.columnOffset
|
||||
}
|
||||
d.Tx([]uint8{CASET}, true)
|
||||
d.Tx([]uint8{uint8(x >> 8), uint8(x), uint8((x + w - 1) >> 8), uint8(x + w - 1)}, false)
|
||||
d.Tx([]uint8{RASET}, true)
|
||||
d.Tx([]uint8{uint8(y >> 8), uint8(y), uint8((y + h - 1) >> 8), uint8(y + h - 1)}, false)
|
||||
d.Command(RAMWR)
|
||||
}
|
||||
|
||||
// FillScreen fills the screen with a given color
|
||||
func (d *Device) FillScreen(c color.RGBA) {
|
||||
d.FillRectangle(0, 0, d.height, d.width, c)
|
||||
}
|
||||
|
||||
// FillRectangle fills a rectangle at a given coordinates with a color
|
||||
func (d *Device) FillRectangle(x, y, width, height int16, c color.RGBA) error {
|
||||
k, j := d.Size()
|
||||
var i int32
|
||||
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||
x >= k || (x+width) > k || y >= j || (y+height) > j {
|
||||
return errors.New("rectangle coordinates outside display area")
|
||||
}
|
||||
d.setWindow(x, y, width, height)
|
||||
c565 := RGBATo565(c)
|
||||
c1 := uint8(c565 >> 8)
|
||||
c2 := uint8(c565)
|
||||
|
||||
for i = 0; i < int32(d.batchLength); i++ {
|
||||
d.batchData[i*2] = c1
|
||||
d.batchData[i*2+1] = c2
|
||||
}
|
||||
i = int32(width) * int32(height)
|
||||
batchLength := int32(d.batchLength)
|
||||
for i > 0 {
|
||||
if i >= batchLength {
|
||||
d.Tx(d.batchData, false)
|
||||
} else {
|
||||
d.Tx(d.batchData[:i*2], false)
|
||||
}
|
||||
i -= batchLength
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Display sends the whole buffer to the screen
|
||||
func (d *Device) Display() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FillRectangleWithBuffer fills buffer with a rectangle at a given coordinates.
|
||||
func (d *Device) FillRectangleWithBuffer(x, y, width, height int16, buffer []color.RGBA) error {
|
||||
h, w := d.Size()
|
||||
if x < 0 || y < 0 || width <= 0 || height <= 0 ||
|
||||
x >= h || (x+width) > h || y >= w || (y+height) > w {
|
||||
return errors.New("rectangle coordinates outside display area")
|
||||
}
|
||||
k := int32(width) * int32(height)
|
||||
l := int32(len(buffer))
|
||||
if k != l {
|
||||
return errors.New("buffer length does not match with rectangle size")
|
||||
}
|
||||
|
||||
d.setWindow(x, y, width, height)
|
||||
|
||||
offset := int32(0)
|
||||
batchLength := int32(d.batchLength)
|
||||
for k > 0 {
|
||||
for i := int32(0); i < batchLength; i++ {
|
||||
if offset+i < l {
|
||||
c565 := RGBATo565(buffer[offset+i])
|
||||
c1 := uint8(c565 >> 8)
|
||||
c2 := uint8(c565)
|
||||
d.batchData[i*2] = c1
|
||||
d.batchData[i*2+1] = c2
|
||||
}
|
||||
}
|
||||
if k >= batchLength {
|
||||
d.Tx(d.batchData, false)
|
||||
} else {
|
||||
d.Tx(d.batchData[:k*2], false)
|
||||
}
|
||||
k -= batchLength
|
||||
offset += batchLength
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DrawFastVLine draws a vertical line faster than using SetPixel
|
||||
func (d *Device) DrawFastVLine(x, y0, y1 int16, c color.RGBA) {
|
||||
if y0 > y1 {
|
||||
y0, y1 = y1, y0
|
||||
}
|
||||
d.FillRectangle(x, y0, 1, y1-y0+1, c)
|
||||
}
|
||||
|
||||
// DrawFastHLine draws a horizontal line faster than using SetPixel
|
||||
func (d *Device) DrawFastHLine(x0, x1, y int16, c color.RGBA) {
|
||||
if x0 > x1 {
|
||||
x0, x1 = x1, x0
|
||||
}
|
||||
d.FillRectangle(x0, y, x1-x0+1, 1, c)
|
||||
}
|
||||
|
||||
// SetPixel sets a pixel in the screen
|
||||
func (d *Device) SetPixel(x, y int16, c color.RGBA) {
|
||||
w, h := d.Size()
|
||||
if x < 0 || y < 0 || x >= w || y >= h {
|
||||
return
|
||||
}
|
||||
d.FillRectangle(x, y, 1, 1, c)
|
||||
}
|
||||
|
||||
// Command sends a command to the display.
|
||||
func (d *Device) Command(command uint8) {
|
||||
d.Tx([]byte{command}, true)
|
||||
}
|
||||
|
||||
// Data sends data to the display.
|
||||
func (d *Device) Data(data uint8) {
|
||||
d.Tx([]byte{data}, false)
|
||||
}
|
||||
|
||||
// Tx sends data to the display
|
||||
func (d *Device) Tx(data []byte, isCommand bool) {
|
||||
d.dcPin.Set(!isCommand)
|
||||
d.bus.Tx(data, nil)
|
||||
}
|
||||
|
||||
// Rx reads data from the display
|
||||
func (d *Device) Rx(command uint8, data []byte) {
|
||||
d.dcPin.Low()
|
||||
d.csPin.Low()
|
||||
d.bus.Transfer(command)
|
||||
d.dcPin.High()
|
||||
for i := range data {
|
||||
data[i], _ = d.bus.Transfer(0xFF)
|
||||
}
|
||||
d.csPin.High()
|
||||
}
|
||||
|
||||
// Size returns the current size of the display.
|
||||
func (d *Device) Size() (w, h int16) {
|
||||
return d.height, d.width
|
||||
}
|
||||
|
||||
// EnableBacklight enables or disables the backlight
|
||||
func (d *Device) EnableBacklight(enable bool) {
|
||||
if enable {
|
||||
d.blPin.High()
|
||||
} else {
|
||||
d.blPin.Low()
|
||||
}
|
||||
}
|
||||
|
||||
// InvertColors inverts the colors of the screen
|
||||
func (d *Device) InvertColors(invert bool) {
|
||||
if invert {
|
||||
d.Command(INVON)
|
||||
} else {
|
||||
d.Command(INVOFF)
|
||||
}
|
||||
}
|
||||
|
||||
// IsBGR changes the color mode (RGB/BGR)
|
||||
func (d *Device) IsBGR(bgr bool) {
|
||||
d.isBGR = bgr
|
||||
}
|
||||
|
||||
// SetScrollArea sets an area to scroll with fixed top and bottom parts of the display.
|
||||
func (d *Device) SetScrollArea(topFixedArea, bottomFixedArea int16) {
|
||||
d.Command(VSCRDEF)
|
||||
d.Tx([]uint8{
|
||||
uint8(topFixedArea >> 8), uint8(topFixedArea),
|
||||
uint8(d.height - topFixedArea - bottomFixedArea>>8), uint8(d.height - topFixedArea - bottomFixedArea),
|
||||
uint8(bottomFixedArea >> 8), uint8(bottomFixedArea)},
|
||||
false)
|
||||
}
|
||||
|
||||
// SetScroll sets the vertical scroll address of the display.
|
||||
func (d *Device) SetScroll(line int16) {
|
||||
d.Command(VSCRSADD)
|
||||
d.Tx([]uint8{uint8(line >> 8), uint8(line)}, false)
|
||||
}
|
||||
|
||||
// StopScroll returns the display to its normal state.
|
||||
func (d *Device) StopScroll() {
|
||||
d.Command(NORON)
|
||||
}
|
||||
|
||||
// RGBATo565 converts a color.RGBA to uint16 used in the display
|
||||
func RGBATo565(c color.RGBA) uint16 {
|
||||
r, g, b, _ := c.RGBA()
|
||||
return uint16((r & 0xF800) +
|
||||
((g & 0xFC00) >> 5) +
|
||||
((b & 0xF800) >> 11))
|
||||
}
|
||||
|
||||
// Configure initializes the display with default configuration
|
||||
func (d *Device) Configure(cfg Config) {
|
||||
if cfg.Width != 0 {
|
||||
d.width = cfg.Width
|
||||
} else {
|
||||
d.width = 240
|
||||
}
|
||||
if cfg.Height != 0 {
|
||||
d.height = cfg.Height
|
||||
} else {
|
||||
d.height = 240
|
||||
}
|
||||
|
||||
d.orientation = cfg.Orientation
|
||||
d.rowOffsetCfg = cfg.RowOffset
|
||||
d.columnOffsetCfg = cfg.ColumnOffset
|
||||
d.batchLength = d.width
|
||||
|
||||
if cfg.VSyncLines >= 2 && cfg.VSyncLines <= 254 {
|
||||
d.vSyncLines = cfg.VSyncLines
|
||||
} else {
|
||||
d.vSyncLines = 16
|
||||
}
|
||||
d.batchLength += d.batchLength & 1
|
||||
d.batchData = make([]uint8, d.batchLength*2)
|
||||
|
||||
// Reset the device
|
||||
d.Reset()
|
||||
|
||||
// Set Device Attributes
|
||||
d.SetDeviceOrientation()
|
||||
|
||||
// Common initialization
|
||||
d.Command(0xEF)
|
||||
d.Command(0xEB)
|
||||
d.Data(0x14)
|
||||
|
||||
d.Command(INTEN1)
|
||||
d.Command(0xEF)
|
||||
|
||||
d.Command(0xEB)
|
||||
d.Data(0x14)
|
||||
|
||||
d.Command(0x84)
|
||||
d.Data(0x40)
|
||||
|
||||
d.Command(0x85)
|
||||
d.Data(0xFF)
|
||||
|
||||
d.Command(0x86)
|
||||
d.Data(0xFF)
|
||||
|
||||
d.Command(0x87)
|
||||
d.Data(0xFF)
|
||||
|
||||
d.Command(0x88)
|
||||
d.Data(0x0A)
|
||||
|
||||
d.Command(0x89)
|
||||
d.Data(0x21)
|
||||
|
||||
d.Command(0x8A)
|
||||
d.Data(0x00)
|
||||
|
||||
d.Command(0x8B)
|
||||
d.Data(0x80)
|
||||
|
||||
d.Command(0x8C)
|
||||
d.Data(0x01)
|
||||
|
||||
d.Command(0x8D)
|
||||
d.Data(0x01)
|
||||
|
||||
d.Command(0x8E)
|
||||
d.Data(0xFF)
|
||||
|
||||
d.Command(0x8F)
|
||||
d.Data(0xFF)
|
||||
|
||||
d.Command(DISFNCTL)
|
||||
d.Data(0x00)
|
||||
d.Data(0x20)
|
||||
|
||||
d.Command(MADCTR)
|
||||
d.Data(0x08) //Set as vertical screen
|
||||
|
||||
d.Command(COLMOD)
|
||||
d.Data(0x05)
|
||||
|
||||
d.Command(0x90)
|
||||
d.Data(0x08)
|
||||
d.Data(0x08)
|
||||
d.Data(0x08)
|
||||
d.Data(0x08)
|
||||
|
||||
d.Command(0xBD)
|
||||
d.Data(0x06)
|
||||
|
||||
d.Command(0xBC)
|
||||
d.Data(0x00)
|
||||
|
||||
d.Command(0xFF)
|
||||
d.Data(0x60)
|
||||
d.Data(0x01)
|
||||
d.Data(0x04)
|
||||
|
||||
d.Command(PWCTR3)
|
||||
d.Data(0x13)
|
||||
d.Command(PWCTR4)
|
||||
d.Data(0x13)
|
||||
|
||||
d.Command(0xC9)
|
||||
d.Data(0x22)
|
||||
|
||||
d.Command(0xBE)
|
||||
d.Data(0x11)
|
||||
|
||||
d.Command(0xE1)
|
||||
d.Data(0x10)
|
||||
d.Data(0x0E)
|
||||
|
||||
d.Command(0xDF)
|
||||
d.Data(0x21)
|
||||
d.Data(0x0c)
|
||||
d.Data(0x02)
|
||||
|
||||
d.Command(GMSET1)
|
||||
d.Data(0x45)
|
||||
d.Data(0x09)
|
||||
d.Data(0x08)
|
||||
d.Data(0x08)
|
||||
d.Data(0x26)
|
||||
d.Data(0x2A)
|
||||
|
||||
d.Command(GMSET2)
|
||||
d.Data(0x43)
|
||||
d.Data(0x70)
|
||||
d.Data(0x72)
|
||||
d.Data(0x36)
|
||||
d.Data(0x37)
|
||||
d.Data(0x6F)
|
||||
|
||||
d.Command(GMSET3)
|
||||
d.Data(0x45)
|
||||
d.Data(0x09)
|
||||
d.Data(0x08)
|
||||
d.Data(0x08)
|
||||
d.Data(0x26)
|
||||
d.Data(0x2A)
|
||||
|
||||
d.Command(GMSET4)
|
||||
d.Data(0x43)
|
||||
d.Data(0x70)
|
||||
d.Data(0x72)
|
||||
d.Data(0x36)
|
||||
d.Data(0x37)
|
||||
d.Data(0x6F)
|
||||
|
||||
d.Command(0xED)
|
||||
d.Data(0x1B)
|
||||
d.Data(0x0B)
|
||||
|
||||
d.Command(0xAE)
|
||||
d.Data(0x77)
|
||||
|
||||
d.Command(0xCD)
|
||||
d.Data(0x63)
|
||||
|
||||
d.Command(0x70)
|
||||
d.Data(0x07)
|
||||
d.Data(0x07)
|
||||
d.Data(0x04)
|
||||
d.Data(0x0E)
|
||||
d.Data(0x0F)
|
||||
d.Data(0x09)
|
||||
d.Data(0x07)
|
||||
d.Data(0x08)
|
||||
d.Data(0x03)
|
||||
|
||||
d.Command(FRMCTL)
|
||||
d.Data(0x34)
|
||||
|
||||
d.Command(0x62)
|
||||
d.Data(0x18)
|
||||
d.Data(0x0D)
|
||||
d.Data(0x71)
|
||||
d.Data(0xED)
|
||||
d.Data(0x70)
|
||||
d.Data(0x70)
|
||||
d.Data(0x18)
|
||||
d.Data(0x0F)
|
||||
d.Data(0x71)
|
||||
d.Data(0xEF)
|
||||
d.Data(0x70)
|
||||
d.Data(0x70)
|
||||
|
||||
d.Command(0x63)
|
||||
d.Data(0x18)
|
||||
d.Data(0x11)
|
||||
d.Data(0x71)
|
||||
d.Data(0xF1)
|
||||
d.Data(0x70)
|
||||
d.Data(0x70)
|
||||
d.Data(0x18)
|
||||
d.Data(0x13)
|
||||
d.Data(0x71)
|
||||
d.Data(0xF3)
|
||||
d.Data(0x70)
|
||||
d.Data(0x70)
|
||||
|
||||
d.Command(0x64)
|
||||
d.Data(0x28)
|
||||
d.Data(0x29)
|
||||
d.Data(0xF1)
|
||||
d.Data(0x01)
|
||||
d.Data(0xF1)
|
||||
d.Data(0x00)
|
||||
d.Data(0x07)
|
||||
|
||||
d.Command(0x66)
|
||||
d.Data(0x3C)
|
||||
d.Data(0x00)
|
||||
d.Data(0xCD)
|
||||
d.Data(0x67)
|
||||
d.Data(0x45)
|
||||
d.Data(0x45)
|
||||
d.Data(0x10)
|
||||
d.Data(0x00)
|
||||
d.Data(0x00)
|
||||
d.Data(0x00)
|
||||
|
||||
d.Command(0x67)
|
||||
d.Data(0x00)
|
||||
d.Data(0x3C)
|
||||
d.Data(0x00)
|
||||
d.Data(0x00)
|
||||
d.Data(0x00)
|
||||
d.Data(0x01)
|
||||
d.Data(0x54)
|
||||
d.Data(0x10)
|
||||
d.Data(0x32)
|
||||
d.Data(0x98)
|
||||
|
||||
d.Command(0x74)
|
||||
d.Data(0x10)
|
||||
d.Data(0x85)
|
||||
d.Data(0x80)
|
||||
d.Data(0x00)
|
||||
d.Data(0x00)
|
||||
d.Data(0x4E)
|
||||
d.Data(0x00)
|
||||
|
||||
d.Command(0x98)
|
||||
d.Data(0x3e)
|
||||
d.Data(0x07)
|
||||
|
||||
d.Command(TEON)
|
||||
d.Command(0x21)
|
||||
|
||||
d.Command(SLPOUT)
|
||||
time.Sleep(120 * time.Millisecond)
|
||||
d.Command(DISPON)
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
|
||||
d.blPin.High()
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package gc9a01
|
||||
|
||||
// Registers
|
||||
const (
|
||||
NOP = 0x00
|
||||
SWRESET = 0x01
|
||||
RDDIDIF = 0x04
|
||||
RDDST = 0x09
|
||||
SLPIN = 0x10
|
||||
SLPOUT = 0x11
|
||||
PTLON = 0x12
|
||||
NORON = 0x13
|
||||
INVOFF = 0x20
|
||||
INVON = 0x21
|
||||
DISPOFF = 0x28
|
||||
DISPON = 0x29
|
||||
CASET = 0x2A
|
||||
RASET = 0x2B
|
||||
RAMWR = 0x2C
|
||||
PTLAR = 0x30
|
||||
VSCRDEF = 0x33
|
||||
TEOFF = 0x34
|
||||
TEON = 0x35
|
||||
MADCTR = 0x36
|
||||
VSCRSADD = 0x37
|
||||
IDMOFF = 0x38
|
||||
IDMON = 0x39
|
||||
COLMOD = 0x3A
|
||||
RMEMCON = 0x3C
|
||||
STTRSCL = 0x44
|
||||
GTSCL = 0x45
|
||||
WRDISBV = 0x51
|
||||
WRCTRLD = 0x51
|
||||
MADCTL_MY = 0x80
|
||||
MADCTL_MX = 0x40
|
||||
MADCTL_MV = 0x20
|
||||
MADCTL_ML = 0x10
|
||||
MADCTL_RGB = 0x00
|
||||
MADCTL_BGR = 0x08
|
||||
MADCTL_MH = 0x04
|
||||
RDID1 = 0xDA
|
||||
RDID2 = 0xDB
|
||||
RDID3 = 0xDC
|
||||
RGBICTR = 0xB0
|
||||
BLPCHCTRL = 0xB5
|
||||
DISFNCTL = 0xB6
|
||||
TECTL = 0xBA
|
||||
INTCTL = 0xBA
|
||||
FRMCTL = 0xE8
|
||||
SPICTL = 0xE9
|
||||
PWCTR1 = 0xC1
|
||||
PWCTR2 = 0xC2
|
||||
PWCTR3 = 0xC3
|
||||
PWCTR4 = 0xC4
|
||||
PWCTR7 = 0xC7
|
||||
INTEN1 = 0xFE
|
||||
INTEN2 = 0xEF
|
||||
GMSET1 = 0xF0
|
||||
GMSET2 = 0xF1
|
||||
GMSET3 = 0xF2
|
||||
GMSET4 = 0xF3
|
||||
|
||||
HORIZONTAL Orientation = 0
|
||||
VERTICAL Orientation = 1
|
||||
)
|
||||
@@ -5,8 +5,8 @@ go 1.15
|
||||
require (
|
||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||
github.com/frankban/quicktest v1.10.2
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
||||
tinygo.org/x/tinyfont v0.3.0
|
||||
tinygo.org/x/tinyfs v0.2.0
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
||||
tinygo.org/x/tinyfont v0.2.1
|
||||
tinygo.org/x/tinyfs v0.1.0
|
||||
tinygo.org/x/tinyterm v0.1.0
|
||||
)
|
||||
|
||||
@@ -5,15 +5,12 @@ github.com/frankban/quicktest v1.10.2 h1:19ARM85nVi4xH7xPXuc5eM/udya5ieh7b/Sv+d8
|
||||
github.com/frankban/quicktest v1.10.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/hajimehoshi/go-jisx0208 v1.0.0/go.mod h1:yYxEStHL7lt9uL+AbdWgW9gBumwieDoZCiB1f/0X0as=
|
||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/sago35/go-bdf v0.0.0-20200313142241-6c17821c91c4/go.mod h1:rOebXGuMLsXhZAC6mF/TjxONsm45498ZyzVhel++6KM=
|
||||
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
|
||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@@ -27,12 +24,9 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
|
||||
tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||
tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||
tinygo.org/x/drivers v0.16.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||
tinygo.org/x/drivers v0.19.0/go.mod h1:uJD/l1qWzxzLx+vcxaW0eY464N5RAgFi1zTVzASFdqI=
|
||||
tinygo.org/x/tinyfont v0.2.1 h1:FAaemBzw8wsfhAtG6fWW+QjyWw/K8YqEeiWo4N1pv4o=
|
||||
tinygo.org/x/tinyfont v0.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM=
|
||||
tinygo.org/x/tinyfont v0.3.0 h1:HIRLQoI3oc+2CMhPcfv+Ig88EcTImE/5npjqOnMD4lM=
|
||||
tinygo.org/x/tinyfont v0.3.0/go.mod h1:+TV5q0KpwSGRWnN+ITijsIhrWYJkoUCp9MYELjKpAXk=
|
||||
tinygo.org/x/tinyfs v0.1.0 h1:yx1Tq9L60rpCm6HURo45x+Tnag+O9RGSbQfgeCb6XYU=
|
||||
tinygo.org/x/tinyfs v0.1.0/go.mod h1:ysc8Y92iHfhTXeyEM9+c7zviUQ4fN9UCFgSOFfMWv20=
|
||||
tinygo.org/x/tinyfs v0.2.0 h1:M0lwZC/dEGFt16XYN5GTQsif/qCkAN2qUVNxELVD1xg=
|
||||
tinygo.org/x/tinyfs v0.2.0/go.mod h1:6ZHYdvB3sFYeMB3ypmXZCNEnFwceKc61ADYTYHpep1E=
|
||||
tinygo.org/x/tinyterm v0.1.0 h1:80i+j+KWoxCFa/Xfp6pWbh79x+8zUdMXC1vaKj2QhkY=
|
||||
tinygo.org/x/tinyterm v0.1.0/go.mod h1:/DDhNnGwNF2/tNgHywvyZuCGnbH3ov49Z/6e8LPLRR4=
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package hd44780 provides a driver for the HD44780 LCD controller.
|
||||
//
|
||||
// Datasheet: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
|
||||
//
|
||||
package hd44780 // import "tinygo.org/x/drivers/hd44780"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// with an I2C adapter.
|
||||
//
|
||||
// Datasheet: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
|
||||
//
|
||||
package hd44780i2c
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// a capacitive digital sensor for relative humidity and temperature.
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/hts221.pdf
|
||||
//
|
||||
package hts221
|
||||
|
||||
import (
|
||||
@@ -84,6 +85,7 @@ func (d *Device) ReadTemperature() (temperature int32, err error) {
|
||||
// Resolution sets the HTS221's resolution mode.
|
||||
// The higher resolutions are more accurate but comsume more power (see datasheet).
|
||||
// The number of averaged samples will be (h + 2) ^ 2, (t + 1) ^ 2
|
||||
//
|
||||
func (d *Device) Resolution(h uint8, t uint8) {
|
||||
if h > 7 {
|
||||
h = 3 // default
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
//
|
||||
// Guide: https://cdn-learn.adafruit.com/downloads/pdf/32x16-32x32-rgb-led-matrix.pdf
|
||||
// This driver was inspired by https://github.com/2dom/PxMatrix
|
||||
//
|
||||
package hub75 // import "tinygo.org/x/drivers/hub75"
|
||||
|
||||
import (
|
||||
|
||||
@@ -7,19 +7,19 @@ package flate
|
||||
// dictDecoder implements the LZ77 sliding dictionary as used in decompression.
|
||||
// LZ77 decompresses data through sequences of two forms of commands:
|
||||
//
|
||||
// - Literal insertions: Runs of one or more symbols are inserted into the data
|
||||
// stream as is. This is accomplished through the writeByte method for a
|
||||
// single symbol, or combinations of writeSlice/writeMark for multiple symbols.
|
||||
// Any valid stream must start with a literal insertion if no preset dictionary
|
||||
// is used.
|
||||
// * Literal insertions: Runs of one or more symbols are inserted into the data
|
||||
// stream as is. This is accomplished through the writeByte method for a
|
||||
// single symbol, or combinations of writeSlice/writeMark for multiple symbols.
|
||||
// Any valid stream must start with a literal insertion if no preset dictionary
|
||||
// is used.
|
||||
//
|
||||
// - Backward copies: Runs of one or more symbols are copied from previously
|
||||
// emitted data. Backward copies come as the tuple (dist, length) where dist
|
||||
// determines how far back in the stream to copy from and length determines how
|
||||
// many bytes to copy. Note that it is valid for the length to be greater than
|
||||
// the distance. Since LZ77 uses forward copies, that situation is used to
|
||||
// perform a form of run-length encoding on repeated runs of symbols.
|
||||
// The writeCopy and tryWriteCopy are used to implement this command.
|
||||
// * Backward copies: Runs of one or more symbols are copied from previously
|
||||
// emitted data. Backward copies come as the tuple (dist, length) where dist
|
||||
// determines how far back in the stream to copy from and length determines how
|
||||
// many bytes to copy. Note that it is valid for the length to be greater than
|
||||
// the distance. Since LZ77 uses forward copies, that situation is used to
|
||||
// perform a form of run-length encoding on repeated runs of symbols.
|
||||
// The writeCopy and tryWriteCopy are used to implement this command.
|
||||
//
|
||||
// For performance reasons, this implementation performs little to no sanity
|
||||
// checks about the arguments. As such, the invariants documented for each
|
||||
|
||||
@@ -194,9 +194,9 @@ func (w *huffmanBitWriter) writeBytes(bytes []byte) {
|
||||
// Codes 0-15 are single byte codes. Codes 16-18 are followed by additional
|
||||
// information. Code badCode is an end marker
|
||||
//
|
||||
// numLiterals The number of literals in literalEncoding
|
||||
// numOffsets The number of offsets in offsetEncoding
|
||||
// litenc, offenc The literal and offset encoder to use
|
||||
// numLiterals The number of literals in literalEncoding
|
||||
// numOffsets The number of offsets in offsetEncoding
|
||||
// litenc, offenc The literal and offset encoder to use
|
||||
func (w *huffmanBitWriter) generateCodegen(numLiterals int, numOffsets int, litEnc, offEnc *huffmanEncoder) {
|
||||
for i := range w.codegenFreq {
|
||||
w.codegenFreq[i] = 0
|
||||
@@ -353,9 +353,9 @@ func (w *huffmanBitWriter) writeCode(c hcode) {
|
||||
|
||||
// Write the header of a dynamic Huffman block to the output stream.
|
||||
//
|
||||
// numLiterals The number of literals specified in codegen
|
||||
// numOffsets The number of offsets specified in codegen
|
||||
// numCodegens The number of codegens used in codegen
|
||||
// numLiterals The number of literals specified in codegen
|
||||
// numOffsets The number of offsets specified in codegen
|
||||
// numCodegens The number of codegens used in codegen
|
||||
func (w *huffmanBitWriter) writeDynamicHeader(numLiterals int, numOffsets int, numCodegens int, isEof bool) {
|
||||
if w.err != nil {
|
||||
return
|
||||
|
||||
@@ -124,18 +124,13 @@ const maxBitsLimit = 16
|
||||
// The cases of 0, 1, and 2 literals are handled by special case code.
|
||||
//
|
||||
// list An array of the literals with non-zero frequencies
|
||||
//
|
||||
// and their associated frequencies. The array is in order of increasing
|
||||
// frequency, and has as its last element a special element with frequency
|
||||
// MaxInt32
|
||||
//
|
||||
// and their associated frequencies. The array is in order of increasing
|
||||
// frequency, and has as its last element a special element with frequency
|
||||
// MaxInt32
|
||||
// maxBits The maximum number of bits that should be used to encode any literal.
|
||||
//
|
||||
// Must be less than 16.
|
||||
//
|
||||
// Must be less than 16.
|
||||
// return An integer array in which array[i] indicates the number of literals
|
||||
//
|
||||
// that should be encoded in i bits.
|
||||
// that should be encoded in i bits.
|
||||
func (h *huffmanEncoder) bitCounts(list []literalNode, maxBits int32) []int32 {
|
||||
if maxBits >= maxBitsLimit {
|
||||
panic("flate: maxBits too large")
|
||||
|
||||
+14
-14
@@ -481,25 +481,25 @@ func scale(dst *block, src *[4]block) {
|
||||
}
|
||||
|
||||
// sosHeaderY is the SOS marker "\xff\xda" followed by 8 bytes:
|
||||
// - the marker length "\x00\x08",
|
||||
// - the number of components "\x01",
|
||||
// - component 1 uses DC table 0 and AC table 0 "\x01\x00",
|
||||
// - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
|
||||
// sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
|
||||
// should be 0x00, 0x3f, 0x00<<4 | 0x00.
|
||||
// - the marker length "\x00\x08",
|
||||
// - the number of components "\x01",
|
||||
// - component 1 uses DC table 0 and AC table 0 "\x01\x00",
|
||||
// - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
|
||||
// sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
|
||||
// should be 0x00, 0x3f, 0x00<<4 | 0x00.
|
||||
var sosHeaderY = []byte{
|
||||
0xff, 0xda, 0x00, 0x08, 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00,
|
||||
}
|
||||
|
||||
// sosHeaderYCbCr is the SOS marker "\xff\xda" followed by 12 bytes:
|
||||
// - the marker length "\x00\x0c",
|
||||
// - the number of components "\x03",
|
||||
// - component 1 uses DC table 0 and AC table 0 "\x01\x00",
|
||||
// - component 2 uses DC table 1 and AC table 1 "\x02\x11",
|
||||
// - component 3 uses DC table 1 and AC table 1 "\x03\x11",
|
||||
// - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
|
||||
// sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
|
||||
// should be 0x00, 0x3f, 0x00<<4 | 0x00.
|
||||
// - the marker length "\x00\x0c",
|
||||
// - the number of components "\x03",
|
||||
// - component 1 uses DC table 0 and AC table 0 "\x01\x00",
|
||||
// - component 2 uses DC table 1 and AC table 1 "\x02\x11",
|
||||
// - component 3 uses DC table 1 and AC table 1 "\x03\x11",
|
||||
// - the bytes "\x00\x3f\x00". Section B.2.3 of the spec says that for
|
||||
// sequential DCTs, those bytes (8-bit Ss, 8-bit Se, 4-bit Ah, 4-bit Al)
|
||||
// should be 0x00, 0x3f, 0x00<<4 | 0x00.
|
||||
var sosHeaderYCbCr = []byte{
|
||||
0xff, 0xda, 0x00, 0x0c, 0x03, 0x01, 0x00, 0x02,
|
||||
0x11, 0x03, 0x11, 0x00, 0x3f, 0x00,
|
||||
|
||||
+1
-3
@@ -326,9 +326,7 @@ func (d *decoder) parsetRNS(length uint32) error {
|
||||
|
||||
// Read presents one or more IDAT chunks as one continuous stream (minus the
|
||||
// intermediate chunk headers and footers). If the PNG data looked like:
|
||||
//
|
||||
// ... len0 IDAT xxx crc0 len1 IDAT yy crc1 len2 IEND crc2
|
||||
//
|
||||
// ... len0 IDAT xxx crc0 len1 IDAT yy crc1 len2 IEND crc2
|
||||
// then this reader presents xxxyy. For well-formed PNG data, the decoder state
|
||||
// immediately before the first Read call is that d.r is positioned between the
|
||||
// first IDAT and xxx, and the decoder state immediately after the last Read
|
||||
|
||||
@@ -43,6 +43,7 @@ func New(bus drivers.I2C) Device {
|
||||
// * VoltConvTime = CONVTIME_1100USEC
|
||||
// * CurrentConvTime = CONVTIME_1100USEC
|
||||
// * Mode = MODE_CONTINUOUS | MODE_VOLTAGE | MODE_CURRENT
|
||||
//
|
||||
func (d *Device) Configure(cfg Config) {
|
||||
var val uint16
|
||||
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
// https://www.adafruit.com/product/3163
|
||||
//
|
||||
// Datasheet:
|
||||
//
|
||||
// https://www.lumissil.com/assets/pdf/core/IS31FL3731_DS.pdf
|
||||
// https://www.lumissil.com/assets/pdf/core/IS31FL3731_DS.pdf
|
||||
//
|
||||
// This driver inspired by Adafruit Python driver:
|
||||
// https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731
|
||||
//
|
||||
// https://github.com/adafruit/Adafruit_CircuitPython_IS31FL3731
|
||||
package is31fl3731
|
||||
|
||||
import (
|
||||
|
||||
@@ -16,28 +16,29 @@ type DeviceAdafruitCharlieWing15x7 struct {
|
||||
// enableLEDs enables only LEDs that are soldered on the Adafruit CharlieWing
|
||||
// board. The board has following LEDs matrix layout:
|
||||
//
|
||||
// "o" - connected (soldered) LEDs
|
||||
// "x" - not connected LEDs
|
||||
// "o" - connected (soldered) LEDs
|
||||
// "x" - not connected LEDs
|
||||
//
|
||||
// + - - - - - - - - - - - - - - +
|
||||
// | + - - - - - - - - - - - - + |
|
||||
// | | | |
|
||||
// | | v v
|
||||
// +---------------------------------+
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | x x x x x x x x x x x x x x x x |
|
||||
// +---------------------------------+
|
||||
// ^ ^ | |
|
||||
// | | ... - - + |
|
||||
// | + - - - - - - - - - - - - - +
|
||||
// |
|
||||
// start (address 0x00)
|
||||
//
|
||||
// + - - - - - - - - - - - - - - +
|
||||
// | + - - - - - - - - - - - - + |
|
||||
// | | | |
|
||||
// | | v v
|
||||
// +---------------------------------+
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | o o o o o o o o o o o o o o o x |
|
||||
// | x x x x x x x x x x x x x x x x |
|
||||
// +---------------------------------+
|
||||
// ^ ^ | |
|
||||
// | | ... - - + |
|
||||
// | + - - - - - - - - - - - - - +
|
||||
// |
|
||||
// start (address 0x00)
|
||||
func (d *DeviceAdafruitCharlieWing15x7) enableLEDs() (err error) {
|
||||
for frame := FRAME_0; frame <= FRAME_7; frame++ {
|
||||
err = d.selectCommand(frame)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// typically used to control DC motors.
|
||||
//
|
||||
// Datasheet: https://www.ti.com/lit/ds/symlink/l293d.pdf
|
||||
//
|
||||
package l293x // import "tinygo.org/x/drivers/l293x"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// typically used to control DC motors.
|
||||
//
|
||||
// Datasheet: https://www.elecrow.com/download/datasheet-l9110.pdf
|
||||
//
|
||||
package l9110x // import "tinygo.org/x/drivers/l9110x"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// a magnetic sensor which is included on BBC micro:bit v1.5.
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lis2mdl.pdf
|
||||
//
|
||||
package lis2mdl // import "tinygo.org/x/drivers/lis2mdl"
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package lis3dh provides a driver for the LIS3DH digital accelerometer.
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lis3dh.pdf
|
||||
//
|
||||
package lis3dh // import "tinygo.org/x/drivers/lis3dh"
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package lps22hb implements a driver for LPS22HB, a MEMS nano pressure sensor.
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/dm00140895.pdf
|
||||
//
|
||||
package lps22hb
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// a 3 axis accelerometer/magnetic sensor which is included on BBC micro:bits v1.5.
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lsm303agr.pdf
|
||||
//
|
||||
package lsm303agr // import "tinygo.org/x/drivers/lsm303agr"
|
||||
|
||||
import (
|
||||
@@ -137,7 +138,7 @@ func (d *Device) Configure(cfg Configuration) (err error) {
|
||||
// -1000000.
|
||||
func (d *Device) ReadAcceleration() (x, y, z int32, err error) {
|
||||
data := d.buf[:6]
|
||||
err = d.bus.ReadRegister(uint8(d.AccelAddress), ACCEL_OUT_AUTO_INC, data)
|
||||
err = d.bus.ReadRegister(uint8(d.AccelAddress), ACCEL_OUT_X_L_A, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -190,7 +191,7 @@ func (d *Device) ReadMagneticField() (x, y, z int32, err error) {
|
||||
}
|
||||
|
||||
data := d.buf[0:6]
|
||||
d.bus.ReadRegister(uint8(d.MagAddress), MAG_OUT_AUTO_INC, data)
|
||||
d.bus.ReadRegister(uint8(d.MagAddress), MAG_OUT_X_L_M, data)
|
||||
|
||||
x = int32(int16((uint16(data[1])<<8 | uint16(data[0]))))
|
||||
y = int32(int16((uint16(data[3])<<8 | uint16(data[2]))))
|
||||
@@ -219,7 +220,7 @@ func (d *Device) ReadCompass() (h int32, err error) {
|
||||
func (d *Device) ReadTemperature() (t int32, err error) {
|
||||
|
||||
data := d.buf[:2]
|
||||
err = d.bus.ReadRegister(uint8(d.AccelAddress), OUT_TEMP_AUTO_INC, data)
|
||||
err = d.bus.ReadRegister(uint8(d.AccelAddress), OUT_TEMP_L_A, data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
+20
-29
@@ -6,40 +6,31 @@ const (
|
||||
ACCEL_ADDRESS = 0x19
|
||||
MAG_ADDRESS = 0x1E
|
||||
|
||||
// i2C 8-bit subaddress (SUB): the 7 LSb represent the actual register address
|
||||
// while the MSB enables address auto increment.
|
||||
// If the MSb of the SUB field is 1, the SUB (register address) is
|
||||
// automatically increased to allow multiple data read/writes.
|
||||
ADDR_AUTO_INC_MASK = 0x80
|
||||
|
||||
// accelerometer registers.
|
||||
ACCEL_WHO_AM_I = 0x0F
|
||||
ACCEL_CTRL_REG1_A = 0x20
|
||||
ACCEL_CTRL_REG4_A = 0x23
|
||||
ACCEL_OUT_X_L_A = 0x28
|
||||
ACCEL_OUT_X_H_A = 0x29
|
||||
ACCEL_OUT_Y_L_A = 0x2A
|
||||
ACCEL_OUT_Y_H_A = 0x2B
|
||||
ACCEL_OUT_Z_L_A = 0x2C
|
||||
ACCEL_OUT_Z_H_A = 0x2D
|
||||
ACCEL_OUT_AUTO_INC = ACCEL_OUT_X_L_A | ADDR_AUTO_INC_MASK
|
||||
ACCEL_WHO_AM_I = 0x0F
|
||||
ACCEL_CTRL_REG1_A = 0x20
|
||||
ACCEL_CTRL_REG4_A = 0x23
|
||||
ACCEL_OUT_X_L_A = 0x28
|
||||
ACCEL_OUT_X_H_A = 0x29
|
||||
ACCEL_OUT_Y_L_A = 0x2A
|
||||
ACCEL_OUT_Y_H_A = 0x2B
|
||||
ACCEL_OUT_Z_L_A = 0x2C
|
||||
ACCEL_OUT_Z_H_A = 0x2D
|
||||
|
||||
// magnetic sensor registers.
|
||||
MAG_WHO_AM_I = 0x4F
|
||||
MAG_MR_REG_M = 0x60
|
||||
MAG_OUT_X_L_M = 0x68
|
||||
MAG_OUT_X_H_M = 0x69
|
||||
MAG_OUT_Y_L_M = 0x6A
|
||||
MAG_OUT_Y_H_M = 0x6B
|
||||
MAG_OUT_Z_L_M = 0x6C
|
||||
MAG_OUT_Z_H_M = 0x6D
|
||||
MAG_OUT_AUTO_INC = MAG_OUT_X_L_M | ADDR_AUTO_INC_MASK
|
||||
MAG_WHO_AM_I = 0x4F
|
||||
MAG_MR_REG_M = 0x60
|
||||
MAG_OUT_X_L_M = 0x68
|
||||
MAG_OUT_X_H_M = 0x69
|
||||
MAG_OUT_Y_L_M = 0x6A
|
||||
MAG_OUT_Y_H_M = 0x6B
|
||||
MAG_OUT_Z_L_M = 0x6C
|
||||
MAG_OUT_Z_H_M = 0x6D
|
||||
|
||||
// temperature sensor registers.
|
||||
TEMP_CFG_REG_A = 0x1F
|
||||
OUT_TEMP_L_A = 0x0C
|
||||
OUT_TEMP_H_A = 0x0D
|
||||
OUT_TEMP_AUTO_INC = OUT_TEMP_L_A | ADDR_AUTO_INC_MASK
|
||||
TEMP_CFG_REG_A = 0x1F
|
||||
OUT_TEMP_L_A = 0x0C
|
||||
OUT_TEMP_H_A = 0x0D
|
||||
|
||||
// accelerometer power mode.
|
||||
ACCEL_POWER_NORMAL = 0x00 // default
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Measurement Unit (IMU)
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lsm6ds3.pdf
|
||||
//
|
||||
package lsm6ds3 // import "tinygo.org/x/drivers/lsm6ds3"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// a 6 axis Inertial Measurement Unit (IMU)
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lsm6ds3tr.pdf
|
||||
//
|
||||
package lsm6ds3tr // import "tinygo.org/x/drivers/lsm6ds3tr"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// a 6 axis Inertial Measurement Unit (IMU)
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lsm6dsox.pdf
|
||||
//
|
||||
package lsm6dsox // import "tinygo.org/x/drivers/lsm6dsox"
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// LSM9DS1, 9 axis Inertial Measurement Unit (IMU)
|
||||
//
|
||||
// Datasheet: https://www.st.com/resource/en/datasheet/lsm6ds3.pdf
|
||||
//
|
||||
package lsm9ds1 // import "tinygo.org/x/drivers/lsm9ds1"
|
||||
|
||||
import (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Freescale/NXP.
|
||||
//
|
||||
// Datasheet: https://www.nxp.com/docs/en/data-sheet/MAG3110.pdf
|
||||
//
|
||||
package mag3110 // import "tinygo.org/x/drivers/mag3110"
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
+25
-44
@@ -1,17 +1,11 @@
|
||||
package makeybutton
|
||||
|
||||
const (
|
||||
bufferSize = 3
|
||||
maxSumAllowed = 4
|
||||
)
|
||||
const bufferSize = 10
|
||||
|
||||
// Buffer is a buffer to keep track of the most recent readings for a button.
|
||||
// in bit form.
|
||||
type Buffer struct {
|
||||
data [bufferSize]byte
|
||||
byteCounter int
|
||||
bitCounter int
|
||||
sum int
|
||||
readings [bufferSize]bool
|
||||
index int
|
||||
}
|
||||
|
||||
// NewBuffer returns a new buffer.
|
||||
@@ -19,47 +13,34 @@ func NewBuffer() *Buffer {
|
||||
return &Buffer{}
|
||||
}
|
||||
|
||||
// Sum returns the sum of all measurements
|
||||
func (b *Buffer) Sum() int {
|
||||
return b.sum
|
||||
// Used returns how many bytes in buffer have been used.
|
||||
func (b *Buffer) Used() int {
|
||||
return b.index
|
||||
}
|
||||
|
||||
// Put stores a boolean button state into the buffer.
|
||||
func (b *Buffer) Put(val bool) {
|
||||
currentMeasurement, oldestMeasurement := b.updateData(val)
|
||||
b.updateCounters()
|
||||
|
||||
if currentMeasurement != 0 && b.sum < maxSumAllowed {
|
||||
b.sum++
|
||||
// Put stores a boolean in the buffer.
|
||||
func (b *Buffer) Put(val bool) bool {
|
||||
b.index++
|
||||
if b.index >= bufferSize {
|
||||
b.index = 0
|
||||
}
|
||||
|
||||
if oldestMeasurement != 0 && b.sum > 0 {
|
||||
b.sum--
|
||||
}
|
||||
b.readings[b.index] = val
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (b *Buffer) updateData(val bool) (byte, byte) {
|
||||
currentByte := b.data[b.byteCounter]
|
||||
oldestMeasurement := (currentByte >> b.bitCounter) & 0x01
|
||||
|
||||
if val {
|
||||
currentByte |= (1 << b.bitCounter)
|
||||
} else {
|
||||
currentByte &= ^(1 << b.bitCounter)
|
||||
}
|
||||
|
||||
b.data[b.byteCounter] = currentByte
|
||||
|
||||
return (currentByte >> b.bitCounter) & 0x01, oldestMeasurement
|
||||
}
|
||||
|
||||
func (b *Buffer) updateCounters() {
|
||||
b.bitCounter++
|
||||
if b.bitCounter == 8 {
|
||||
b.bitCounter = 0
|
||||
b.byteCounter++
|
||||
if b.byteCounter == bufferSize {
|
||||
b.byteCounter = 0
|
||||
// Avg returns the "average" of all the readings in the buffer, by
|
||||
// treating a true as 1 and a false as -1.
|
||||
func (b *Buffer) Avg() int {
|
||||
avg := 0
|
||||
for i := 0; i < bufferSize; i++ {
|
||||
if b.readings[i] {
|
||||
avg += 1
|
||||
} else {
|
||||
avg -= 1
|
||||
}
|
||||
}
|
||||
|
||||
return avg
|
||||
}
|
||||
|
||||
+23
-49
@@ -4,19 +4,9 @@
|
||||
// Inspired by the amazing MakeyMakey
|
||||
// https://makeymakey.com/
|
||||
//
|
||||
// This code is a reinterpretation of
|
||||
// https://github.com/sparkfun/MaKeyMaKey/blob/master/firmware/Arduino/makey_makey/makey_makey.ino
|
||||
package makeybutton
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
pressThreshold int = 1
|
||||
releaseThreshold int = 0
|
||||
)
|
||||
import "machine"
|
||||
|
||||
// ButtonState represents the state of a MakeyButton.
|
||||
type ButtonState int
|
||||
@@ -40,13 +30,15 @@ const (
|
||||
type Button struct {
|
||||
pin machine.Pin
|
||||
state ButtonState
|
||||
pressed bool
|
||||
readings *Buffer
|
||||
HighMeansPressed bool
|
||||
}
|
||||
|
||||
// NewButton creates a new Button.
|
||||
func NewButton(pin machine.Pin) *Button {
|
||||
pin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
pin.Set(false)
|
||||
|
||||
return &Button{
|
||||
pin: pin,
|
||||
state: NeverPressed,
|
||||
@@ -55,51 +47,33 @@ func NewButton(pin machine.Pin) *Button {
|
||||
}
|
||||
}
|
||||
|
||||
// Configure configures the Makey Button pin to have the correct settings to detect touches.
|
||||
func (b *Button) Configure() error {
|
||||
// Note that on AVR we have to first turn on the pullup, and then turn off the pullup,
|
||||
// in order for the pin to be properly floating.
|
||||
b.pin.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
b.pin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
b.pin.Set(false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get returns a ButtonEvent based on the most recent state of the button,
|
||||
// and if it has changed by being pressed or released.
|
||||
func (b *Button) Get() ButtonEvent {
|
||||
b.update()
|
||||
// if pin is pulled up, a low value means the key is pressed
|
||||
pressed := !b.pin.Get()
|
||||
if b.HighMeansPressed {
|
||||
// otherwise, a high value means the key is pressed
|
||||
pressed = !pressed
|
||||
}
|
||||
|
||||
if b.pressed {
|
||||
// the button had previously been pressed,
|
||||
// but now appears to have been released.
|
||||
if b.readings.Sum() <= releaseThreshold {
|
||||
b.pressed = false
|
||||
avg := b.readings.Avg()
|
||||
b.readings.Put(pressed)
|
||||
|
||||
switch {
|
||||
case pressed && avg > 0:
|
||||
if b.state == Press {
|
||||
return NotChanged
|
||||
}
|
||||
|
||||
b.state = Press
|
||||
return Pressed
|
||||
case !pressed:
|
||||
if b.state == Press {
|
||||
b.state = Release
|
||||
return Released
|
||||
}
|
||||
} else {
|
||||
// the button had previously not been pressed,
|
||||
// but now appears to have been pressed.
|
||||
if b.readings.Sum() >= pressThreshold {
|
||||
b.pressed = true
|
||||
b.state = Press
|
||||
return Pressed
|
||||
}
|
||||
}
|
||||
|
||||
return NotChanged
|
||||
}
|
||||
|
||||
func (b *Button) update() {
|
||||
// if pin is pulled up, a low value means the key is pressed
|
||||
press := !b.pin.Get()
|
||||
if b.HighMeansPressed {
|
||||
// otherwise, a high value means the key is pressed
|
||||
press = !press
|
||||
}
|
||||
|
||||
b.readings.Put(press)
|
||||
}
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@ func (d *Device) GetPins() (Pins, error) {
|
||||
//
|
||||
// That is, it does the equivalent of:
|
||||
//
|
||||
// for i := 0; i < PinCount; i++ {
|
||||
// for i := 0; i < PinCount; i++ {
|
||||
// if mask.Get(i) {
|
||||
// d.Pin(i).Set(pins.Get(i))
|
||||
// }
|
||||
|
||||
@@ -93,7 +93,7 @@ func (devs Devices) GetPins(pins PinSlice) error {
|
||||
//
|
||||
// That is, it does the equivalent of:
|
||||
//
|
||||
// for i := 0; i < PinCount*len(devs); i++ {
|
||||
// for i := 0; i < PinCount*len(devs); i++ {
|
||||
// if mask.Get(i) {
|
||||
// d.Pin(i).Set(pins.Get(i))
|
||||
// }
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package mcp2515 implements a driver for the MCP2515 CAN Controller.
|
||||
//
|
||||
// Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Stand-Alone-CAN-Controller-with-SPI-20001801J.pdf
|
||||
//
|
||||
package mcp2515 // import "tinygo.org/x/drivers/mcp2515"
|
||||
|
||||
const DebugEn = 0
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Package mcp3008 implements a driver for the MCP3008 Analog to Digital Converter.
|
||||
//
|
||||
// Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21295d.pdf
|
||||
//
|
||||
package mcp3008 // import "tinygo.org/x/drivers/mcp3008"
|
||||
|
||||
import (
|
||||
|
||||
@@ -4,16 +4,14 @@
|
||||
// Package microbitmatrix implements a driver for the BBC micro:bit's LED matrix.
|
||||
//
|
||||
// Schematic: https://github.com/bbcmicrobit/hardware/blob/master/SCH_BBC-Microbit_V1.3B.pdf
|
||||
//
|
||||
package microbitmatrix // import "tinygo.org/x/drivers/microbitmatrix"
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 4 rotation orientations (0, 90, 180, 270), CW (clock wise)
|
||||
// 5 rows
|
||||
// 5 cols
|
||||
// target coordinates in machine rows (y) and cols (x)
|
||||
var matrixRotations = [4][5][5][2]uint8{
|
||||
{ // 0
|
||||
{{0, 0}, {1, 3}, {0, 1}, {1, 4}, {0, 2}},
|
||||
@@ -22,7 +20,7 @@ var matrixRotations = [4][5][5][2]uint8{
|
||||
{{0, 7}, {0, 6}, {0, 5}, {0, 4}, {0, 3}},
|
||||
{{2, 2}, {1, 6}, {2, 0}, {1, 5}, {2, 1}},
|
||||
},
|
||||
{ // 90 CW
|
||||
{ // 90 CCW
|
||||
{{0, 2}, {2, 7}, {1, 0}, {0, 3}, {2, 1}},
|
||||
{{1, 4}, {2, 6}, {2, 8}, {0, 4}, {1, 5}},
|
||||
{{0, 1}, {2, 5}, {1, 2}, {0, 5}, {2, 0}},
|
||||
@@ -45,33 +43,71 @@ var matrixRotations = [4][5][5][2]uint8{
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
ledRows = 3
|
||||
ledCols = 9
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
pin [ledCols + ledRows]machine.Pin
|
||||
buffer [ledRows][ledCols]int8
|
||||
pin [12]machine.Pin
|
||||
buffer [3][9]bool
|
||||
rotation uint8
|
||||
}
|
||||
|
||||
func (d *Device) assignPins() {
|
||||
d.pin[0] = machine.LED_COL_1
|
||||
d.pin[1] = machine.LED_COL_2
|
||||
d.pin[2] = machine.LED_COL_3
|
||||
d.pin[3] = machine.LED_COL_4
|
||||
d.pin[4] = machine.LED_COL_5
|
||||
d.pin[5] = machine.LED_COL_6
|
||||
d.pin[6] = machine.LED_COL_7
|
||||
d.pin[7] = machine.LED_COL_8
|
||||
d.pin[8] = machine.LED_COL_9
|
||||
// Configure sets up the device.
|
||||
func (d *Device) Configure(cfg Config) {
|
||||
d.SetRotation(cfg.Rotation)
|
||||
|
||||
d.pin[9] = machine.LED_ROW_1
|
||||
d.pin[10] = machine.LED_ROW_2
|
||||
d.pin[11] = machine.LED_ROW_3
|
||||
for i := machine.LED_COL_1; i <= machine.LED_ROW_3; i++ {
|
||||
d.pin[i-machine.LED_COL_1] = i
|
||||
d.pin[i-machine.LED_COL_1].Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
}
|
||||
d.ClearDisplay()
|
||||
d.DisableAll()
|
||||
}
|
||||
|
||||
for i := 0; i < len(d.pin); i++ {
|
||||
d.pin[i].Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
// Display sends the buffer (if any) to the screen.
|
||||
func (d *Device) Display() error {
|
||||
for row := 0; row < 3; row++ {
|
||||
d.DisableAll()
|
||||
d.pin[9+row].High()
|
||||
|
||||
for col := 0; col < 9; col++ {
|
||||
if d.buffer[row][col] {
|
||||
d.pin[col].Low()
|
||||
}
|
||||
|
||||
}
|
||||
time.Sleep(time.Millisecond * 2)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearDisplay erases the internal buffer
|
||||
func (d *Device) ClearDisplay() {
|
||||
for row := 0; row < 3; row++ {
|
||||
for col := 0; col < 9; col++ {
|
||||
d.buffer[row][col] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DisableAll disables all the LEDs without modifying the buffer
|
||||
func (d *Device) DisableAll() {
|
||||
for i := machine.LED_COL_1; i <= machine.LED_COL_9; i++ {
|
||||
d.pin[i-machine.LED_COL_1].High()
|
||||
}
|
||||
for i := machine.LED_ROW_1; i <= machine.LED_ROW_3; i++ {
|
||||
d.pin[i-machine.LED_COL_1].Low()
|
||||
}
|
||||
}
|
||||
|
||||
// EnableAll enables all the LEDs without modifying the buffer
|
||||
func (d *Device) EnableAll() {
|
||||
for i := machine.LED_COL_1; i <= machine.LED_COL_9; i++ {
|
||||
d.pin[i-machine.LED_COL_1].Low()
|
||||
}
|
||||
for i := machine.LED_ROW_1; i <= machine.LED_ROW_3; i++ {
|
||||
d.pin[i-machine.LED_COL_1].High()
|
||||
}
|
||||
}
|
||||
|
||||
// Size returns the current size of the display.
|
||||
func (d *Device) Size() (w, h int16) {
|
||||
return 5, 5
|
||||
}
|
||||
|
||||
@@ -3,60 +3,56 @@
|
||||
|
||||
// Package microbitmatrix implements a driver for the BBC micro:bit version 2 LED matrix.
|
||||
//
|
||||
// Schematic: https://github.com/microbit-foundation/microbit-v2-hardware/blob/main/V2.00/MicroBit_V2.0.0_S_schematic.PDF
|
||||
// Schematic:
|
||||
//
|
||||
package microbitmatrix // import "tinygo.org/x/drivers/microbitmatrix"
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 4 rotation orientations (0, 90, 180, 270), CW (clock wise)
|
||||
// 5 rows
|
||||
// 5 cols
|
||||
// target coordinates in machine rows (y) and cols (x)
|
||||
var matrixRotations = [4][5][5][2]uint8{
|
||||
{ // 0
|
||||
{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}},
|
||||
{{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}},
|
||||
{{2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}},
|
||||
{{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}},
|
||||
{{4, 0}, {4, 1}, {4, 2}, {4, 3}, {4, 4}},
|
||||
},
|
||||
{ // 90 CW
|
||||
{{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}},
|
||||
{{0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}},
|
||||
{{0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}},
|
||||
{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}},
|
||||
{{0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}},
|
||||
{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}},
|
||||
{{0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}},
|
||||
{{0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}},
|
||||
{{0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}},
|
||||
},
|
||||
{ // 90 CCW
|
||||
{{4, 0}, {4, 1}, {4, 2}, {4, 3}, {4, 4}},
|
||||
{{3, 0}, {3, 1}, {3, 2}, {3, 3}, {3, 4}},
|
||||
{{2, 0}, {2, 1}, {2, 2}, {2, 3}, {2, 4}},
|
||||
{{1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}},
|
||||
{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}},
|
||||
},
|
||||
{ // 180
|
||||
{{4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}},
|
||||
{{3, 4}, {3, 3}, {3, 2}, {3, 1}, {3, 0}},
|
||||
{{2, 4}, {2, 3}, {2, 2}, {2, 1}, {2, 0}},
|
||||
{{1, 4}, {1, 3}, {1, 2}, {1, 1}, {1, 0}},
|
||||
{{0, 4}, {0, 3}, {0, 2}, {0, 1}, {0, 0}},
|
||||
{{4, 4}, {3, 4}, {2, 4}, {1, 4}, {0, 4}},
|
||||
{{4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}},
|
||||
{{4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}},
|
||||
{{4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}},
|
||||
{{4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}},
|
||||
},
|
||||
{ // 270
|
||||
{{4, 0}, {3, 0}, {2, 0}, {1, 0}, {0, 0}},
|
||||
{{4, 1}, {3, 1}, {2, 1}, {1, 1}, {0, 1}},
|
||||
{{4, 2}, {3, 2}, {2, 2}, {1, 2}, {0, 2}},
|
||||
{{4, 3}, {3, 3}, {2, 3}, {1, 3}, {0, 3}},
|
||||
{{4, 4}, {3, 4}, {2, 4}, {1, 4}, {0, 4}},
|
||||
{{0, 4}, {0, 3}, {0, 2}, {0, 1}, {0, 0}},
|
||||
{{1, 4}, {1, 3}, {1, 2}, {1, 1}, {1, 0}},
|
||||
{{2, 4}, {2, 3}, {2, 2}, {2, 1}, {2, 0}},
|
||||
{{3, 4}, {3, 3}, {3, 2}, {3, 1}, {3, 0}},
|
||||
{{4, 4}, {4, 3}, {4, 2}, {4, 1}, {4, 0}},
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
ledRows = 5
|
||||
ledCols = 5
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
pin [ledCols + ledRows]machine.Pin
|
||||
buffer [ledRows][ledCols]int8
|
||||
pin [10]machine.Pin
|
||||
buffer [5][5]bool
|
||||
rotation uint8
|
||||
}
|
||||
|
||||
func (d *Device) assignPins() {
|
||||
// Configure sets up the device.
|
||||
func (d *Device) Configure(cfg Config) {
|
||||
d.SetRotation(cfg.Rotation)
|
||||
|
||||
d.pin[0] = machine.LED_COL_1
|
||||
d.pin[1] = machine.LED_COL_2
|
||||
d.pin[2] = machine.LED_COL_3
|
||||
@@ -69,7 +65,59 @@ func (d *Device) assignPins() {
|
||||
d.pin[8] = machine.LED_ROW_4
|
||||
d.pin[9] = machine.LED_ROW_5
|
||||
|
||||
for i := 0; i < len(d.pin); i++ {
|
||||
for i := 0; i < 10; i++ {
|
||||
d.pin[i].Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
}
|
||||
|
||||
d.ClearDisplay()
|
||||
d.DisableAll()
|
||||
}
|
||||
|
||||
// Display sends the buffer (if any) to the screen.
|
||||
func (d *Device) Display() error {
|
||||
for x := 0; x < 5; x++ {
|
||||
d.DisableAll()
|
||||
d.pin[x].Low()
|
||||
|
||||
for y := 0; y < 5; y++ {
|
||||
if d.buffer[x][y] {
|
||||
d.pin[5+y].High()
|
||||
} else {
|
||||
d.pin[5+y].Low()
|
||||
}
|
||||
|
||||
}
|
||||
time.Sleep(time.Millisecond * 4)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearDisplay erases the internal buffer
|
||||
func (d *Device) ClearDisplay() {
|
||||
for row := 0; row < 5; row++ {
|
||||
for col := 0; col < 5; col++ {
|
||||
d.buffer[row][col] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DisableAll disables all the LEDs without modifying the buffer
|
||||
func (d *Device) DisableAll() {
|
||||
for i := 0; i < 5; i++ {
|
||||
d.pin[i].High()
|
||||
d.pin[5+i].Low()
|
||||
}
|
||||
}
|
||||
|
||||
// EnableAll enables all the LEDs without modifying the buffer
|
||||
func (d *Device) EnableAll() {
|
||||
for i := 0; i < 5; i++ {
|
||||
d.pin[i].Low()
|
||||
d.pin[5+i].High()
|
||||
}
|
||||
}
|
||||
|
||||
// Size returns the current size of the display.
|
||||
func (d *Device) Size() (w, h int16) {
|
||||
return 5, 5
|
||||
}
|
||||
|
||||
@@ -1,213 +1,43 @@
|
||||
// Package microbitmatrix implements a driver for the BBC micro:bit's LED matrix.
|
||||
//
|
||||
// Schematic: https://github.com/bbcmicrobit/hardware/blob/master/SCH_BBC-Microbit_V1.3B.pdf
|
||||
//
|
||||
package microbitmatrix // import "tinygo.org/x/drivers/microbitmatrix"
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
// Rotation of the LED matrix.
|
||||
//
|
||||
// Valid values:
|
||||
//
|
||||
// 0: regular orientation, (0 degree rotation)
|
||||
// 1: 90 degree rotation clock wise
|
||||
// 2: 180 degree rotation clock wise
|
||||
// 3: 270 degree rotation clock wise
|
||||
Rotation uint8
|
||||
}
|
||||
|
||||
const (
|
||||
RotationNormal = 0
|
||||
Rotation90 = 1
|
||||
Rotation180 = 2
|
||||
Rotation270 = 3
|
||||
)
|
||||
|
||||
// New returns a new microbitmatrix driver.
|
||||
func New() Device {
|
||||
return Device{}
|
||||
}
|
||||
|
||||
// Configure sets up the device.
|
||||
func (d *Device) Configure(cfg Config) {
|
||||
d.SetRotation(cfg.Rotation)
|
||||
|
||||
d.assignPins()
|
||||
|
||||
d.ClearDisplay()
|
||||
d.DisableAll()
|
||||
}
|
||||
|
||||
// SetRotation changes the rotation of the LED matrix.
|
||||
//
|
||||
// Valid values for rotation:
|
||||
//
|
||||
// 0: regular orientation, (0 degree rotation)
|
||||
// 1: 90 degree rotation clock wise
|
||||
// 2: 180 degree rotation clock wise
|
||||
// 3: 270 degree rotation clock wise
|
||||
// SetRotation changes the rotation of the LED matrix
|
||||
func (d *Device) SetRotation(rotation uint8) {
|
||||
d.rotation = rotation % 4
|
||||
}
|
||||
|
||||
// Source:
|
||||
// https://github.com/bbcmicrobit/micropython/blob/1252f887ddc790676bf9314a136bd17650b9c36c/source/microbit/microbitdisplay.cpp#L282
|
||||
var renderTimings = []time.Duration{
|
||||
0, // Bright, Ticks Duration, Relative power
|
||||
2, // 1, 2, 32µs, inf
|
||||
2, // 2, 4, 64µs, 200%
|
||||
4, // 3, 8, 128µs, 200%
|
||||
7, // 4, 15, 240µs, 187%
|
||||
13, // 5, 28, 448µs, 187%
|
||||
25, // 6, 53, 848µs, 189%
|
||||
49, // 7, 102, 1632µs, 192%
|
||||
97, // 8, 199, 3184µs, 195%
|
||||
}
|
||||
|
||||
// Source:
|
||||
// https://github.com/bbcmicrobit/micropython/blob/1252f887ddc790676bf9314a136bd17650b9c36c/source/microbit/microbitdisplay.cpp#L368
|
||||
const tickDuration = 16 * time.Microsecond
|
||||
|
||||
const (
|
||||
rowIdx = 0
|
||||
colIdx = 1
|
||||
)
|
||||
|
||||
// SetPixel modifies the internal buffer in a single pixel.
|
||||
//
|
||||
// The alpha channel of the RGBA is used to control the brightness of the LED
|
||||
// in 9 different levels.
|
||||
//
|
||||
// alpha channel, brightness level
|
||||
// 0 - 27, 9 (no transparency = highest brightness)
|
||||
// 28 - 55, 8
|
||||
// 56 - 83, 7
|
||||
// 84 - 111, 6
|
||||
// 112 - 139, 5
|
||||
// 140 - 167, 4
|
||||
// 168 - 195, 3
|
||||
// 196 - 223, 2
|
||||
// 224 - 251, 1 (very high transparency = lowest brightness)
|
||||
// 252 - 255, 0 (full transparency = off)
|
||||
func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
|
||||
if x < 0 || x >= 5 || y < 0 || y >= 5 {
|
||||
return
|
||||
}
|
||||
col := x
|
||||
row := y
|
||||
if c.R != 0 || c.G != 0 || c.B != 0 {
|
||||
d.buffer[matrixRotations[d.rotation][row][col][rowIdx]][matrixRotations[d.rotation][row][col][colIdx]] = brightness(c.A)
|
||||
d.buffer[matrixRotations[d.rotation][x][y][0]][matrixRotations[d.rotation][x][y][1]] = true
|
||||
} else {
|
||||
d.buffer[matrixRotations[d.rotation][row][col][rowIdx]][matrixRotations[d.rotation][row][col][colIdx]] = 0
|
||||
d.buffer[matrixRotations[d.rotation][x][y][0]][matrixRotations[d.rotation][x][y][1]] = false
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
brightnessLevels = 9
|
||||
brightnessDivider = int8(255 / brightnessLevels)
|
||||
)
|
||||
|
||||
var (
|
||||
Brightness0 = color.RGBA{R: 0, G: 0, B: 0, A: 0}
|
||||
Brightness1 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*1}
|
||||
Brightness2 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*2}
|
||||
Brightness3 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*3}
|
||||
Brightness4 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*4}
|
||||
Brightness5 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*5}
|
||||
Brightness6 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*6}
|
||||
Brightness7 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*7}
|
||||
Brightness8 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*8}
|
||||
Brightness9 = color.RGBA{R: 255, G: 255, B: 255, A: 255 - uint8(brightnessDivider)*9}
|
||||
|
||||
BrightnessOff = Brightness0
|
||||
BrightnessFull = Brightness9
|
||||
)
|
||||
|
||||
func brightness(alpha uint8) int8 {
|
||||
return brightnessLevels - int8(alpha/uint8(brightnessDivider))
|
||||
}
|
||||
|
||||
// GetPixel returns if the specific pixels is enabled.
|
||||
// GetPixel returns if the specific pixels is enabled
|
||||
func (d *Device) GetPixel(x int16, y int16) bool {
|
||||
if x < 0 || x >= 5 || y < 0 || y >= 5 {
|
||||
return false
|
||||
}
|
||||
col := x
|
||||
row := y
|
||||
return d.buffer[matrixRotations[d.rotation][row][col][rowIdx]][matrixRotations[d.rotation][row][col][colIdx]] > 0
|
||||
}
|
||||
|
||||
const displayRefreshDelay = 8 * time.Millisecond
|
||||
|
||||
// Display sends the buffer (if any) to the screen.
|
||||
func (d *Device) Display() error {
|
||||
var displayBuffer [ledRows][ledCols]int8
|
||||
for row := 0; row < ledRows; row++ {
|
||||
for col := 0; col < ledCols; col++ {
|
||||
displayBuffer[row][col] = d.buffer[row][col]
|
||||
}
|
||||
}
|
||||
|
||||
for row := 0; row < ledRows; row++ {
|
||||
d.DisableAll()
|
||||
d.pin[ledCols+row].High()
|
||||
|
||||
for col := 0; col < ledCols; col++ {
|
||||
if displayBuffer[row][col] > 0 {
|
||||
d.pin[col].Low()
|
||||
}
|
||||
}
|
||||
|
||||
then := time.Now()
|
||||
var offset time.Duration = 0
|
||||
for _, ticks := range renderTimings {
|
||||
for time.Since(then).Nanoseconds() < int64(ticks*tickDuration+offset) {
|
||||
time.Sleep(offset / 10)
|
||||
}
|
||||
offset += ticks + tickDuration
|
||||
for col := 0; col < ledCols; col++ {
|
||||
displayBuffer[row][col]--
|
||||
if displayBuffer[row][col] <= 0 {
|
||||
d.pin[col].High()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(displayRefreshDelay)
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearDisplay erases the internal buffer.
|
||||
func (d *Device) ClearDisplay() {
|
||||
for row := 0; row < ledRows; row++ {
|
||||
for col := 0; col < ledCols; col++ {
|
||||
d.buffer[row][col] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// DisableAll disables all the LEDs without modifying the buffer.
|
||||
func (d *Device) DisableAll() {
|
||||
for i := 0; i < ledCols; i++ {
|
||||
d.pin[i].High()
|
||||
}
|
||||
for i := 0; i < ledRows; i++ {
|
||||
d.pin[ledCols+i].Low()
|
||||
}
|
||||
}
|
||||
|
||||
// EnableAll enables all the LEDs without modifying the buffer.
|
||||
func (d *Device) EnableAll() {
|
||||
for i := 0; i < ledCols; i++ {
|
||||
d.pin[i].Low()
|
||||
}
|
||||
for i := 0; i < ledRows; i++ {
|
||||
d.pin[ledCols+i].High()
|
||||
}
|
||||
}
|
||||
|
||||
// Size returns the current size of the display.
|
||||
func (d *Device) Size() (w, h int16) {
|
||||
return 5, 5
|
||||
return d.buffer[matrixRotations[d.rotation][x][y][0]][matrixRotations[d.rotation][x][y][1]]
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// For example, the Adafruit PDM MEMS breakout board (https://www.adafruit.com/product/3492)
|
||||
//
|
||||
// Datasheet: https://cdn-learn.adafruit.com/assets/assets/000/049/977/original/MP34DT01-M.pdf
|
||||
//
|
||||
package microphone // import "tinygo.org/x/drivers/microphone"
|
||||
|
||||
import (
|
||||
@@ -140,6 +141,7 @@ func (d *Device) GetSoundPressure() (int32, int32) {
|
||||
// for that sample.
|
||||
//
|
||||
// For more information: https://en.wikipedia.org/wiki/Sinc_filter
|
||||
//
|
||||
var sincfilter = [quantizeSteps]uint16{
|
||||
0, 2, 9, 21, 39, 63, 94, 132,
|
||||
179, 236, 302, 379, 467, 565, 674, 792,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
//
|
||||
// Datasheet:
|
||||
// https://www.nxp.com/docs/en/data-sheet/MMA8653FC.pdf
|
||||
//
|
||||
package mma8653 // import "tinygo.org/x/drivers/mma8653"
|
||||
|
||||
import "tinygo.org/x/drivers"
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user