Compare commits

..

23 Commits

Author SHA1 Message Date
sago35 349b5ca87e WIP: net/http RoundTripper 2022-12-08 22:28:27 +09:00
Lucas Bremgartner c5dbe18be1 lsm303agr: fix I2C address auto increment for multi data read
fixes: #475
2022-10-31 10:02:44 +01:00
Andy Janata 2bca84b8d1 remove unused import 2022-10-29 23:39:52 +02:00
Lucas Bremgartner 690daebcd1 microbitmatrix: add smoke test for microbitmatrix with microbit-v2 2022-10-29 22:49:31 +02:00
Lucas Bremgartner 89770a7d05 microbitmatrix: add support for brightness of led pixels
Inspired by brightness levels in micro:bit MicroPython
2022-10-29 22:49:31 +02:00
Lucas Bremgartner 8a39bb7aae microbitmatrix: harmonize v1 and v2 implementation 2022-10-29 22:49:31 +02:00
Lucas Bremgartner a106fd48ce microbitmatrix: move Size() to verion agnostic part 2022-10-29 22:49:31 +02:00
Lucas Bremgartner b2fdd3c333 microbitmatrix: add link to schema for microbit V2 2022-10-29 22:49:31 +02:00
Ayke van Laethem 42dc6eb068 mpu6050: return I2C error when configuring fails
An I2C bus can generate errors (like any I/O can), but they weren't
returned. This commit fixes this oversight.

Found while trying to figure out why LLVM 15 is broken just for the
itsybitsy-m4.
2022-10-18 20:32:33 +02:00
Rafael Badiale c00cb3abdd qmi8658c: Add support for the QMI8658C sensor (#467)
* Add support for the QMI8658C sensor

* qmi8656c: update ReadTemperature signature

* Update README devices count
2022-10-02 14:14:37 +02:00
deadprogram 81bc1bcad1 all: prepare for release 0.23.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-10-01 23:07:23 +02:00
deadprogram 1bb1b621c6 all: correct go fmt
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-25 13:23:16 +02:00
Lucas Bremgartner 98ba5a231a microbitmatrix: fix inverted axis
Resolves #460
2022-09-24 13:19:37 +02:00
sago35 5af2512901 espat,wifinina,rtl8720dn: change ssid/pass from const to var 2022-09-24 11:34:29 +02:00
Lucas Matte 4061adf6db Add GC9A01 Driver (#452)
* Added driver for gc9a01 round display and example code
2022-09-18 15:22:07 +02:00
Alexandre Jomin 7133c2e9db feat(ssd1306): add getter method to the current buffer 2022-09-16 18:51:10 +02:00
deadprogram 0ea72e7f1e makeybutton: revise to better match the algorithm defined by the original
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-16 18:34:36 +02:00
sago35 7396a5be43 examples/rtl8720dn: remove wifi setting 2022-09-06 13:51:46 +02:00
deadprogram c409e8f3cf examples/rtl8720dn: add call to optional debug setting
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-06 13:29:15 +02:00
deadprogram a6a8d478b9 examples/rtl8720dn: update all remaining examples for refactored API
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-06 13:29:15 +02:00
deadprogram 54ddb895cc rtl8720dn: refactor by bringing this driver more in line with wifinina and espat
Signed-off-by: deadprogram <ron@hybridgroup.com>
2022-09-06 13:29:15 +02:00
Daniel Esteban 6f05615f3e Initial support for VL6180x sensor
required changes
2022-09-05 16:04:30 +02:00
Arsen6331 2a2e897261 Trim quotes from IP returned by espat's GetDNS() 2022-08-19 18:55:09 +02:00
143 changed files with 2461 additions and 1513 deletions
+31
View File
@@ -1,3 +1,34 @@
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**
+8
View File
@@ -53,6 +53,8 @@ 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
@@ -101,6 +103,8 @@ 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
@@ -143,6 +147,8 @@ 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
@@ -205,6 +211,8 @@ 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
+9 -6
View File
@@ -52,7 +52,7 @@ func main() {
## Currently supported devices
The following 82 devices are supported.
The following 90 devices are supported.
| Device Name | Interface Type |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
@@ -97,10 +97,10 @@ The following 82 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,9 +112,10 @@ The following 82 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 |
@@ -132,13 +133,15 @@ The following 82 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 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
View File
@@ -1,7 +1,6 @@
// 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 (
-1
View File
@@ -3,7 +3,6 @@
// 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"
-1
View File
@@ -2,7 +2,6 @@
// 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 (
-2
View File
@@ -3,8 +3,6 @@
package apds9960
import "tinygo.org/x/drivers"
// Configure sets up the APDS-9960 device.
func (d *Device) Configure(cfg Configuration) {
// configure device
-1
View File
@@ -3,7 +3,6 @@
//
// 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 (
-1
View File
@@ -2,7 +2,6 @@
//
// Datasheet:
// https://www.mouser.com/ds/2/348/bh1750fvi-e-186247.pdf
//
package bh1750 // import "tinygo.org/x/drivers/bh1750"
import (
-1
View File
@@ -1,7 +1,6 @@
// 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
View File
@@ -3,7 +3,6 @@
//
// Datasheet:
// https://cdn-shop.adafruit.com/datasheets/BST-BME280_DS001-10.pdf
//
package bme280
import (
@@ -149,7 +148,8 @@ 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
-1
View File
@@ -3,7 +3,6 @@
//
// Datasheet:
// https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf
//
package bmp180 // import "tinygo.org/x/drivers/bmp180"
import (
-1
View File
@@ -1,5 +1,4 @@
// Package buzzer provides a very simplistic driver for a connected buzzer or low-fidelity speaker.
//
package buzzer // import "tinygo.org/x/drivers/buzzer"
import (
+7 -8
View File
@@ -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,5 +38,4 @@
// 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"
-1
View File
@@ -2,7 +2,6 @@
//
// Datasheet:
// https://datasheets.maximintegrated.com/en/ds/DS1307.pdf
//
package ds1307 // import "tinygo.org/x/drivers/ds1307"
import (
-1
View File
@@ -15,7 +15,6 @@
//
// 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
View File
@@ -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 res[0], nil
return strings.Trim(res[0], `"`), nil
}
// ConnectTCPSocket creates a new TCP socket connection for the ESP8266/ESP32.
+5 -4
View File
@@ -6,7 +6,6 @@
//
// 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 (
@@ -19,9 +18,11 @@ import (
// change actAsAP to true to act as an access point instead of connecting to one.
const actAsAP = false
// access point info
const ssid = "YOURSSID"
const pass = "YOURPASS"
var (
// access point info
ssid string
pass string
)
// these are the default pins for the Arduino Nano33 IoT.
// change these to connect to a different UART or pins for the ESP8266/ESP32
+5 -4
View File
@@ -3,7 +3,6 @@
//
// In other words:
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266 <--> INTERNET
//
package main
import (
@@ -17,9 +16,11 @@ import (
// change actAsAP to true to act as an access point instead of connecting to one.
const actAsAP = false
// access point info
const ssid = "YOURSSID"
const pass = "YOURPASS"
var (
// access point info
ssid string
pass string
)
// these are the default pins for the Arduino Nano33 IoT.
// change these to connect to a different UART or pins for the ESP8266/ESP32
+5 -4
View File
@@ -3,7 +3,6 @@
//
// In other words:
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266
//
package main
import (
@@ -14,9 +13,11 @@ import (
"tinygo.org/x/drivers/net"
)
// access point info
const ssid = "YOURSSID"
const pass = "YOURPASS"
var (
// access point info
ssid string
pass string
)
// IP address of the listener aka "hub". Replace with your own info.
const hubIP = "0.0.0.0"
+6 -5
View File
@@ -7,8 +7,7 @@
//
// 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,9 +19,11 @@ import (
"tinygo.org/x/drivers/net/mqtt"
)
// access point info
const ssid = "YOURSSID"
const pass = "YOURPASS"
var (
// access point info
ssid string
pass string
)
// IP address of the MQTT broker to use. Replace with your own info.
const server = "tcp://test.mosquitto.org:1883"
+6 -5
View File
@@ -7,8 +7,7 @@
//
// 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 (
@@ -21,9 +20,11 @@ import (
"tinygo.org/x/drivers/net/mqtt"
)
// access point info
const ssid = "YOURSSID"
const pass = "YOURPASS"
var (
// access point info
ssid string
pass string
)
// IP address of the MQTT broker to use. Replace with your own info.
//const server = "tcp://test.mosquitto.org:1883"
+5 -4
View File
@@ -3,7 +3,6 @@
//
// In other words:
// Your computer <--> UART0 <--> MCU <--> UART1 <--> ESP8266
//
package main
import (
@@ -14,9 +13,11 @@ import (
"tinygo.org/x/drivers/net"
)
// access point info
const ssid = "YOURSSID"
const pass = "YOURPASS"
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const serverIP = "0.0.0.0"
+39
View File
@@ -0,0 +1,39 @@
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)
}
}
-2
View File
@@ -9,8 +9,6 @@ import (
"tinygo.org/x/drivers/ili9341"
)
var ()
func InitDisplay() *ili9341.Device {
machine.SPI0.Configure(machine.SPIConfig{
SCK: machine.SPI0_SCK_PIN,
+3 -2
View File
@@ -9,7 +9,7 @@ import (
var (
led machine.Pin = machine.LED
button machine.Pin = machine.BUTTON
button machine.Pin = machine.D10
key *makeybutton.Button
)
@@ -25,6 +25,7 @@ func main() {
case makeybutton.Released:
led.Low()
}
time.Sleep(100 * time.Millisecond)
// the more frequent the more responsive
time.Sleep(50 * time.Millisecond)
}
}
-1
View File
@@ -2,7 +2,6 @@
// to read data from the onboard MEMS microphone.
//
// Uses ideas from the https://github.com/adafruit/Adafruit_CircuitPlayground repo.
//
package main
import (
+66
View File
@@ -0,0 +1,66 @@
// 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)
}
}
+16 -16
View File
@@ -7,15 +7,16 @@
//
// 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"
@@ -28,23 +29,23 @@ import (
// You can override the setting with the init() in another source code.
// func init() {
// ssid = "your-ssid"
// password = "your-password"
// pass = "your-password"
// debug = true
// server = "tinygo.org"
// }
var (
ssid string
password string
server string = "tcp://test.mosquitto.org:1883"
debug = false
ssid string
pass 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.RTL8720DN
var adaptor *rtl8720dn.Driver
func main() {
err := run()
@@ -59,18 +60,17 @@ var (
)
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
// 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()
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,74 +0,0 @@
//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)
}
+17 -17
View File
@@ -7,16 +7,17 @@
//
// 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"
@@ -29,23 +30,23 @@ import (
// You can override the setting with the init() in another source code.
// func init() {
// ssid = "your-ssid"
// password = "your-password"
// pass = "your-password"
// debug = true
// server = "tinygo.org"
// }
var (
ssid string
password string
server string = "tcp://test.mosquitto.org:1883"
debug = false
ssid string
pass 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.RTL8720DN
var adaptor *rtl8720dn.Driver
func main() {
err := run()
@@ -68,18 +69,17 @@ func subHandler(client mqtt.Client, msg mqtt.Message) {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
// 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()
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
-74
View File
@@ -1,74 +0,0 @@
//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)
}
+13 -12
View File
@@ -4,28 +4,31 @@
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"
// password = "your-password"
// pass = "your-password"
// ntpHost = "129.6.15.29"
// debug = true
// }
var (
ssid string
password string
ntpHost = "129.6.15.29"
debug = false
ssid string
pass string
ntpHost = "129.6.15.29"
debug = false
)
const NTP_PACKET_SIZE = 48
@@ -41,18 +44,16 @@ func main() {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
adaptor.Debug(debug)
adaptor.Configure()
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,72 +0,0 @@
//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)
}
+11 -11
View File
@@ -4,28 +4,30 @@
// 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 = "sghome-gw"
// password = "3af25537b4524"
// ssid = "your-ssid"
// pass = "your-password"
// serverIP = "192.168.1.119"
// debug = true
// }
var (
ssid string
password string
pass string
serverIP = ""
debug = false
)
@@ -41,18 +43,16 @@ func main() {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
adaptor.Debug(debug)
adaptor.Configure()
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,72 +0,0 @@
//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)
}
+14 -14
View File
@@ -1,6 +1,8 @@
package main
import (
"machine"
"bufio"
"fmt"
"strings"
@@ -14,17 +16,17 @@ import (
// You can override the setting with the init() in another source code.
// func init() {
// ssid = "your-ssid"
// password = "your-password"
// pass = "your-password"
// debug = true
// url = "https://www.example.com"
// test_root_ca = "..."
// }
var (
ssid string
password string
url string = "https://www.example.com"
debug = false
ssid string
pass string
url string = "https://www.example.com"
debug = false
)
// Set the test_root_ca created by the following command
@@ -57,7 +59,6 @@ var buf [0x1000]byte
var lastRequestTime time.Time
var conn net.Conn
var adaptor *rtl8720dn.RTL8720DN
func main() {
err := run()
@@ -68,20 +69,19 @@ func main() {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
rtl.SetRootCA(&test_root_ca)
net.UseDriver(rtl)
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 = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,72 +0,0 @@
//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)
}
+14 -12
View File
@@ -1,28 +1,31 @@
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"
// password = "your-password"
// pass = "your-password"
// hubIP = "192.168.1.118"
// debug = true
// }
var (
ssid string
password string
hubIP = ""
debug = false
ssid string
pass string
hubIP = ""
debug = false
)
var buf [0x400]byte
@@ -36,19 +39,18 @@ func main() {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
adaptor.Debug(debug)
adaptor.Configure()
http.SetBuf(buf[:])
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,72 +0,0 @@
//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)
}
+7 -7
View File
@@ -1,10 +1,12 @@
package main
import (
"machine"
"fmt"
"time"
"tinygo.org/x/drivers/examples/rtl8720dn"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
@@ -20,13 +22,11 @@ func main() {
}
func run() error {
//rtl8720dn.Debug(true)
rtl, err := rtl8720dn.Setup()
if err != nil {
return err
}
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
adaptor.Debug(debug)
adaptor.Configure()
ver, err := rtl.Version()
ver, err := adaptor.Version()
if err != nil {
return nil
}
+39 -13
View File
@@ -1,14 +1,18 @@
package main
import (
"machine"
"bufio"
"fmt"
"image/color"
"strings"
"time"
"tinygo.org/x/drivers/net"
"tinygo.org/x/drivers/ili9341"
"tinygo.org/x/drivers/net/http"
"tinygo.org/x/drivers/rtl8720dn"
"tinygo.org/x/tinyfont/proggy"
"tinygo.org/x/tinyterm"
)
@@ -17,19 +21,28 @@ import (
// If debug is enabled, a serial connection is required.
// func init() {
// ssid = "your-ssid"
// password = "your-password"
// pass = "your-password"
// debug = false // true
// server = "tinygo.org"
// }
var (
ssid string
password string
url = "http://tinygo.org/"
debug = false
ssid string
pass 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)
black = color.RGBA{0, 0, 0, 255}
@@ -66,21 +79,22 @@ func run() error {
fmt.Fprintf(terminal, "Running in debug mode.\r\n")
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
}
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
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 = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
fmt.Fprintf(terminal, "connected\r\n\r\n")
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -134,3 +148,15 @@ 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})
}
@@ -1,98 +0,0 @@
//go:build wioterminal
// +build wioterminal
package main
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/ili9341"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
)
var (
display = ili9341.NewSPI(
machine.SPI3,
machine.LCD_DC,
machine.LCD_SS_PIN,
machine.LCD_RESET,
)
backlight = machine.LCD_BACKLIGHT
)
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})
}
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)
}
+15 -13
View File
@@ -1,28 +1,30 @@
package main
import (
"machine"
"bufio"
"fmt"
"strings"
"time"
"tinygo.org/x/drivers/net"
"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"
// password = "your-password"
// pass = "your-password"
// url = "http://tinygo.org/"
// debug = true
// }
var (
ssid string
password string
url = "http://tinygo.org/"
debug = false
ssid string
pass string
url = "http://tinygo.org/"
debug = false
)
var buf [0x400]byte
@@ -36,19 +38,19 @@ func main() {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
net.UseDriver(rtl)
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 = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,72 +0,0 @@
//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)
}
+12 -11
View File
@@ -7,19 +7,20 @@ import (
"time"
"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"
// password = "your-password"
// pass = "your-password"
// debug = true
// }
var (
ssid string
password string
debug = false
ssid string
pass string
debug = false
)
var led = machine.LED
@@ -37,18 +38,18 @@ func main() {
}
func run() error {
rtl, err := setupRTL8720DN()
if err != nil {
return err
}
http.UseDriver(rtl)
adaptor := rtl8720dn.New(machine.UART3, machine.PB24, machine.PC24, machine.RTL8720D_CHIP_PU)
adaptor.Debug(debug)
adaptor.Configure()
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
http.UseDriver(adaptor)
err := adaptor.ConnectToAccessPoint(ssid, pass, 10*time.Second)
if err != nil {
return err
}
ip, subnet, gateway, err := rtl.GetIP()
ip, subnet, gateway, err := adaptor.GetIP()
if err != nil {
return err
}
@@ -1,74 +0,0 @@
//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)
}
-79
View File
@@ -1,79 +0,0 @@
//go:build wioterminal
// +build wioterminal
package rtl8720dn
import (
"device/sam"
"machine"
"runtime/interrupt"
"time"
"tinygo.org/x/drivers/rtl8720dn"
)
var (
uart UARTx
debug bool
)
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
}
// 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
}
+6 -6
View File
@@ -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 -2
View File
@@ -2,8 +2,8 @@
// +build nucleowl55jc
/*
Nucleo WL55JC1
RFSwitch
Nucleo WL55JC1
RFSwitch
+-----------+---------+------------+------------+
| | FE_CTRL1 | FE_CTRL2 | FE_CTRL3 |
+34
View File
@@ -0,0 +1,34 @@
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)
}
}
+5 -4
View File
@@ -4,7 +4,6 @@
// You can open a server to accept connections from this program using:
//
// nc -w 5 -lk 8080
//
package main
import (
@@ -15,9 +14,11 @@ import (
"tinygo.org/x/drivers/net"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const serverIP = ""
+5 -3
View File
@@ -9,9 +9,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// these are the default pins for the Arduino Nano33 IoT.
// change these to connect to a different UART or pins for the ESP8266/ESP32
+5 -4
View File
@@ -9,7 +9,6 @@
//
// examples/wifinina/webclient
// examples/wifinina/tlsclient
//
package main
import (
@@ -24,9 +23,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
// Can specify a URL starting with http or https
+6 -5
View File
@@ -7,8 +7,7 @@
//
// 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 (
@@ -21,9 +20,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the MQTT broker to use. Replace with your own info.
const server = "tcp://test.mosquitto.org:1883"
+6 -5
View File
@@ -7,8 +7,7 @@
//
// 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 (
@@ -21,9 +20,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the MQTT broker to use. Replace with your own info.
const server = "tcp://test.mosquitto.org:1883"
+5 -3
View File
@@ -14,9 +14,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const ntpHost = "129.6.15.29"
+5 -4
View File
@@ -4,7 +4,6 @@
// You can open a server to accept connections from this program using:
//
// nc -w 5 -lk 8080
//
package main
import (
@@ -17,9 +16,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const serverIP = ""
+5 -4
View File
@@ -4,7 +4,6 @@
// 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 (
@@ -18,9 +17,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const server = "tinygo.org"
+5 -4
View File
@@ -3,7 +3,6 @@
//
// In other words:
// Your computer <--> UART0 <--> MCU <--> SPI <--> ESP32
//
package main
import (
@@ -15,9 +14,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const hubIP = ""
+5 -4
View File
@@ -3,7 +3,6 @@
// Arduino example:
//
// https://github.com/arduino-libraries/WiFiNINA/blob/master/examples/WiFiWebClientRepeating/
//
package main
import (
@@ -15,9 +14,11 @@ import (
"tinygo.org/x/drivers/wifinina"
)
// access point info
const ssid = ""
const pass = ""
var (
// access point info
ssid string
pass string
)
// IP address of the server aka "hub". Replace with your own info.
const server = "tinygo.org"
+3 -3
View File
@@ -2,7 +2,6 @@
// panel controller.
//
// Datasheet: https://focuslcds.com/content/FT6236.pdf
//
package ft6336
import (
@@ -42,8 +41,9 @@ 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)
}
+567
View File
@@ -0,0 +1,567 @@
// 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()
}
+65
View File
@@ -0,0 +1,65 @@
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
)
-1
View File
@@ -1,7 +1,6 @@
// 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 (
-1
View File
@@ -2,7 +2,6 @@
// with an I2C adapter.
//
// Datasheet: https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
//
package hd44780i2c
import (
-2
View File
@@ -2,7 +2,6 @@
// a capacitive digital sensor for relative humidity and temperature.
//
// Datasheet: https://www.st.com/resource/en/datasheet/hts221.pdf
//
package hts221
import (
@@ -85,7 +84,6 @@ 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
-1
View File
@@ -2,7 +2,6 @@
//
// 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 (
+12 -12
View File
@@ -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
+10 -5
View File
@@ -124,13 +124,18 @@ 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
View File
@@ -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,
+3 -1
View File
@@ -326,7 +326,9 @@ 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
-1
View File
@@ -43,7 +43,6 @@ 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
+3 -2
View File
@@ -7,11 +7,12 @@
// 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 (
+21 -22
View File
@@ -16,29 +16,28 @@ 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
//
// + - - - - - - - - - - - - - - +
// | + - - - - - - - - - - - - + |
// | | | |
// | | 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)
// "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)
func (d *DeviceAdafruitCharlieWing15x7) enableLEDs() (err error) {
for frame := FRAME_0; frame <= FRAME_7; frame++ {
err = d.selectCommand(frame)
-1
View File
@@ -2,7 +2,6 @@
// 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 (
-1
View File
@@ -2,7 +2,6 @@
// typically used to control DC motors.
//
// Datasheet: https://www.elecrow.com/download/datasheet-l9110.pdf
//
package l9110x // import "tinygo.org/x/drivers/l9110x"
import (
-1
View File
@@ -2,7 +2,6 @@
// 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
View File
@@ -1,7 +1,6 @@
// 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
View File
@@ -1,7 +1,6 @@
// 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 (
+3 -4
View File
@@ -2,7 +2,6 @@
// 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 (
@@ -138,7 +137,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_X_L_A, data)
err = d.bus.ReadRegister(uint8(d.AccelAddress), ACCEL_OUT_AUTO_INC, data)
if err != nil {
return
}
@@ -191,7 +190,7 @@ func (d *Device) ReadMagneticField() (x, y, z int32, err error) {
}
data := d.buf[0:6]
d.bus.ReadRegister(uint8(d.MagAddress), MAG_OUT_X_L_M, data)
d.bus.ReadRegister(uint8(d.MagAddress), MAG_OUT_AUTO_INC, data)
x = int32(int16((uint16(data[1])<<8 | uint16(data[0]))))
y = int32(int16((uint16(data[3])<<8 | uint16(data[2]))))
@@ -220,7 +219,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_L_A, data)
err = d.bus.ReadRegister(uint8(d.AccelAddress), OUT_TEMP_AUTO_INC, data)
if err != nil {
return
}
+29 -20
View File
@@ -6,31 +6,40 @@ 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_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
// 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_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
// temperature sensor registers.
TEMP_CFG_REG_A = 0x1F
OUT_TEMP_L_A = 0x0C
OUT_TEMP_H_A = 0x0D
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
// accelerometer power mode.
ACCEL_POWER_NORMAL = 0x00 // default
-1
View File
@@ -2,7 +2,6 @@
// Measurement Unit (IMU)
//
// Datasheet: https://www.st.com/resource/en/datasheet/lsm6ds3.pdf
//
package lsm6ds3 // import "tinygo.org/x/drivers/lsm6ds3"
import (
-1
View File
@@ -2,7 +2,6 @@
// 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 (
-1
View File
@@ -2,7 +2,6 @@
// 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
View File
@@ -1,7 +1,6 @@
// 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 (
-1
View File
@@ -2,7 +2,6 @@
// 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"
+44 -25
View File
@@ -1,11 +1,17 @@
package makeybutton
const bufferSize = 6
const (
bufferSize = 3
maxSumAllowed = 4
)
// Buffer is a buffer to keep track of the most recent readings for a button.
// in bit form.
type Buffer struct {
readings [bufferSize]bool
index int
data [bufferSize]byte
byteCounter int
bitCounter int
sum int
}
// NewBuffer returns a new buffer.
@@ -13,34 +19,47 @@ func NewBuffer() *Buffer {
return &Buffer{}
}
// Used returns how many bytes in buffer have been used.
func (b *Buffer) Used() int {
return b.index
// Sum returns the sum of all measurements
func (b *Buffer) Sum() int {
return 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
// 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++
}
b.readings[b.index] = val
return true
if oldestMeasurement != 0 && b.sum > 0 {
b.sum--
}
}
// 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
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
}
}
return avg
}
+34 -20
View File
@@ -4,6 +4,8 @@
// 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 (
@@ -11,6 +13,11 @@ import (
"time"
)
var (
pressThreshold int = 1
releaseThreshold int = 0
)
// ButtonState represents the state of a MakeyButton.
type ButtonState int
@@ -33,6 +40,7 @@ const (
type Button struct {
pin machine.Pin
state ButtonState
pressed bool
readings *Buffer
HighMeansPressed bool
}
@@ -49,7 +57,7 @@ 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 we have to first turn on the pullup, and then turn off the pullup,
// 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)
@@ -62,30 +70,36 @@ func (b *Button) Configure() error {
// 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 {
// 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
}
b.update()
avg := b.readings.Avg()
b.readings.Put(pressed)
switch {
case pressed && avg > -1*bufferSize+2:
if b.state == Press {
return NotChanged
}
b.state = Press
return Pressed
case !pressed:
if b.state == Press {
if b.pressed {
// the button had previously been pressed,
// but now appears to have been released.
if b.readings.Sum() <= releaseThreshold {
b.pressed = false
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
View File
@@ -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))
// }
+1 -1
View File
@@ -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
View File
@@ -1,7 +1,6 @@
// 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
View File
@@ -1,7 +1,6 @@
// 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 (
+27 -63
View File
@@ -4,14 +4,16 @@
// 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}},
@@ -20,7 +22,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 CCW
{ // 90 CW
{{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}},
@@ -43,71 +45,33 @@ var matrixRotations = [4][5][5][2]uint8{
},
}
const (
ledRows = 3
ledCols = 9
)
type Device struct {
pin [12]machine.Pin
buffer [3][9]bool
pin [ledCols + ledRows]machine.Pin
buffer [ledRows][ledCols]int8
rotation uint8
}
// Configure sets up the device.
func (d *Device) Configure(cfg Config) {
d.SetRotation(cfg.Rotation)
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
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()
}
d.pin[9] = machine.LED_ROW_1
d.pin[10] = machine.LED_ROW_2
d.pin[11] = machine.LED_ROW_3
// 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
}
for i := 0; i < len(d.pin); i++ {
d.pin[i].Configure(machine.PinConfig{Mode: machine.PinOutput})
}
}
// 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
}
+35 -83
View File
@@ -3,56 +3,60 @@
// Package microbitmatrix implements a driver for the BBC micro:bit version 2 LED matrix.
//
// Schematic:
//
// Schematic: https://github.com/microbit-foundation/microbit-v2-hardware/blob/main/V2.00/MicroBit_V2.0.0_S_schematic.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, 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}},
{{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}},
},
{ // 180
{{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}},
{{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}},
},
{ // 270
{{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}},
{{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}},
},
}
const (
ledRows = 5
ledCols = 5
)
type Device struct {
pin [10]machine.Pin
buffer [5][5]bool
pin [ledCols + ledRows]machine.Pin
buffer [ledRows][ledCols]int8
rotation uint8
}
// Configure sets up the device.
func (d *Device) Configure(cfg Config) {
d.SetRotation(cfg.Rotation)
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
@@ -65,59 +69,7 @@ func (d *Device) Configure(cfg Config) {
d.pin[8] = machine.LED_ROW_4
d.pin[9] = machine.LED_ROW_5
for i := 0; i < 10; i++ {
for i := 0; i < len(d.pin); 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
}
+179 -9
View File
@@ -1,43 +1,213 @@
// 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{}
}
// SetRotation changes the rotation of the LED matrix
// 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
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][x][y][0]][matrixRotations[d.rotation][x][y][1]] = true
d.buffer[matrixRotations[d.rotation][row][col][rowIdx]][matrixRotations[d.rotation][row][col][colIdx]] = brightness(c.A)
} else {
d.buffer[matrixRotations[d.rotation][x][y][0]][matrixRotations[d.rotation][x][y][1]] = false
d.buffer[matrixRotations[d.rotation][row][col][rowIdx]][matrixRotations[d.rotation][row][col][colIdx]] = 0
}
}
// GetPixel returns if the specific pixels is enabled
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.
func (d *Device) GetPixel(x int16, y int16) bool {
if x < 0 || x >= 5 || y < 0 || y >= 5 {
return false
}
return d.buffer[matrixRotations[d.rotation][x][y][0]][matrixRotations[d.rotation][x][y][1]]
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
}
-2
View File
@@ -2,7 +2,6 @@
// 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 (
@@ -141,7 +140,6 @@ 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,
-1
View File
@@ -3,7 +3,6 @@
//
// Datasheet:
// https://www.nxp.com/docs/en/data-sheet/MMA8653FC.pdf
//
package mma8653 // import "tinygo.org/x/drivers/mma8653"
import "tinygo.org/x/drivers"
+2 -3
View File
@@ -4,7 +4,6 @@
// Datasheets:
// https://store.invensense.com/datasheets/invensense/MPU-6050_DataSheet_V3%204.pdf
// https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf
//
package mpu6050 // import "tinygo.org/x/drivers/mpu6050"
import "tinygo.org/x/drivers"
@@ -32,8 +31,8 @@ func (d Device) Connected() bool {
}
// Configure sets up the device for communication.
func (d Device) Configure() {
d.bus.WriteRegister(uint8(d.Address), PWR_MGMT_1, []uint8{0})
func (d Device) Configure() error {
return d.bus.WriteRegister(uint8(d.Address), PWR_MGMT_1, []uint8{0})
}
// ReadAcceleration reads the current acceleration from the device and returns

Some files were not shown because too many files have changed in this diff Show More