mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-19 22:23:58 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b7da60f8f |
@@ -0,0 +1,20 @@
|
|||||||
|
# Golang CircleCI 2.0 configuration file
|
||||||
|
#
|
||||||
|
# Check https://circleci.com/docs/2.0/language-go/ for more details
|
||||||
|
version: 2
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
docker:
|
||||||
|
- image: tinygo/tinygo-dev
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: tinygo version
|
||||||
|
- run:
|
||||||
|
name: "Enforce Go Formatted Code"
|
||||||
|
command: make fmt-check
|
||||||
|
- run:
|
||||||
|
name: "Run unit tests"
|
||||||
|
command: make unit-test
|
||||||
|
- run:
|
||||||
|
name: "Run build and smoke tests"
|
||||||
|
command: make smoke-test
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
name: Build
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- dev
|
|
||||||
- release
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container: tinygo/tinygo-dev
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
- name: TinyGo version check
|
|
||||||
run: tinygo version
|
|
||||||
- name: Enforce Go Formatted Code
|
|
||||||
run: make fmt-check
|
|
||||||
- name: Run unit tests
|
|
||||||
run: make unit-test
|
|
||||||
- name: Run build and smoke tests
|
|
||||||
run: make smoke-test
|
|
||||||
@@ -1,24 +1,3 @@
|
|||||||
0.21.0
|
|
||||||
---
|
|
||||||
- **new devices**
|
|
||||||
- lsm6ds3tr: initial implementation
|
|
||||||
- UC8151: used in Pimoroni's badger2040 e-paper (#416)
|
|
||||||
- scd4x: implement driver for CO2 sensor
|
|
||||||
|
|
||||||
- **enhancements**
|
|
||||||
- easystepper: Add support for '8-step mode'
|
|
||||||
- vl53l1x: Add functions for setting the device address
|
|
||||||
- sdcard: support thingplus-rp2040
|
|
||||||
- wifinina: add mutex to prevent communication race problems
|
|
||||||
- **ws2812**
|
|
||||||
- support thingplus-rp2040 board
|
|
||||||
- Added 125 MHz rp2040 timing
|
|
||||||
- Added unsafe.Pointer for pointer conversion
|
|
||||||
|
|
||||||
- **bugfixes**
|
|
||||||
- ssd1351: Fix mirrored text on OLED display
|
|
||||||
|
|
||||||
|
|
||||||
0.20.0
|
0.20.0
|
||||||
---
|
---
|
||||||
- **new devices**
|
- **new devices**
|
||||||
|
|||||||
@@ -235,21 +235,16 @@ endif
|
|||||||
@md5sum ./build/test.uf2
|
@md5sum ./build/test.uf2
|
||||||
tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
|
tinygo build -size short -o ./build/test.hex -target=pico ./examples/irremote/main.go
|
||||||
@md5sum ./build/test.hex
|
@md5sum ./build/test.hex
|
||||||
tinygo build -size short -o ./build/test.hex -target=badger2040 ./examples/uc8151/main.go
|
|
||||||
@md5sum ./build/test.hex
|
|
||||||
tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
|
tinygo build -size short -o ./build/test.uf2 -target=pico ./examples/scd4x/main.go
|
||||||
@md5sum ./build/test.uf2
|
@md5sum ./build/test.uf2
|
||||||
tinygo build -size short -o ./build/test.uf2 -target=circuitplay-express ./examples/makeybutton/main.go
|
|
||||||
@md5sum ./build/test.uf2
|
|
||||||
|
|
||||||
# rwildcard is a recursive version of $(wildcard)
|
DRIVERS = $(wildcard */)
|
||||||
# https://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
|
NOTESTS = build examples flash semihosting pcd8544 shiftregister st7789 microphone mcp3008 gps microbitmatrix \
|
||||||
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
|
hcsr04 ssd1331 ws2812 thermistor apa102 easystepper ssd1351 ili9341 wifinina shifter hub75 \
|
||||||
# Recursively find all *_test.go files from cwd & reduce to unique dir names
|
hd44780 buzzer ssd1306 espat l9110x st7735 bmi160 l293x keypad4x4 max72xx p1am tone tm1637 \
|
||||||
HAS_TESTS = $(sort $(dir $(call rwildcard,,*_test.go)))
|
pcf8563 mcp2515 servo sdcard rtl8720dn image cmd i2csoft hts221 lps22hb apds9960 axp192 xpt2046 \
|
||||||
# Exclude anything we explicitly don't want to test for whatever reason
|
ft6336 sx126x ssd1289 irremote
|
||||||
EXCLUDE_TESTS = image
|
TESTS = $(filter-out $(addsuffix /%,$(NOTESTS)),$(DRIVERS))
|
||||||
TESTS = $(filter-out $(addsuffix /%,$(EXCLUDE_TESTS)),$(HAS_TESTS))
|
|
||||||
|
|
||||||
unit-test:
|
unit-test:
|
||||||
@go test -v $(addprefix ./,$(TESTS))
|
@go test -v $(addprefix ./,$(TESTS))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# TinyGo Drivers
|
# TinyGo Drivers
|
||||||
|
|
||||||
[](https://pkg.go.dev/tinygo.org/x/drivers) [](https://github.com/tinygo-org/drivers/actions/workflows/build.yml)
|
[](https://pkg.go.dev/tinygo.org/x/drivers) [](https://circleci.com/gh/tinygo-org/drivers/tree/dev)
|
||||||
|
|
||||||
|
|
||||||
This package provides a collection of hardware drivers for devices such as sensors and displays that can be used together with [TinyGo](https://tinygo.org).
|
This package provides a collection of hardware drivers for devices such as sensors and displays that can be used together with [TinyGo](https://tinygo.org).
|
||||||
@@ -52,10 +52,10 @@ func main() {
|
|||||||
|
|
||||||
## Currently supported devices
|
## Currently supported devices
|
||||||
|
|
||||||
The following 81 devices are supported.
|
The following 78 devices are supported.
|
||||||
|
|
||||||
| Device Name | Interface Type |
|
| Device Name | Interface Type |
|
||||||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|
|
|----------|-------------|
|
||||||
| [ADT7410 I2C Temperature Sensor](https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf) | I2C |
|
| [ADT7410 I2C Temperature Sensor](https://www.analog.com/media/en/technical-documentation/data-sheets/ADT7410.pdf) | I2C |
|
||||||
| [ADXL345 accelerometer](http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf) | I2C |
|
| [ADXL345 accelerometer](http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf) | I2C |
|
||||||
| [AHT20 I2C Temperature and Humidity Sensor](http://www.aosong.com/userfiles/files/media/AHT20%20%E8%8B%B1%E6%96%87%E7%89%88%E8%AF%B4%E6%98%8E%E4%B9%A6%20A0%2020201222.pdf) | I2C |
|
| [AHT20 I2C Temperature and Humidity Sensor](http://www.aosong.com/userfiles/files/media/AHT20%20%E8%8B%B1%E6%96%87%E7%89%88%E8%AF%B4%E6%98%8E%E4%B9%A6%20A0%2020201222.pdf) | I2C |
|
||||||
@@ -97,10 +97,8 @@ The following 81 devices are supported.
|
|||||||
| [LPS22HB MEMS nano pressure sensor](https://www.st.com/resource/en/datasheet/dm00140895.pdf) | I2C |
|
| [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 |
|
| [LSM6DS3 accelerometer](https://www.st.com/resource/en/datasheet/lsm6ds3.pdf) | I2C |
|
||||||
| [LSM6DSOX accelerometer](https://www.st.com/resource/en/datasheet/lsm6dsox.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 |
|
|
||||||
| [LSM303AGR accelerometer](https://www.st.com/resource/en/datasheet/lsm303agr.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 |
|
| [LSM9DS1 accelerometer](https://www.st.com/resource/en/datasheet/lsm9ds1.pdf) | I2C |
|
||||||
| [Makey Button](https://makeymakey.com/) | GPIO |
|
|
||||||
| [MAG3110 magnetometer](https://www.nxp.com/docs/en/data-sheet/MAG3110.pdf) | I2C |
|
| [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 |
|
| [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 |
|
| [MCP2515 Stand-Alone CAN Controller with SPI Interface](https://ww1.microchip.com/downloads/en/DeviceDoc/MCP2515-Family-Data-Sheet-DS20001801K.pdf) | SPI |
|
||||||
@@ -114,7 +112,6 @@ The following 81 devices are supported.
|
|||||||
| [PCF8563 real time clock](https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf) | I2C |
|
| [PCF8563 real time clock](https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf) | I2C |
|
||||||
| [Resistive Touchscreen (4-wire)](http://ww1.microchip.com/downloads/en/Appnotes/doc8091.pdf) | GPIO |
|
| [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 |
|
| [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 |
|
|
||||||
| [Semihosting](https://wiki.segger.com/Semihosting) | Debug |
|
| [Semihosting](https://wiki.segger.com/Semihosting) | Debug |
|
||||||
| [Servo](https://learn.sparkfun.com/tutorials/hobby-servo-tutorial/all) | PWM |
|
| [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 |
|
| [Shift register (PISO)](https://en.wikipedia.org/wiki/Shift_register#Parallel-in_serial-out_\(PISO\)) | GPIO |
|
||||||
@@ -132,7 +129,6 @@ The following 81 devices are supported.
|
|||||||
| [Thermistor](https://www.farnell.com/datasheets/33552.pdf) | ADC |
|
| [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 |
|
| [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 |
|
| [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 |
|
|
||||||
| [VEML6070 UV light sensor](https://www.vishay.com/docs/84277/veml6070.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 |
|
| [VL53L1X time-of-flight distance sensor](https://www.st.com/resource/en/datasheet/vl53l1x.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" (B & C) e-paper display](https://www.waveshare.com/w/upload/d/d3/2.13inch-e-paper-b-Specification.pdf) | SPI |
|
||||||
|
|||||||
+22
-138
@@ -2,76 +2,28 @@
|
|||||||
package easystepper // import "tinygo.org/x/drivers/easystepper"
|
package easystepper // import "tinygo.org/x/drivers/easystepper"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"machine"
|
"machine"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StepMode determines the coil sequence used to perform a single step
|
|
||||||
type StepMode uint8
|
|
||||||
|
|
||||||
// Valid values for StepMode
|
|
||||||
const (
|
|
||||||
// ModeFour uses a 'four step' coil sequence (12-23-34-41). This is the default (zero-value) mode
|
|
||||||
ModeFour StepMode = iota
|
|
||||||
// ModeEight uses an 'eight step' coil sequence (1-12-2-23-3-34-4-41)
|
|
||||||
ModeEight
|
|
||||||
)
|
|
||||||
|
|
||||||
// stepCount is a helper function to return the number of steps in a StepMode sequence
|
|
||||||
func (sm StepMode) stepCount() uint {
|
|
||||||
switch sm {
|
|
||||||
default:
|
|
||||||
fallthrough
|
|
||||||
case ModeFour:
|
|
||||||
return 4
|
|
||||||
case ModeEight:
|
|
||||||
return 8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeviceConfig contains the configuration data for a single easystepper driver
|
|
||||||
type DeviceConfig struct {
|
|
||||||
// Pin1 ... Pin4 determines the pins to configure and use for the device
|
|
||||||
Pin1, Pin2, Pin3, Pin4 machine.Pin
|
|
||||||
// StepCount is the number of steps required to perform a full revolution of the stepper motor
|
|
||||||
StepCount uint
|
|
||||||
// RPM determines the speed of the stepper motor in 'Revolutions per Minute'
|
|
||||||
RPM uint
|
|
||||||
// Mode determines the coil sequence used to perform a single step
|
|
||||||
Mode StepMode
|
|
||||||
}
|
|
||||||
|
|
||||||
// DualDeviceConfig contains the configuration data for a dual easystepper driver
|
|
||||||
type DualDeviceConfig struct {
|
|
||||||
DeviceConfig
|
|
||||||
// Pin5 ... Pin8 determines the pins to configure and use for the second device
|
|
||||||
Pin5, Pin6, Pin7, Pin8 machine.Pin
|
|
||||||
}
|
|
||||||
|
|
||||||
// Device holds the pins and the delay between steps
|
// Device holds the pins and the delay between steps
|
||||||
type Device struct {
|
type Device struct {
|
||||||
pins [4]machine.Pin
|
pins [4]machine.Pin
|
||||||
stepDelay time.Duration
|
stepDelay int32
|
||||||
stepNumber uint8
|
stepNumber uint8
|
||||||
stepMode StepMode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DualDevice holds information for controlling 2 motors
|
// DualDevice holds information for controlling 2 motors
|
||||||
type DualDevice struct {
|
type DualDevice struct {
|
||||||
devices [2]*Device
|
devices [2]Device
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new single easystepper driver given a DeviceConfig
|
// New returns a new easystepper driver given 4 pins, number of steps and rpm
|
||||||
func New(config DeviceConfig) (*Device, error) {
|
func New(pin1, pin2, pin3, pin4 machine.Pin, steps int32, rpm int32) Device {
|
||||||
if config.StepCount == 0 || config.RPM == 0 {
|
return Device{
|
||||||
return nil, errors.New("config.StepCount and config.RPM must be > 0")
|
pins: [4]machine.Pin{pin1, pin2, pin3, pin4},
|
||||||
|
stepDelay: 60000000 / (steps * rpm),
|
||||||
}
|
}
|
||||||
return &Device{
|
|
||||||
pins: [4]machine.Pin{config.Pin1, config.Pin2, config.Pin3, config.Pin4},
|
|
||||||
stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)),
|
|
||||||
stepMode: config.Mode,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure configures the pins of the Device
|
// Configure configures the pins of the Device
|
||||||
@@ -82,23 +34,17 @@ func (d *Device) Configure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm
|
// NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm
|
||||||
func NewDual(config DualDeviceConfig) (*DualDevice, error) {
|
func NewDual(pin1, pin2, pin3, pin4, pin5, pin6, pin7, pin8 machine.Pin, steps int32, rpm int32) DualDevice {
|
||||||
// Create the first device
|
var dual DualDevice
|
||||||
dev1, err := New(config.DeviceConfig)
|
dual.devices[0] = Device{
|
||||||
if err != nil {
|
pins: [4]machine.Pin{pin1, pin2, pin3, pin4},
|
||||||
return nil, err
|
stepDelay: 60000000 / (steps * rpm),
|
||||||
}
|
}
|
||||||
// Create the second device
|
dual.devices[1] = Device{
|
||||||
config.DeviceConfig.Pin1 = config.Pin5
|
pins: [4]machine.Pin{pin5, pin6, pin7, pin8},
|
||||||
config.DeviceConfig.Pin2 = config.Pin6
|
stepDelay: 60000000 / (steps * rpm),
|
||||||
config.DeviceConfig.Pin3 = config.Pin7
|
|
||||||
config.DeviceConfig.Pin4 = config.Pin8
|
|
||||||
dev2, err := New(config.DeviceConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
// Return composite dual device
|
return dual
|
||||||
return &DualDevice{devices: [2]*Device{dev1, dev2}}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure configures the pins of the DualDevice
|
// Configure configures the pins of the DualDevice
|
||||||
@@ -118,7 +64,7 @@ func (d *Device) Move(steps int32) {
|
|||||||
var s int32
|
var s int32
|
||||||
d.stepMotor(d.stepNumber)
|
d.stepMotor(d.stepNumber)
|
||||||
for s = int32(d.stepNumber); s < steps; s++ {
|
for s = int32(d.stepNumber); s < steps; s++ {
|
||||||
time.Sleep(d.stepDelay)
|
time.Sleep(time.Duration(d.stepDelay) * time.Microsecond)
|
||||||
d.moveDirectionSteps(direction, s)
|
d.moveDirectionSteps(direction, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,7 +101,7 @@ func (d *DualDevice) Move(stepsA, stepsB int32) {
|
|||||||
stepsA += int32(d.devices[max].stepNumber)
|
stepsA += int32(d.devices[max].stepNumber)
|
||||||
minStep = int32(d.devices[min].stepNumber)
|
minStep = int32(d.devices[min].stepNumber)
|
||||||
for s := int32(d.devices[max].stepNumber); s < stepsA; s++ {
|
for s := int32(d.devices[max].stepNumber); s < stepsA; s++ {
|
||||||
time.Sleep(d.devices[0].stepDelay)
|
time.Sleep(time.Duration(d.devices[0].stepDelay) * time.Microsecond)
|
||||||
d.devices[max].moveDirectionSteps(directions[max], s)
|
d.devices[max].moveDirectionSteps(directions[max], s)
|
||||||
|
|
||||||
if ((s * stepsB) / stepsA) > minStep {
|
if ((s * stepsB) / stepsA) > minStep {
|
||||||
@@ -173,18 +119,6 @@ func (d *DualDevice) Off() {
|
|||||||
|
|
||||||
// stepMotor changes the pins' state to the correct step
|
// stepMotor changes the pins' state to the correct step
|
||||||
func (d *Device) stepMotor(step uint8) {
|
func (d *Device) stepMotor(step uint8) {
|
||||||
switch d.stepMode {
|
|
||||||
default:
|
|
||||||
fallthrough
|
|
||||||
case ModeFour:
|
|
||||||
d.stepMotor4(step)
|
|
||||||
case ModeEight:
|
|
||||||
d.stepMotor8(step)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// stepMotor4 changes the pins' state to the correct step in 4-step mode
|
|
||||||
func (d *Device) stepMotor4(step uint8) {
|
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
d.pins[0].High()
|
d.pins[0].High()
|
||||||
@@ -214,63 +148,13 @@ func (d *Device) stepMotor4(step uint8) {
|
|||||||
d.stepNumber = step
|
d.stepNumber = step
|
||||||
}
|
}
|
||||||
|
|
||||||
// stepMotor8 changes the pins' state to the correct step in 8-step mode
|
|
||||||
func (d *Device) stepMotor8(step uint8) {
|
|
||||||
switch step {
|
|
||||||
case 0:
|
|
||||||
d.pins[0].High()
|
|
||||||
d.pins[2].Low()
|
|
||||||
d.pins[1].Low()
|
|
||||||
d.pins[3].Low()
|
|
||||||
case 1:
|
|
||||||
d.pins[0].High()
|
|
||||||
d.pins[2].High()
|
|
||||||
d.pins[1].Low()
|
|
||||||
d.pins[3].Low()
|
|
||||||
case 2:
|
|
||||||
d.pins[0].Low()
|
|
||||||
d.pins[2].High()
|
|
||||||
d.pins[1].Low()
|
|
||||||
d.pins[3].Low()
|
|
||||||
case 3:
|
|
||||||
d.pins[0].Low()
|
|
||||||
d.pins[2].High()
|
|
||||||
d.pins[1].High()
|
|
||||||
d.pins[3].Low()
|
|
||||||
case 4:
|
|
||||||
d.pins[0].Low()
|
|
||||||
d.pins[2].Low()
|
|
||||||
d.pins[1].High()
|
|
||||||
d.pins[3].Low()
|
|
||||||
case 5:
|
|
||||||
d.pins[0].Low()
|
|
||||||
d.pins[2].Low()
|
|
||||||
d.pins[1].High()
|
|
||||||
d.pins[3].High()
|
|
||||||
case 6:
|
|
||||||
d.pins[0].Low()
|
|
||||||
d.pins[2].Low()
|
|
||||||
d.pins[1].Low()
|
|
||||||
d.pins[3].High()
|
|
||||||
case 7:
|
|
||||||
d.pins[0].High()
|
|
||||||
d.pins[2].Low()
|
|
||||||
d.pins[1].Low()
|
|
||||||
d.pins[3].High()
|
|
||||||
}
|
|
||||||
d.stepNumber = step
|
|
||||||
}
|
|
||||||
|
|
||||||
// moveDirectionSteps uses the direction to calculate the correct step and change the motor to it.
|
// moveDirectionSteps uses the direction to calculate the correct step and change the motor to it.
|
||||||
// Direction true: (4-step mode) 0, 1, 2, 3, 0, 1, 2, ...
|
// Direction true: 0, 1, 2, 3, 0, 1, 2, ...
|
||||||
// Direction false: (4-step mode) 0, 3, 2, 1, 0, 3, 2, ...
|
// Direction false: 0, 3, 2, 1, 0, 3, 2, ...
|
||||||
// Direction true: (8-step mode) 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, ...
|
|
||||||
// Direction false: (8-step mode) 0, 7, 6, 5, 4, 3, 2, 1, 0, 7, 6, ...
|
|
||||||
func (d *Device) moveDirectionSteps(direction bool, step int32) {
|
func (d *Device) moveDirectionSteps(direction bool, step int32) {
|
||||||
modulus := int32(d.stepMode.stepCount())
|
|
||||||
if direction {
|
if direction {
|
||||||
d.stepMotor(uint8(step % modulus))
|
d.stepMotor(uint8(step % 4))
|
||||||
} else {
|
} else {
|
||||||
d.stepMotor(uint8(((-step % modulus) + modulus) % modulus))
|
d.stepMotor(uint8((step + 2*(step%2)) % 4))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config := easystepper.DeviceConfig{
|
motor := easystepper.New(machine.P13, machine.P15, machine.P14, machine.P16, 200, 75)
|
||||||
Pin1: machine.P13, Pin2: machine.P15, Pin3: machine.P14, Pin4: machine.P16,
|
|
||||||
StepCount: 200, RPM: 75, Mode: easystepper.ModeFour,
|
|
||||||
}
|
|
||||||
motor, _ := easystepper.New(config)
|
|
||||||
motor.Configure()
|
motor.Configure()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|||||||
+18
-18
@@ -8,27 +8,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var irCmdButtons = map[uint16]string{
|
var irCmdButtons = map[uint16]string{
|
||||||
0x45: "POWER",
|
0xA2: "POWER",
|
||||||
0x47: "FUNC/STOP",
|
0xE2: "FUNC/STOP",
|
||||||
0x46: "VOL+",
|
0x62: "VOL+",
|
||||||
0x44: "FAST BACK",
|
0x22: "FAST BACK",
|
||||||
0x40: "PAUSE",
|
0x02: "PAUSE",
|
||||||
0x43: "FAST FORWARD",
|
0xC2: "FAST FORWARD",
|
||||||
0x07: "DOWN",
|
0xE0: "DOWN",
|
||||||
0x15: "VOL-",
|
0xA8: "VOL-",
|
||||||
0x09: "UP",
|
0x90: "UP",
|
||||||
0x19: "EQ",
|
0x98: "EQ",
|
||||||
0x0D: "ST/REPT",
|
0xB0: "ST/REPT",
|
||||||
0x16: "0",
|
0x68: "0",
|
||||||
0x0C: "1",
|
0x30: "1",
|
||||||
0x18: "2",
|
0x18: "2",
|
||||||
0x5E: "3",
|
0x7A: "3",
|
||||||
0x08: "4",
|
0x10: "4",
|
||||||
0x1C: "5",
|
0x38: "5",
|
||||||
0x5A: "6",
|
0x5A: "6",
|
||||||
0x42: "7",
|
0x42: "7",
|
||||||
0x52: "8",
|
0x4A: "8",
|
||||||
0x4A: "9",
|
0x52: "9",
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
// Connects to an LSM6DS3TR I2C a 6 axis Inertial Measurement Unit (IMU)
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/lsm6ds3tr"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
machine.I2C0.Configure(machine.I2CConfig{})
|
|
||||||
|
|
||||||
accel := lsm6ds3tr.New(machine.I2C0)
|
|
||||||
err := accel.Configure(lsm6ds3tr.Configuration{})
|
|
||||||
if err != nil {
|
|
||||||
for {
|
|
||||||
println("Failed to configure", err.Error())
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
if !accel.Connected() {
|
|
||||||
println("LSM6DS3TR not connected")
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
x, y, z, _ := accel.ReadAcceleration()
|
|
||||||
println("Acceleration:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
|
|
||||||
x, y, z, _ = accel.ReadRotation()
|
|
||||||
println("Gyroscope:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000)
|
|
||||||
x, _ = accel.ReadTemperature()
|
|
||||||
println("Degrees C", float32(x)/1000, "\n\n")
|
|
||||||
time.Sleep(time.Millisecond * 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/makeybutton"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
led machine.Pin = machine.LED
|
|
||||||
button machine.Pin = machine.BUTTON
|
|
||||||
key *makeybutton.Button
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
key = makeybutton.NewButton(button)
|
|
||||||
key.Configure()
|
|
||||||
|
|
||||||
for {
|
|
||||||
switch key.Get() {
|
|
||||||
case makeybutton.Pressed:
|
|
||||||
led.High()
|
|
||||||
case makeybutton.Released:
|
|
||||||
led.Low()
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/examples/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
debug = false
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
err := run()
|
|
||||||
for err != nil {
|
|
||||||
fmt.Printf("error: %s\r\n", err.Error())
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func run() error {
|
|
||||||
//rtl8720dn.Debug(true)
|
|
||||||
rtl, err := rtl8720dn.Setup()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ver, err := rtl.Version()
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
fmt.Printf("RTL8270DN Firmware Version: %s\r\n", ver)
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -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_with_timeout(10 * time.Second)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI1
|
spi = machine.SPI1
|
||||||
sckPin = machine.SDCARD_SCK_PIN
|
sckPin = machine.SDCARD_SCK_PIN
|
||||||
sdoPin = machine.SDCARD_SDO_PIN
|
sdoPin = machine.SDCARD_SDO_PIN
|
||||||
sdiPin = machine.SDCARD_SDI_PIN
|
sdiPin = machine.SDCARD_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
spi *machine.SPI
|
spi machine.SPI
|
||||||
sckPin machine.Pin
|
sckPin machine.Pin
|
||||||
sdoPin machine.Pin
|
sdoPin machine.Pin
|
||||||
sdiPin machine.Pin
|
sdiPin machine.Pin
|
||||||
@@ -18,6 +18,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
waitSerial()
|
||||||
fmt.Printf("sdcard console\r\n")
|
fmt.Printf("sdcard console\r\n")
|
||||||
|
|
||||||
led := ledPin
|
led := ledPin
|
||||||
@@ -41,3 +42,10 @@ func main() {
|
|||||||
time.Sleep(200 * time.Millisecond)
|
time.Sleep(200 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for user to open serial console
|
||||||
|
func waitSerial() {
|
||||||
|
for !machine.Serial.DTR() {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SDCARD_SPI
|
spi = machine.SDCARD_SPI
|
||||||
sckPin = machine.SDCARD_SCK_PIN
|
sckPin = machine.SDCARD_SCK_PIN
|
||||||
sdoPin = machine.SDCARD_SDO_PIN
|
sdoPin = machine.SDCARD_SDO_PIN
|
||||||
sdiPin = machine.SDCARD_SDI_PIN
|
sdiPin = machine.SDCARD_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
//go:build thingplus_rp2040
|
|
||||||
// +build thingplus_rp2040
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
spi = machine.SPI1
|
|
||||||
sckPin = machine.SPI1_SCK_PIN
|
|
||||||
sdoPin = machine.SPI1_SDO_PIN
|
|
||||||
sdiPin = machine.SPI1_SDI_PIN
|
|
||||||
csPin = machine.GPIO9
|
|
||||||
|
|
||||||
ledPin = machine.LED
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI2
|
spi = machine.SPI2
|
||||||
sckPin = machine.SCK2
|
sckPin = machine.SCK2
|
||||||
sdoPin = machine.SDO2
|
sdoPin = machine.SDO2
|
||||||
sdiPin = machine.SDI2
|
sdiPin = machine.SDI2
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI1
|
spi = machine.SPI1
|
||||||
sckPin = machine.SDCARD_SCK_PIN
|
sckPin = machine.SDCARD_SCK_PIN
|
||||||
sdoPin = machine.SDCARD_SDO_PIN
|
sdoPin = machine.SDCARD_SDO_PIN
|
||||||
sdiPin = machine.SDCARD_SDI_PIN
|
sdiPin = machine.SDCARD_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
spi *machine.SPI
|
spi machine.SPI
|
||||||
sckPin machine.Pin
|
sckPin machine.Pin
|
||||||
sdoPin machine.Pin
|
sdoPin machine.Pin
|
||||||
sdiPin machine.Pin
|
sdiPin machine.Pin
|
||||||
@@ -20,6 +20,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
waitSerial()
|
||||||
|
|
||||||
sd := sdcard.New(spi, sckPin, sdoPin, sdiPin, csPin)
|
sd := sdcard.New(spi, sckPin, sdoPin, sdiPin, csPin)
|
||||||
err := sd.Configure()
|
err := sd.Configure()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -38,3 +40,10 @@ func main() {
|
|||||||
|
|
||||||
console.RunFor(&sd, filesystem)
|
console.RunFor(&sd, filesystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for user to open serial console
|
||||||
|
func waitSerial() {
|
||||||
|
for !machine.Serial.DTR() {
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SDCARD_SPI
|
spi = machine.SDCARD_SPI
|
||||||
sckPin = machine.SDCARD_SCK_PIN
|
sckPin = machine.SDCARD_SCK_PIN
|
||||||
sdoPin = machine.SDCARD_SDO_PIN
|
sdoPin = machine.SDCARD_SDO_PIN
|
||||||
sdiPin = machine.SDCARD_SDI_PIN
|
sdiPin = machine.SDCARD_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI0
|
spi = machine.SPI0
|
||||||
sckPin = machine.SPI0_SCK_PIN
|
sckPin = machine.SPI0_SCK_PIN
|
||||||
sdoPin = machine.SPI0_SDO_PIN
|
sdoPin = machine.SPI0_SDO_PIN
|
||||||
sdiPin = machine.SPI0_SDI_PIN
|
sdiPin = machine.SPI0_SDI_PIN
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
//go:build thingplus_rp2040
|
|
||||||
// +build thingplus_rp2040
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
spi = machine.SPI1
|
|
||||||
sckPin = machine.SPI1_SCK_PIN
|
|
||||||
sdoPin = machine.SPI1_SDO_PIN
|
|
||||||
sdiPin = machine.SPI1_SDI_PIN
|
|
||||||
csPin = machine.GPIO9
|
|
||||||
|
|
||||||
ledPin = machine.LED
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
spi = &machine.SPI2
|
spi = machine.SPI2
|
||||||
sckPin = machine.SCK2
|
sckPin = machine.SCK2
|
||||||
sdoPin = machine.SDO2
|
sdoPin = machine.SDO2
|
||||||
sdiPin = machine.SDI2
|
sdiPin = machine.SDI2
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"image/color"
|
|
||||||
"machine"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/uc8151"
|
|
||||||
)
|
|
||||||
|
|
||||||
var display uc8151.Device
|
|
||||||
var led machine.Pin
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
led = machine.LED
|
|
||||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.SPI0.Configure(machine.SPIConfig{
|
|
||||||
Frequency: 12000000,
|
|
||||||
SCK: machine.EPD_SCK_PIN,
|
|
||||||
SDO: machine.EPD_SDO_PIN,
|
|
||||||
})
|
|
||||||
|
|
||||||
display = uc8151.New(machine.SPI0, machine.EPD_CS_PIN, machine.EPD_DC_PIN, machine.EPD_RESET_PIN, machine.EPD_BUSY_PIN)
|
|
||||||
display.Configure(uc8151.Config{
|
|
||||||
Rotation: uc8151.ROTATION_270,
|
|
||||||
Speed: uc8151.MEDIUM,
|
|
||||||
Blocking: true,
|
|
||||||
})
|
|
||||||
black := color.RGBA{1, 1, 1, 255}
|
|
||||||
|
|
||||||
display.ClearBuffer()
|
|
||||||
display.Display()
|
|
||||||
for i := int16(0); i < 37; i++ {
|
|
||||||
for j := int16(0); j < 16; j++ {
|
|
||||||
if (i+j)%2 == 0 {
|
|
||||||
showRect(i*8, j*8, 8, 8, black)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
display.Display()
|
|
||||||
}
|
|
||||||
|
|
||||||
func showRect(x int16, y int16, w int16, h int16, c color.RGBA) {
|
|
||||||
for i := x; i < x+w; i++ {
|
|
||||||
for j := y; j < y+h; j++ {
|
|
||||||
display.SetPixel(i, j, c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
//go:build !digispark && !arduino && !qtpy && !m5stamp_c3 && !thingplus_rp2040
|
//go:build !digispark && !arduino && !qtpy && !m5stamp_c3
|
||||||
// +build !digispark,!arduino,!qtpy,!m5stamp_c3,!thingplus_rp2040
|
// +build !digispark,!arduino,!qtpy,!m5stamp_c3
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
//go:build thingplus_rp2040
|
|
||||||
// +build thingplus_rp2040
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "machine"
|
|
||||||
|
|
||||||
// This is the pin assignment for the internal neopixel of the
|
|
||||||
// Sparkfun thingplus rp2040.
|
|
||||||
// Replace neo and led in the code below to match the pin
|
|
||||||
// that you are using if different.
|
|
||||||
var neo machine.Pin = machine.GPIO8
|
|
||||||
var led = machine.LED
|
|
||||||
@@ -5,8 +5,8 @@ go 1.15
|
|||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||||
github.com/frankban/quicktest v1.10.2
|
github.com/frankban/quicktest v1.10.2
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
||||||
tinygo.org/x/tinyfont v0.3.0
|
tinygo.org/x/tinyfont v0.2.1
|
||||||
tinygo.org/x/tinyfs v0.2.0
|
tinygo.org/x/tinyfs v0.1.0
|
||||||
tinygo.org/x/tinyterm v0.1.0
|
tinygo.org/x/tinyterm v0.1.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ github.com/frankban/quicktest v1.10.2 h1:19ARM85nVi4xH7xPXuc5eM/udya5ieh7b/Sv+d8
|
|||||||
github.com/frankban/quicktest v1.10.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
github.com/frankban/quicktest v1.10.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
||||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/hajimehoshi/go-jisx0208 v1.0.0/go.mod h1:yYxEStHL7lt9uL+AbdWgW9gBumwieDoZCiB1f/0X0as=
|
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/sago35/go-bdf v0.0.0-20200313142241-6c17821c91c4/go.mod h1:rOebXGuMLsXhZAC6mF/TjxONsm45498ZyzVhel++6KM=
|
|
||||||
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
|
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
|
||||||
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -27,12 +24,9 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
|
|||||||
tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||||
tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||||
tinygo.org/x/drivers v0.16.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
tinygo.org/x/drivers v0.16.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||||
tinygo.org/x/drivers v0.19.0/go.mod h1:uJD/l1qWzxzLx+vcxaW0eY464N5RAgFi1zTVzASFdqI=
|
tinygo.org/x/tinyfont v0.2.1 h1:FAaemBzw8wsfhAtG6fWW+QjyWw/K8YqEeiWo4N1pv4o=
|
||||||
tinygo.org/x/tinyfont v0.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM=
|
tinygo.org/x/tinyfont v0.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM=
|
||||||
tinygo.org/x/tinyfont v0.3.0 h1:HIRLQoI3oc+2CMhPcfv+Ig88EcTImE/5npjqOnMD4lM=
|
tinygo.org/x/tinyfs v0.1.0 h1:yx1Tq9L60rpCm6HURo45x+Tnag+O9RGSbQfgeCb6XYU=
|
||||||
tinygo.org/x/tinyfont v0.3.0/go.mod h1:+TV5q0KpwSGRWnN+ITijsIhrWYJkoUCp9MYELjKpAXk=
|
|
||||||
tinygo.org/x/tinyfs v0.1.0/go.mod h1:ysc8Y92iHfhTXeyEM9+c7zviUQ4fN9UCFgSOFfMWv20=
|
tinygo.org/x/tinyfs v0.1.0/go.mod h1:ysc8Y92iHfhTXeyEM9+c7zviUQ4fN9UCFgSOFfMWv20=
|
||||||
tinygo.org/x/tinyfs v0.2.0 h1:M0lwZC/dEGFt16XYN5GTQsif/qCkAN2qUVNxELVD1xg=
|
|
||||||
tinygo.org/x/tinyfs v0.2.0/go.mod h1:6ZHYdvB3sFYeMB3ypmXZCNEnFwceKc61ADYTYHpep1E=
|
|
||||||
tinygo.org/x/tinyterm v0.1.0 h1:80i+j+KWoxCFa/Xfp6pWbh79x+8zUdMXC1vaKj2QhkY=
|
tinygo.org/x/tinyterm v0.1.0 h1:80i+j+KWoxCFa/Xfp6pWbh79x+8zUdMXC1vaKj2QhkY=
|
||||||
tinygo.org/x/tinyterm v0.1.0/go.mod h1:/DDhNnGwNF2/tNgHywvyZuCGnbH3ov49Z/6e8LPLRR4=
|
tinygo.org/x/tinyterm v0.1.0/go.mod h1:/DDhNnGwNF2/tNgHywvyZuCGnbH3ov49Z/6e8LPLRR4=
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ func (ir *ReceiverDevice) pinChange(pin machine.Pin) {
|
|||||||
ir.resetStateMachine()
|
ir.resetStateMachine()
|
||||||
} else {
|
} else {
|
||||||
// 562.5µs OR 1687.5µs space detected
|
// 562.5µs OR 1687.5µs space detected
|
||||||
mask := uint32(1 << ir.bitIndex)
|
mask := uint32((1 << (31 - ir.bitIndex)))
|
||||||
if duration > time.Microsecond*1000 {
|
if duration > time.Microsecond*1000 {
|
||||||
// 1687.5µs space detected (logic 1) - Set bit
|
// 1687.5µs space detected (logic 1) - Set bit
|
||||||
ir.data.Code |= mask
|
ir.data.Code |= mask
|
||||||
@@ -201,16 +201,16 @@ const (
|
|||||||
|
|
||||||
func (ir *ReceiverDevice) decode() irDecodeError {
|
func (ir *ReceiverDevice) decode() irDecodeError {
|
||||||
// Decode cmd and inverse cmd and perform validation check
|
// Decode cmd and inverse cmd and perform validation check
|
||||||
cmd := uint8((ir.data.Code & 0x00ff0000) >> 16)
|
cmd := uint8((ir.data.Code & 0xff00) >> 8)
|
||||||
invCmd := uint8((ir.data.Code & 0xff000000) >> 24)
|
invCmd := uint8(ir.data.Code & 0xff)
|
||||||
if cmd != ^invCmd {
|
if cmd != ^invCmd {
|
||||||
// Validation failure. cmd and inverse cmd do not match
|
// Validation failure. cmd and inverse cmd do not match
|
||||||
return irDecodeErrorInverseCheckFail
|
return irDecodeErrorInverseCheckFail
|
||||||
}
|
}
|
||||||
// cmd validation pass, decode address
|
// cmd validation pass, decode address
|
||||||
ir.data.Command = uint16(cmd)
|
ir.data.Command = uint16(cmd)
|
||||||
addrLow := uint8(ir.data.Code & 0xff)
|
addrLow := uint8((ir.data.Code & 0xff000000) >> 24)
|
||||||
addrHigh := uint8((ir.data.Code & 0xff00) >> 8)
|
addrHigh := uint8((ir.data.Code & 0x00ff0000) >> 16)
|
||||||
if addrHigh == ^addrLow {
|
if addrHigh == ^addrLow {
|
||||||
// addrHigh is inverse of addrLow. This is not a valid 16-bit address in extended NEC coding
|
// addrHigh is inverse of addrLow. This is not a valid 16-bit address in extended NEC coding
|
||||||
// since it is indistinguishable from 8-bit address with inverse validation. Use the 8-bit address
|
// since it is indistinguishable from 8-bit address with inverse validation. Use the 8-bit address
|
||||||
|
|||||||
@@ -1,189 +0,0 @@
|
|||||||
// Package lsm6ds3tr implements a driver for the LSM6DS3TR
|
|
||||||
// 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 (
|
|
||||||
"errors"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AccelRange uint8
|
|
||||||
type AccelSampleRate uint8
|
|
||||||
type AccelBandwidth uint8
|
|
||||||
|
|
||||||
type GyroRange uint8
|
|
||||||
type GyroSampleRate uint8
|
|
||||||
|
|
||||||
// Device wraps an I2C connection to a LSM6DS3TR device.
|
|
||||||
type Device struct {
|
|
||||||
bus drivers.I2C
|
|
||||||
Address uint16
|
|
||||||
accelRange AccelRange
|
|
||||||
accelSampleRate AccelSampleRate
|
|
||||||
gyroRange GyroRange
|
|
||||||
gyroSampleRate GyroSampleRate
|
|
||||||
buf [6]uint8
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configuration for LSM6DS3TR device.
|
|
||||||
type Configuration struct {
|
|
||||||
AccelRange AccelRange
|
|
||||||
AccelSampleRate AccelSampleRate
|
|
||||||
AccelBandWidth AccelBandwidth
|
|
||||||
GyroRange GyroRange
|
|
||||||
GyroSampleRate GyroSampleRate
|
|
||||||
IsPedometer bool
|
|
||||||
ResetStepCounter bool
|
|
||||||
}
|
|
||||||
|
|
||||||
var errNotConnected = errors.New("lsm6ds3tr: failed to communicate with acel/gyro sensor")
|
|
||||||
|
|
||||||
// New creates a new LSM6DS3TR connection. The I2C bus must already be configured.
|
|
||||||
//
|
|
||||||
// This function only creates the Device object, it does not touch the device.
|
|
||||||
func New(bus drivers.I2C) *Device {
|
|
||||||
return &Device{
|
|
||||||
bus: bus,
|
|
||||||
Address: Address,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure sets up the device for communication.
|
|
||||||
func (d *Device) doConfigure(cfg Configuration) (err error) {
|
|
||||||
|
|
||||||
// Verify unit communication
|
|
||||||
if !d.Connected() {
|
|
||||||
return errNotConnected
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.AccelRange != 0 {
|
|
||||||
d.accelRange = cfg.AccelRange
|
|
||||||
} else {
|
|
||||||
d.accelRange = ACCEL_2G
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.AccelSampleRate != 0 {
|
|
||||||
d.accelSampleRate = cfg.AccelSampleRate
|
|
||||||
} else {
|
|
||||||
d.accelSampleRate = ACCEL_SR_104
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.GyroRange != 0 {
|
|
||||||
d.gyroRange = cfg.GyroRange
|
|
||||||
} else {
|
|
||||||
d.gyroRange = GYRO_2000DPS
|
|
||||||
}
|
|
||||||
|
|
||||||
if cfg.GyroSampleRate != 0 {
|
|
||||||
d.gyroSampleRate = cfg.GyroSampleRate
|
|
||||||
} else {
|
|
||||||
d.gyroSampleRate = GYRO_SR_104
|
|
||||||
}
|
|
||||||
|
|
||||||
data := d.buf[:1]
|
|
||||||
|
|
||||||
// Configure accelerometer
|
|
||||||
data[0] = uint8(d.accelRange) | uint8(d.accelSampleRate)
|
|
||||||
err = d.bus.WriteRegister(uint8(d.Address), CTRL1_XL, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set ODR bit
|
|
||||||
err = d.bus.ReadRegister(uint8(d.Address), CTRL4_C, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data[0] = data[0] &^ BW_SCAL_ODR_ENABLED
|
|
||||||
data[0] |= BW_SCAL_ODR_ENABLED
|
|
||||||
err = d.bus.WriteRegister(uint8(d.Address), CTRL4_C, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure gyroscope
|
|
||||||
data[0] = uint8(d.gyroRange) | uint8(d.gyroSampleRate)
|
|
||||||
err = d.bus.WriteRegister(uint8(d.Address), CTRL2_G, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connected returns whether a LSM6DS3TR has been found.
|
|
||||||
// It does a "who am I" request and checks the response.
|
|
||||||
func (d *Device) Connected() bool {
|
|
||||||
data := d.buf[:1]
|
|
||||||
d.bus.ReadRegister(uint8(d.Address), WHO_AM_I, data)
|
|
||||||
return data[0] == 0x6A
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadAcceleration reads the current acceleration from the device and returns
|
|
||||||
// it in µg (micro-gravity). When one of the axes is pointing straight to Earth
|
|
||||||
// and the sensor is not moving the returned value will be around 1000000 or
|
|
||||||
// -1000000.
|
|
||||||
func (d *Device) ReadAcceleration() (x, y, z int32, err error) {
|
|
||||||
data := d.buf[:6]
|
|
||||||
err = d.bus.ReadRegister(uint8(d.Address), OUTX_L_XL, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// k comes from "Table 3. Mechanical characteristics" 3 of the datasheet * 1000
|
|
||||||
k := int32(61) // 2G
|
|
||||||
if d.accelRange == ACCEL_4G {
|
|
||||||
k = 122
|
|
||||||
} else if d.accelRange == ACCEL_8G {
|
|
||||||
k = 244
|
|
||||||
} else if d.accelRange == ACCEL_16G {
|
|
||||||
k = 488
|
|
||||||
}
|
|
||||||
x = int32(int16((uint16(data[1])<<8)|uint16(data[0]))) * k
|
|
||||||
y = int32(int16((uint16(data[3])<<8)|uint16(data[2]))) * k
|
|
||||||
z = int32(int16((uint16(data[5])<<8)|uint16(data[4]))) * k
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadRotation reads the current rotation from the device and returns it in
|
|
||||||
// µ°/s (micro-degrees/sec). This means that if you were to do a complete
|
|
||||||
// rotation along one axis and while doing so integrate all values over time,
|
|
||||||
// you would get a value close to 360000000.
|
|
||||||
func (d *Device) ReadRotation() (x, y, z int32, err error) {
|
|
||||||
data := d.buf[:6]
|
|
||||||
err = d.bus.ReadRegister(uint8(d.Address), OUTX_L_G, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// k comes from "Table 3. Mechanical characteristics" 3 of the datasheet * 1000
|
|
||||||
k := int32(4375) // 125DPS
|
|
||||||
if d.gyroRange == GYRO_245DPS {
|
|
||||||
k = 8750
|
|
||||||
} else if d.gyroRange == GYRO_500DPS {
|
|
||||||
k = 17500
|
|
||||||
} else if d.gyroRange == GYRO_1000DPS {
|
|
||||||
k = 35000
|
|
||||||
} else if d.gyroRange == GYRO_2000DPS {
|
|
||||||
k = 70000
|
|
||||||
}
|
|
||||||
x = int32(int16((uint16(data[1])<<8)|uint16(data[0]))) * k
|
|
||||||
y = int32(int16((uint16(data[3])<<8)|uint16(data[2]))) * k
|
|
||||||
z = int32(int16((uint16(data[5])<<8)|uint16(data[4]))) * k
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
|
|
||||||
func (d *Device) ReadTemperature() (t int32, err error) {
|
|
||||||
data := d.buf[:2]
|
|
||||||
err = d.bus.ReadRegister(uint8(d.Address), OUT_TEMP_L, data)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// From "Table 5. Temperature sensor characteristics"
|
|
||||||
// temp = value/256 + 25
|
|
||||||
t = 25000 + (int32(int16((int16(data[1])<<8)|int16(data[0])))*125)/32
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
//go:build !xiao_ble
|
|
||||||
// +build !xiao_ble
|
|
||||||
|
|
||||||
package lsm6ds3tr
|
|
||||||
|
|
||||||
// Configure sets up the device for communication.
|
|
||||||
func (d *Device) Configure(cfg Configuration) error {
|
|
||||||
return d.doConfigure(cfg)
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
//go:build xiao_ble
|
|
||||||
// +build xiao_ble
|
|
||||||
|
|
||||||
package lsm6ds3tr
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/nrf"
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Configure sets up the device for communication.
|
|
||||||
func (d *Device) Configure(cfg Configuration) error {
|
|
||||||
|
|
||||||
// Following lines are XIAO BLE Sense specific, they have nothing to do with sensor per se
|
|
||||||
// Implementation adapted from https://github.com/Seeed-Studio/Seeed_Arduino_LSM6DS3/blob/master/LSM6DS3.cpp#L68-L77
|
|
||||||
|
|
||||||
// Special mode for IMU power pin on this board.
|
|
||||||
// Can not use pin.Configure() directly due to special mode and 32 bit size
|
|
||||||
pinConfig := uint32(nrf.GPIO_PIN_CNF_DIR_Output<<nrf.GPIO_PIN_CNF_DIR_Pos) |
|
|
||||||
uint32(nrf.GPIO_PIN_CNF_INPUT_Disconnect<<nrf.GPIO_PIN_CNF_INPUT_Pos) |
|
|
||||||
uint32(nrf.GPIO_PIN_CNF_PULL_Disabled<<nrf.GPIO_PIN_CNF_PULL_Pos) |
|
|
||||||
uint32(nrf.GPIO_PIN_CNF_DRIVE_H0H1<<nrf.GPIO_PIN_CNF_DRIVE_Pos) |
|
|
||||||
uint32(nrf.GPIO_PIN_CNF_SENSE_Disabled<<nrf.GPIO_PIN_CNF_SENSE_Pos)
|
|
||||||
nrf.P1.PIN_CNF[8].Set(pinConfig) // LSM_PWR == P1_08
|
|
||||||
|
|
||||||
// Enable IMU
|
|
||||||
machine.LSM_PWR.High()
|
|
||||||
|
|
||||||
// Wait a moment
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
|
|
||||||
// Common initialisation code
|
|
||||||
return d.doConfigure(cfg)
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
package lsm6ds3tr
|
|
||||||
|
|
||||||
// Constants/addresses used for I2C.
|
|
||||||
|
|
||||||
// The I2C address which this device listens to.
|
|
||||||
const Address = 0x6A
|
|
||||||
|
|
||||||
const (
|
|
||||||
WHO_AM_I = 0x0F
|
|
||||||
STATUS = 0x1E
|
|
||||||
CTRL1_XL = 0x10
|
|
||||||
CTRL2_G = 0x11
|
|
||||||
CTRL3_C = 0x12
|
|
||||||
CTRL4_C = 0x13
|
|
||||||
CTRL5_C = 0x14
|
|
||||||
CTRL6_C = 0x15
|
|
||||||
CTRL7_G = 0x16
|
|
||||||
CTRL8_XL = 0x17
|
|
||||||
CTRL9_XL = 0x18
|
|
||||||
CTRL10_C = 0x19
|
|
||||||
OUTX_L_G = 0x22
|
|
||||||
OUTX_H_G = 0x23
|
|
||||||
OUTY_L_G = 0x24
|
|
||||||
OUTY_H_G = 0x25
|
|
||||||
OUTZ_L_G = 0x26
|
|
||||||
OUTZ_H_G = 0x27
|
|
||||||
OUTX_L_XL = 0x28
|
|
||||||
OUTX_H_XL = 0x29
|
|
||||||
OUTY_L_XL = 0x2A
|
|
||||||
OUTY_H_XL = 0x2B
|
|
||||||
OUTZ_L_XL = 0x2C
|
|
||||||
OUTZ_H_XL = 0x2D
|
|
||||||
OUT_TEMP_L = 0x20
|
|
||||||
OUT_TEMP_H = 0x21
|
|
||||||
BW_SCAL_ODR_DISABLED = 0x00
|
|
||||||
BW_SCAL_ODR_ENABLED = 0x80
|
|
||||||
STEP_TIMESTAMP_L = 0x49
|
|
||||||
STEP_TIMESTAMP_H = 0x4A
|
|
||||||
STEP_COUNTER_L = 0x4B
|
|
||||||
STEP_COUNTER_H = 0x4C
|
|
||||||
STEP_COUNT_DELTA = 0x15
|
|
||||||
TAP_CFG = 0x58
|
|
||||||
INT1_CTRL = 0x0D
|
|
||||||
|
|
||||||
ACCEL_2G AccelRange = 0x00
|
|
||||||
ACCEL_4G AccelRange = 0x08
|
|
||||||
ACCEL_8G AccelRange = 0x0C
|
|
||||||
ACCEL_16G AccelRange = 0x04
|
|
||||||
|
|
||||||
ACCEL_SR_OFF AccelSampleRate = 0x00
|
|
||||||
ACCEL_SR_13 AccelSampleRate = 0x10
|
|
||||||
ACCEL_SR_26 AccelSampleRate = 0x20
|
|
||||||
ACCEL_SR_52 AccelSampleRate = 0x30
|
|
||||||
ACCEL_SR_104 AccelSampleRate = 0x40
|
|
||||||
ACCEL_SR_208 AccelSampleRate = 0x50
|
|
||||||
ACCEL_SR_416 AccelSampleRate = 0x60
|
|
||||||
ACCEL_SR_833 AccelSampleRate = 0x70
|
|
||||||
ACCEL_SR_1666 AccelSampleRate = 0x80
|
|
||||||
ACCEL_SR_3332 AccelSampleRate = 0x90
|
|
||||||
ACCEL_SR_6664 AccelSampleRate = 0xA0
|
|
||||||
|
|
||||||
GYRO_125DPS GyroRange = 0x02
|
|
||||||
GYRO_245DPS GyroRange = 0x00
|
|
||||||
GYRO_500DPS GyroRange = 0x04
|
|
||||||
GYRO_1000DPS GyroRange = 0x08
|
|
||||||
GYRO_2000DPS GyroRange = 0x0C
|
|
||||||
|
|
||||||
GYRO_SR_OFF GyroSampleRate = 0x00
|
|
||||||
GYRO_SR_13 GyroSampleRate = 0x10
|
|
||||||
GYRO_SR_26 GyroSampleRate = 0x20
|
|
||||||
GYRO_SR_52 GyroSampleRate = 0x30
|
|
||||||
GYRO_SR_104 GyroSampleRate = 0x40
|
|
||||||
GYRO_SR_208 GyroSampleRate = 0x50
|
|
||||||
GYRO_SR_416 GyroSampleRate = 0x60
|
|
||||||
GYRO_SR_833 GyroSampleRate = 0x70
|
|
||||||
GYRO_SR_1666 GyroSampleRate = 0x80
|
|
||||||
GYRO_SR_3332 GyroSampleRate = 0x90
|
|
||||||
GYRO_SR_6664 GyroSampleRate = 0xA0
|
|
||||||
)
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package makeybutton
|
|
||||||
|
|
||||||
const bufferSize = 6
|
|
||||||
|
|
||||||
// Buffer is a buffer to keep track of the most recent readings for a button.
|
|
||||||
type Buffer struct {
|
|
||||||
readings [bufferSize]bool
|
|
||||||
index int
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewBuffer returns a new buffer.
|
|
||||||
func NewBuffer() *Buffer {
|
|
||||||
return &Buffer{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Used returns how many bytes in buffer have been used.
|
|
||||||
func (b *Buffer) Used() int {
|
|
||||||
return b.index
|
|
||||||
}
|
|
||||||
|
|
||||||
// Put stores a boolean in the buffer.
|
|
||||||
func (b *Buffer) Put(val bool) bool {
|
|
||||||
b.index++
|
|
||||||
if b.index >= bufferSize {
|
|
||||||
b.index = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
b.readings[b.index] = val
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avg returns the "average" of all the readings in the buffer, by
|
|
||||||
// treating a true as 1 and a false as -1.
|
|
||||||
func (b *Buffer) Avg() int {
|
|
||||||
avg := 0
|
|
||||||
for i := 0; i < bufferSize; i++ {
|
|
||||||
if b.readings[i] {
|
|
||||||
avg += 1
|
|
||||||
} else {
|
|
||||||
avg -= 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return avg
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
// Package makeybutton providers a driver for a button that can be triggered
|
|
||||||
// by anything that is conductive by using an ultra high value resistor.
|
|
||||||
//
|
|
||||||
// Inspired by the amazing MakeyMakey
|
|
||||||
// https://makeymakey.com/
|
|
||||||
//
|
|
||||||
package makeybutton
|
|
||||||
|
|
||||||
import (
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ButtonState represents the state of a MakeyButton.
|
|
||||||
type ButtonState int
|
|
||||||
|
|
||||||
const (
|
|
||||||
NeverPressed ButtonState = 0
|
|
||||||
Press = 1
|
|
||||||
Release = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
// ButtonEvent represents when the state of a Button changes.
|
|
||||||
type ButtonEvent int
|
|
||||||
|
|
||||||
const (
|
|
||||||
NotChanged ButtonEvent = 0
|
|
||||||
Pressed = 1
|
|
||||||
Released = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
// Button is a "button"-like device that acts like a MakeyMakey.
|
|
||||||
type Button struct {
|
|
||||||
pin machine.Pin
|
|
||||||
state ButtonState
|
|
||||||
readings *Buffer
|
|
||||||
HighMeansPressed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewButton creates a new Button.
|
|
||||||
func NewButton(pin machine.Pin) *Button {
|
|
||||||
return &Button{
|
|
||||||
pin: pin,
|
|
||||||
state: NeverPressed,
|
|
||||||
readings: NewBuffer(),
|
|
||||||
HighMeansPressed: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,
|
|
||||||
// in order for the pin to be properly floating.
|
|
||||||
b.pin.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
b.pin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
|
||||||
b.pin.Set(false)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get returns a ButtonEvent based on the most recent state of the button,
|
|
||||||
// and if it has changed by being pressed or released.
|
|
||||||
func (b *Button) Get() ButtonEvent {
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
|
||||||
b.state = Release
|
|
||||||
return Released
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NotChanged
|
|
||||||
}
|
|
||||||
+10
-25
@@ -20,11 +20,6 @@ func SetBuf(b []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Do(req *Request) (*Response, error) {
|
func (c *Client) Do(req *Request) (*Response, error) {
|
||||||
if c.Jar != nil {
|
|
||||||
for _, cookie := range c.Jar.Cookies(req.URL) {
|
|
||||||
req.AddCookie(cookie)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch req.URL.Scheme {
|
switch req.URL.Scheme {
|
||||||
case "http":
|
case "http":
|
||||||
return c.doHTTP(req)
|
return c.doHTTP(req)
|
||||||
@@ -36,17 +31,15 @@ func (c *Client) Do(req *Request) (*Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doHTTP(req *Request) (*Response, error) {
|
func (c *Client) doHTTP(req *Request) (*Response, error) {
|
||||||
|
if c.Jar != nil {
|
||||||
|
for _, cookie := range c.Jar.Cookies(req.URL) {
|
||||||
|
req.AddCookie(cookie)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// make TCP connection
|
// make TCP connection
|
||||||
ip := net.ParseIP(req.URL.Hostname())
|
ip := net.ParseIP(req.URL.Host)
|
||||||
port := 80
|
raddr := &net.TCPAddr{IP: ip, Port: 80}
|
||||||
if req.URL.Port() != "" {
|
|
||||||
p, err := strconv.ParseUint(req.URL.Port(), 0, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
port = int(p)
|
|
||||||
}
|
|
||||||
raddr := &net.TCPAddr{IP: ip, Port: port}
|
|
||||||
laddr := &net.TCPAddr{Port: 8080}
|
laddr := &net.TCPAddr{Port: 8080}
|
||||||
|
|
||||||
conn, err := net.DialTCP("tcp", laddr, raddr)
|
conn, err := net.DialTCP("tcp", laddr, raddr)
|
||||||
@@ -185,17 +178,12 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
println("Read error: " + err.Error())
|
println("Read error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
// Take care of the case where "\r\n\r\n" is on the boundary of a buffer
|
idx := bytes.Index(buf[ofs:ofs+n], []byte("\r\n\r\n"))
|
||||||
start := ofs
|
|
||||||
if start > 3 {
|
|
||||||
start -= 3
|
|
||||||
}
|
|
||||||
idx := bytes.Index(buf[start:ofs+n], []byte("\r\n\r\n"))
|
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
ofs += n
|
ofs += n
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
idx += start + 4
|
idx += ofs + 4
|
||||||
|
|
||||||
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
|
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
|
||||||
if resp.Status == "" && scanner.Scan() {
|
if resp.Status == "" && scanner.Scan() {
|
||||||
@@ -273,9 +261,6 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
|
|||||||
return nil, fmt.Errorf("slice out of range : use http.SetBuf() to change the allocation to %d bytes or more", end)
|
return nil, fmt.Errorf("slice out of range : use http.SetBuf() to change the allocation to %d bytes or more", end)
|
||||||
}
|
}
|
||||||
n, err := conn.Read(buf[ofs : ofs+0x400])
|
n, err := conn.Read(buf[ofs : ofs+0x400])
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,12 +100,6 @@ func (c *mqttclient) Connect() Token {
|
|||||||
connectPkt.ProtocolName = "MQTT"
|
connectPkt.ProtocolName = "MQTT"
|
||||||
connectPkt.Keepalive = 60
|
connectPkt.Keepalive = 60
|
||||||
|
|
||||||
connectPkt.WillFlag = c.opts.WillEnabled
|
|
||||||
connectPkt.WillTopic = c.opts.WillTopic
|
|
||||||
connectPkt.WillMessage = c.opts.WillPayload
|
|
||||||
connectPkt.WillQos = c.opts.WillQos
|
|
||||||
connectPkt.WillRetain = c.opts.WillRetained
|
|
||||||
|
|
||||||
err = connectPkt.Write(c.conn)
|
err = connectPkt.Write(c.conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &mqtttoken{err: err}
|
return &mqtttoken{err: err}
|
||||||
@@ -152,7 +146,6 @@ func (c *mqttclient) Publish(topic string, qos byte, retained bool, payload inte
|
|||||||
pub := packets.NewControlPacket(packets.Publish).(*packets.PublishPacket)
|
pub := packets.NewControlPacket(packets.Publish).(*packets.PublishPacket)
|
||||||
pub.Qos = qos
|
pub.Qos = qos
|
||||||
pub.TopicName = topic
|
pub.TopicName = topic
|
||||||
pub.Retain = retained
|
|
||||||
switch payload.(type) {
|
switch payload.(type) {
|
||||||
case string:
|
case string:
|
||||||
pub.Payload = []byte(payload.(string))
|
pub.Payload = []byte(payload.(string))
|
||||||
|
|||||||
@@ -118,9 +118,6 @@ func (r *RTL8720DN) ConnectSSLSocket(addr, port string) error {
|
|||||||
if r.debug {
|
if r.debug {
|
||||||
fmt.Printf("ConnectSSLSocket(%q, %q)\r\n", addr, port)
|
fmt.Printf("ConnectSSLSocket(%q, %q)\r\n", addr, port)
|
||||||
}
|
}
|
||||||
if r.root_ca == nil {
|
|
||||||
return fmt.Errorf("root_ca is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := r.Rpc_wifi_ssl_client_create()
|
client, err := r.Rpc_wifi_ssl_client_create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-32
@@ -1,10 +1,6 @@
|
|||||||
package rtl8720dn
|
package rtl8720dn
|
||||||
|
|
||||||
import (
|
import "io"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const maxUartRecvSize = 128
|
const maxUartRecvSize = 128
|
||||||
|
|
||||||
@@ -42,33 +38,6 @@ func New(r io.ReadWriter) *RTL8720DN {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RTL8720DN) Rpc_tcpip_adapter_init_with_timeout(d time.Duration) (int32, error) {
|
|
||||||
timeout := make(chan bool)
|
|
||||||
go func() {
|
|
||||||
time.Sleep(d)
|
|
||||||
timeout <- true
|
|
||||||
}()
|
|
||||||
|
|
||||||
var ret int32
|
|
||||||
var err error
|
|
||||||
done := make(chan bool)
|
|
||||||
go func() {
|
|
||||||
ret, err = r.Rpc_tcpip_adapter_init()
|
|
||||||
done <- true
|
|
||||||
}()
|
|
||||||
|
|
||||||
select {
|
|
||||||
case <-timeout:
|
|
||||||
return ret, fmt.Errorf("Rpc_tcpip_adapter_init: timeout")
|
|
||||||
case <-done:
|
|
||||||
if err != nil {
|
|
||||||
return ret, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *RTL8720DN) SetSeq(s uint64) {
|
func (r *RTL8720DN) SetSeq(s uint64) {
|
||||||
r.seq = s
|
r.seq = s
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus *machine.SPI
|
bus machine.SPI
|
||||||
sck machine.Pin
|
sck machine.Pin
|
||||||
sdo machine.Pin
|
sdo machine.Pin
|
||||||
sdi machine.Pin
|
sdi machine.Pin
|
||||||
@@ -41,7 +41,7 @@ type Device struct {
|
|||||||
CSD *CSD
|
CSD *CSD
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(b *machine.SPI, sck, sdo, sdi, cs machine.Pin) Device {
|
func New(b machine.SPI, sck, sdo, sdi, cs machine.Pin) Device {
|
||||||
return Device{
|
return Device{
|
||||||
bus: b,
|
bus: b,
|
||||||
cs: cs,
|
cs: cs,
|
||||||
|
|||||||
+1
-1
@@ -103,7 +103,7 @@ func (d *Device) Configure(cfg Config) {
|
|||||||
d.Command(SET_MUX_RATIO)
|
d.Command(SET_MUX_RATIO)
|
||||||
d.Data(0x7F)
|
d.Data(0x7F)
|
||||||
d.Command(SET_REMAP_COLORDEPTH)
|
d.Command(SET_REMAP_COLORDEPTH)
|
||||||
d.Data(0x62)
|
d.Data(0x72)
|
||||||
d.Command(SET_COLUMN_ADDRESS)
|
d.Command(SET_COLUMN_ADDRESS)
|
||||||
d.Data(0x00)
|
d.Data(0x00)
|
||||||
d.Data(0x7F)
|
d.Data(0x7F)
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
package uc8151
|
|
||||||
|
|
||||||
// Registers
|
|
||||||
const (
|
|
||||||
// Display resolution
|
|
||||||
EPD_WIDTH = 128
|
|
||||||
EPD_HEIGHT = 296
|
|
||||||
|
|
||||||
PSR = 0x00
|
|
||||||
PWR = 0x01
|
|
||||||
POF = 0x02
|
|
||||||
PFS = 0x03
|
|
||||||
PON = 0x04
|
|
||||||
PMES = 0x05
|
|
||||||
BTST = 0x06
|
|
||||||
DSLP = 0x07
|
|
||||||
DTM1 = 0x10
|
|
||||||
DSP = 0x11
|
|
||||||
DRF = 0x12
|
|
||||||
DTM2 = 0x13
|
|
||||||
LUT_VCOM = 0x20
|
|
||||||
LUT_WW = 0x21
|
|
||||||
LUT_BW = 0x22
|
|
||||||
LUT_WB = 0x23
|
|
||||||
LUT_BB = 0x24
|
|
||||||
PLL = 0x30
|
|
||||||
TSC = 0x40
|
|
||||||
TSE = 0x41
|
|
||||||
TSR = 0x43
|
|
||||||
TSW = 0x42
|
|
||||||
CDI = 0x50
|
|
||||||
LPD = 0x51
|
|
||||||
TCON = 0x60
|
|
||||||
TRES = 0x61
|
|
||||||
REV = 0x70
|
|
||||||
FLG = 0x71
|
|
||||||
AMV = 0x80
|
|
||||||
VV = 0x81
|
|
||||||
VDCS = 0x82
|
|
||||||
PTL = 0x90
|
|
||||||
PTIN = 0x91
|
|
||||||
PTOU = 0x92
|
|
||||||
PGM = 0xa0
|
|
||||||
APG = 0xa1
|
|
||||||
ROTP = 0xa2
|
|
||||||
CCSET = 0xe0
|
|
||||||
PWS = 0xe3
|
|
||||||
TSSET = 0xe5
|
|
||||||
|
|
||||||
RES_96x230 = 0b00000000
|
|
||||||
RES_96x252 = 0b01000000
|
|
||||||
RES_128x296 = 0b10000000
|
|
||||||
RES_160x296 = 0b11000000
|
|
||||||
|
|
||||||
LUT_OTP = 0b00000000
|
|
||||||
LUT_REG = 0b00100000
|
|
||||||
|
|
||||||
FORMAT_BWR = 0b00000000
|
|
||||||
FORMAT_BW = 0b00010000
|
|
||||||
|
|
||||||
SCAN_DOWN = 0b00000000
|
|
||||||
SCAN_UP = 0b00001000
|
|
||||||
|
|
||||||
SHIFT_LEFT = 0b00000000
|
|
||||||
SHIFT_RIGHT = 0b00000100
|
|
||||||
|
|
||||||
BOOSTER_OFF = 0b00000000
|
|
||||||
BOOSTER_ON = 0b00000010
|
|
||||||
|
|
||||||
RESET_SOFT = 0b00000000
|
|
||||||
RESET_NONE = 0b00000001
|
|
||||||
|
|
||||||
VDS_EXTERNAL = 0b00000000
|
|
||||||
VDS_INTERNAL = 0b00000010
|
|
||||||
|
|
||||||
VDG_EXTERNAL = 0b00000000
|
|
||||||
VDG_INTERNAL = 0b00000001
|
|
||||||
|
|
||||||
VCOM_VD = 0b00000000
|
|
||||||
VCOM_VG = 0b00000100
|
|
||||||
|
|
||||||
VGHL_16V = 0b00000000
|
|
||||||
VGHL_15V = 0b00000001
|
|
||||||
VGHL_14V = 0b00000010
|
|
||||||
VGHL_13V = 0b00000011
|
|
||||||
|
|
||||||
START_10MS = 0b00000000
|
|
||||||
START_20MS = 0b01000000
|
|
||||||
START_30MS = 0b10000000
|
|
||||||
START_40MS = 0b11000000
|
|
||||||
|
|
||||||
STRENGTH_1 = 0b00000000
|
|
||||||
STRENGTH_2 = 0b00001000
|
|
||||||
STRENGTH_3 = 0b00010000
|
|
||||||
STRENGTH_4 = 0b00011000
|
|
||||||
STRENGTH_5 = 0b00100000
|
|
||||||
STRENGTH_6 = 0b00101000
|
|
||||||
STRENGTH_7 = 0b00110000
|
|
||||||
STRENGTH_8 = 0b00111000
|
|
||||||
|
|
||||||
OFF_0_27US = 0b00000000
|
|
||||||
OFF_0_34US = 0b00000001
|
|
||||||
OFF_0_40US = 0b00000010
|
|
||||||
OFF_0_54US = 0b00000011
|
|
||||||
OFF_0_80US = 0b00000100
|
|
||||||
OFF_1_54US = 0b00000101
|
|
||||||
OFF_3_34US = 0b00000110
|
|
||||||
OFF_6_58US = 0b00000111
|
|
||||||
|
|
||||||
FRAMES_1 = 0b00000000
|
|
||||||
FRAMES_2 = 0b00010000
|
|
||||||
FRAMES_3 = 0b00100000
|
|
||||||
FRAMES_4 = 0b00110000
|
|
||||||
|
|
||||||
TEMP_INTERNAL = 0b00000000
|
|
||||||
TEMP_EXTERNAL = 0b10000000
|
|
||||||
|
|
||||||
OFFSET_0 = 0b00000000
|
|
||||||
OFFSET_1 = 0b00000001
|
|
||||||
OFFSET_2 = 0b00000010
|
|
||||||
OFFSET_3 = 0b00000011
|
|
||||||
OFFSET_4 = 0b00000100
|
|
||||||
OFFSET_5 = 0b00000101
|
|
||||||
OFFSET_6 = 0b00000110
|
|
||||||
OFFSET_7 = 0b00000111
|
|
||||||
|
|
||||||
OFFSET_MIN_8 = 0b00001000
|
|
||||||
OFFSET_MIN_7 = 0b00001001
|
|
||||||
OFFSET_MIN_6 = 0b00001010
|
|
||||||
OFFSET_MIN_5 = 0b00001011
|
|
||||||
OFFSET_MIN_4 = 0b00001100
|
|
||||||
OFFSET_MIN_3 = 0b00001101
|
|
||||||
OFFSET_MIN_2 = 0b00001110
|
|
||||||
OFFSET_MIN_1 = 0b00001111
|
|
||||||
|
|
||||||
HZ_29 = 0b00111111
|
|
||||||
HZ_33 = 0b00111110
|
|
||||||
HZ_40 = 0b00111101
|
|
||||||
HZ_50 = 0b00111100
|
|
||||||
HZ_67 = 0b00111011
|
|
||||||
HZ_100 = 0b00111010
|
|
||||||
HZ_200 = 0b00111001
|
|
||||||
|
|
||||||
NO_ROTATION Rotation = 0
|
|
||||||
ROTATION_90 Rotation = 1 // 90 degrees clock-wise rotation
|
|
||||||
ROTATION_180 Rotation = 2
|
|
||||||
ROTATION_270 Rotation = 3
|
|
||||||
|
|
||||||
DEFAULT Speed = 0
|
|
||||||
MEDIUM Speed = 1
|
|
||||||
FAST Speed = 2
|
|
||||||
TURBO Speed = 3
|
|
||||||
)
|
|
||||||
@@ -1,634 +0,0 @@
|
|||||||
// Package uc8151 implements a driver for e-ink displays controlled by UC8151
|
|
||||||
//
|
|
||||||
// Inspired by https://github.com/pimoroni/pimoroni-pico/blob/main/drivers/uc8151/uc8151.cpp
|
|
||||||
// Datasheet: https://www.buydisplay.com/download/ic/UC8151C.pdf
|
|
||||||
//
|
|
||||||
package uc8151 // import "tinygo.org/x/drivers/uc8151"
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"image/color"
|
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Config struct {
|
|
||||||
Width int16
|
|
||||||
Height int16
|
|
||||||
Rotation Rotation // Rotation is clock-wise
|
|
||||||
Speed Speed // Value from DEFAULT, MEDIUM, FAST, TURBO
|
|
||||||
Blocking bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Device struct {
|
|
||||||
bus drivers.SPI
|
|
||||||
cs machine.Pin
|
|
||||||
dc machine.Pin
|
|
||||||
rst machine.Pin
|
|
||||||
busy machine.Pin
|
|
||||||
width int16
|
|
||||||
height int16
|
|
||||||
buffer []uint8
|
|
||||||
bufferLength uint32
|
|
||||||
rotation Rotation
|
|
||||||
speed Speed
|
|
||||||
blocking bool
|
|
||||||
}
|
|
||||||
|
|
||||||
type Rotation uint8
|
|
||||||
type Speed uint8
|
|
||||||
|
|
||||||
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus.
|
|
||||||
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
|
|
||||||
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
|
||||||
return Device{
|
|
||||||
bus: bus,
|
|
||||||
cs: csPin,
|
|
||||||
dc: dcPin,
|
|
||||||
rst: rstPin,
|
|
||||||
busy: busyPin,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure sets up the device.
|
|
||||||
func (d *Device) Configure(cfg Config) {
|
|
||||||
if cfg.Width != 0 {
|
|
||||||
d.width = cfg.Width
|
|
||||||
} else {
|
|
||||||
d.width = EPD_WIDTH
|
|
||||||
}
|
|
||||||
if cfg.Height != 0 {
|
|
||||||
d.height = cfg.Height
|
|
||||||
} else {
|
|
||||||
d.height = EPD_HEIGHT
|
|
||||||
}
|
|
||||||
d.rotation = cfg.Rotation
|
|
||||||
d.speed = cfg.Speed
|
|
||||||
d.blocking = cfg.Blocking
|
|
||||||
d.bufferLength = (uint32(d.width) * uint32(d.height)) / 8
|
|
||||||
d.buffer = make([]uint8, d.bufferLength)
|
|
||||||
for i := uint32(0); i < d.bufferLength; i++ {
|
|
||||||
d.buffer[i] = 0xFF
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Reset()
|
|
||||||
|
|
||||||
d.SendCommand(PSR)
|
|
||||||
if d.speed == 0 {
|
|
||||||
d.SendData(RES_128x296 | LUT_OTP | FORMAT_BW | SHIFT_RIGHT | BOOSTER_ON | RESET_NONE | SCAN_UP)
|
|
||||||
} else {
|
|
||||||
d.SendData(RES_128x296 | LUT_REG | FORMAT_BW | SHIFT_RIGHT | BOOSTER_ON | RESET_NONE | SCAN_UP)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.SetLUT(d.speed)
|
|
||||||
|
|
||||||
d.SendCommand(PWR)
|
|
||||||
d.SendData(VDS_INTERNAL | VDG_INTERNAL)
|
|
||||||
d.SendData(VCOM_VG | VGHL_16V)
|
|
||||||
d.SendData(0x2B)
|
|
||||||
d.SendData(0x2B)
|
|
||||||
d.SendData(0x2B)
|
|
||||||
|
|
||||||
d.SendCommand(PON)
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
|
|
||||||
d.SendCommand(BTST)
|
|
||||||
d.SendData(START_10MS | STRENGTH_3 | OFF_6_58US)
|
|
||||||
d.SendData(START_10MS | STRENGTH_3 | OFF_6_58US)
|
|
||||||
d.SendData(START_10MS | STRENGTH_3 | OFF_6_58US)
|
|
||||||
|
|
||||||
d.SendCommand(PFS)
|
|
||||||
d.SendData(FRAMES_1)
|
|
||||||
|
|
||||||
d.SendCommand(TSE)
|
|
||||||
d.SendData(TEMP_INTERNAL | OFFSET_0)
|
|
||||||
|
|
||||||
d.SendCommand(TCON)
|
|
||||||
d.SendData(0x22)
|
|
||||||
|
|
||||||
d.SendCommand(CDI)
|
|
||||||
d.SendData(0x4C) // 4C //5C
|
|
||||||
|
|
||||||
d.SendCommand(PLL)
|
|
||||||
d.SendData(HZ_100)
|
|
||||||
|
|
||||||
d.SendCommand(POF)
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset resets the device
|
|
||||||
func (d *Device) Reset() {
|
|
||||||
d.rst.Low()
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
d.rst.High()
|
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
}
|
|
||||||
|
|
||||||
// PowerOff power off the device
|
|
||||||
func (d *Device) PowerOff() {
|
|
||||||
d.SendCommand(POF)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendCommand sends a command to the display
|
|
||||||
func (d *Device) SendCommand(command uint8) {
|
|
||||||
d.sendDataCommand(true, command)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SendData sends a data byte to the display
|
|
||||||
func (d *Device) SendData(data uint8) {
|
|
||||||
d.sendDataCommand(false, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// sendDataCommand sends image data or a command to the screen
|
|
||||||
func (d *Device) sendDataCommand(isCommand bool, data uint8) {
|
|
||||||
if isCommand {
|
|
||||||
d.dc.Low()
|
|
||||||
} else {
|
|
||||||
d.dc.High()
|
|
||||||
}
|
|
||||||
d.cs.Low()
|
|
||||||
d.bus.Transfer(data)
|
|
||||||
d.cs.High()
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPixel modifies the internal buffer in a single pixel.
|
|
||||||
// The display have 2 colors: black and white
|
|
||||||
// We use RGBA(0,0,0, 255) as white (transparent)
|
|
||||||
// Anything else as black
|
|
||||||
func (d *Device) SetPixel(x int16, y int16, c color.RGBA) {
|
|
||||||
x, y = d.xy(x, y)
|
|
||||||
|
|
||||||
if x < 0 || x >= d.width || y < 0 || y >= d.height {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
byteIndex := x/8 + y*(d.width/8)
|
|
||||||
if c.R == 0 && c.G == 0 && c.B == 0 { // TRANSPARENT / WHITE
|
|
||||||
d.buffer[byteIndex] &^= 0x80 >> uint8(x%8)
|
|
||||||
} else { // WHITE / EMPTY
|
|
||||||
d.buffer[byteIndex] |= 0x80 >> uint8(x%8)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display sends the buffer to the screen.
|
|
||||||
func (d *Device) Display() error {
|
|
||||||
if d.blocking {
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
}
|
|
||||||
d.SendCommand(PON)
|
|
||||||
d.SendCommand(PTOU)
|
|
||||||
d.SendCommand(DTM2)
|
|
||||||
for i := uint32(0); i < d.bufferLength; i++ {
|
|
||||||
d.SendData(d.buffer[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
d.SendCommand(DSP)
|
|
||||||
d.SendCommand(DRF)
|
|
||||||
if d.blocking {
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
d.PowerOff()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// DisplayRect sends only an area of the buffer to the screen.
|
|
||||||
// The rectangle points need to be a multiple of 8 in the screen.
|
|
||||||
// They might not work as expected if the screen is rotated.
|
|
||||||
func (d *Device) DisplayRect(x int16, y int16, width int16, height int16) error {
|
|
||||||
if d.blocking {
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
}
|
|
||||||
|
|
||||||
x, y = d.xy(x, y)
|
|
||||||
if x < 0 || y < 0 || x >= d.width || y >= d.height || width < 0 || height < 0 {
|
|
||||||
return errors.New("wrong rectangle")
|
|
||||||
}
|
|
||||||
if d.rotation == ROTATION_90 {
|
|
||||||
width, height = height, width
|
|
||||||
x -= width
|
|
||||||
} else if d.rotation == ROTATION_180 {
|
|
||||||
x -= width - 1
|
|
||||||
y -= height - 1
|
|
||||||
} else if d.rotation == ROTATION_270 {
|
|
||||||
width, height = height, width
|
|
||||||
y -= height
|
|
||||||
}
|
|
||||||
x &= 0xF8
|
|
||||||
width &= 0xF8
|
|
||||||
width = x + width // reuse variables
|
|
||||||
if width >= d.width {
|
|
||||||
width = d.width
|
|
||||||
}
|
|
||||||
height = y + height
|
|
||||||
if height > d.height {
|
|
||||||
height = d.height
|
|
||||||
}
|
|
||||||
|
|
||||||
d.SendCommand(PON)
|
|
||||||
d.SendCommand(PTIN)
|
|
||||||
d.SendCommand(PTL)
|
|
||||||
|
|
||||||
d.SendData(uint8(x))
|
|
||||||
d.SendData(uint8(x+width-1) | 0x07)
|
|
||||||
d.SendData(uint8(y >> 8))
|
|
||||||
d.SendData(uint8(y))
|
|
||||||
d.SendData(uint8((y + height - 1) >> 8))
|
|
||||||
d.SendData(uint8(y + height - 1))
|
|
||||||
d.SendData(0x01)
|
|
||||||
|
|
||||||
d.SendCommand(DTM2)
|
|
||||||
x = x / 8
|
|
||||||
width = width / 8
|
|
||||||
for ; y < height; y++ {
|
|
||||||
for i := x; i < width; i++ {
|
|
||||||
d.SendData(d.buffer[i+y*(d.width/8)])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
d.SendCommand(DSP)
|
|
||||||
d.SendCommand(DRF)
|
|
||||||
|
|
||||||
if d.blocking {
|
|
||||||
d.WaitUntilIdle()
|
|
||||||
d.PowerOff()
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearDisplay erases the device SRAM
|
|
||||||
func (d *Device) ClearDisplay() {
|
|
||||||
d.ClearBuffer()
|
|
||||||
d.Display()
|
|
||||||
}
|
|
||||||
|
|
||||||
// WaitUntilIdle waits until the display is ready
|
|
||||||
func (d *Device) WaitUntilIdle() {
|
|
||||||
for !d.busy.Get() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsBusy returns the busy status of the display
|
|
||||||
func (d *Device) IsBusy() bool {
|
|
||||||
return d.busy.Get()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearBuffer sets the buffer to 0xFF (white)
|
|
||||||
func (d *Device) ClearBuffer() {
|
|
||||||
for i := uint32(0); i < d.bufferLength; i++ {
|
|
||||||
d.buffer[i] = 0x00
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Size returns the current size of the display.
|
|
||||||
func (d *Device) Size() (w, h int16) {
|
|
||||||
if d.rotation == ROTATION_90 || d.rotation == ROTATION_270 {
|
|
||||||
return d.height, d.width
|
|
||||||
}
|
|
||||||
return d.width, d.height
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetRotation changes the rotation (clock-wise) of the device
|
|
||||||
func (d *Device) SetRotation(rotation Rotation) {
|
|
||||||
d.rotation = rotation
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBlocking changes the blocking flag of the device
|
|
||||||
func (d *Device) SetBlocking(blocking bool) {
|
|
||||||
d.blocking = blocking
|
|
||||||
}
|
|
||||||
|
|
||||||
// xy chages the coordinates according to the rotation
|
|
||||||
func (d *Device) xy(x, y int16) (int16, int16) {
|
|
||||||
switch d.rotation {
|
|
||||||
case NO_ROTATION:
|
|
||||||
return x, y
|
|
||||||
case ROTATION_90:
|
|
||||||
return d.width - y - 1, x
|
|
||||||
case ROTATION_180:
|
|
||||||
return d.width - x - 1, d.height - y - 1
|
|
||||||
case ROTATION_270:
|
|
||||||
return y, d.height - x - 1
|
|
||||||
}
|
|
||||||
return x, y
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSpeed changes the refresh speed of the device (the display needs to re-configure)
|
|
||||||
func (d *Device) SetSpeed(speed Speed) {
|
|
||||||
d.Configure(Config{
|
|
||||||
Width: d.width,
|
|
||||||
Height: d.height,
|
|
||||||
Rotation: d.rotation,
|
|
||||||
Speed: speed,
|
|
||||||
Blocking: d.blocking,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invert sets the display' invert mode
|
|
||||||
func (d *Device) Invert(invert bool) {
|
|
||||||
if invert {
|
|
||||||
d.SendData(0x5C)
|
|
||||||
} else {
|
|
||||||
d.SendData(0x4C)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetLUT sets the look up tables for full or partial updates
|
|
||||||
func (d *Device) SetLUT(speed Speed) {
|
|
||||||
switch speed {
|
|
||||||
case MEDIUM:
|
|
||||||
var lut = [44]uint8{
|
|
||||||
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x00, 0x23, 0x23, 0x00, 0x00, 0x02,
|
|
||||||
0x00, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00,
|
|
||||||
}
|
|
||||||
d.SendCommand(LUT_VCOM)
|
|
||||||
for i := 0; i < 44; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
|
|
||||||
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
|
|
||||||
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
|
|
||||||
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x60, 0x23, 0x23, 0x00, 0x00, 0x02,
|
|
||||||
0x54, 0x16, 0x16, 0x0d, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
case FAST:
|
|
||||||
var lut = [44]uint8{
|
|
||||||
0x00, 0x04, 0x04, 0x07, 0x00, 0x01,
|
|
||||||
0x00, 0x0c, 0x0c, 0x00, 0x00, 0x02,
|
|
||||||
0x00, 0x04, 0x04, 0x07, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00,
|
|
||||||
}
|
|
||||||
d.SendCommand(LUT_VCOM)
|
|
||||||
for i := 0; i < 44; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x04, 0x04, 0x07, 0x00, 0x01,
|
|
||||||
0x60, 0x0c, 0x0c, 0x00, 0x00, 0x02,
|
|
||||||
0xa8, 0x04, 0x04, 0x07, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x04, 0x04, 0x07, 0x00, 0x01,
|
|
||||||
0x60, 0x0c, 0x0c, 0x00, 0x00, 0x02,
|
|
||||||
0xa8, 0x04, 0x04, 0x07, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x04, 0x04, 0x07, 0x00, 0x01,
|
|
||||||
0x60, 0x0c, 0x0c, 0x00, 0x00, 0x02,
|
|
||||||
0x54, 0x04, 0x04, 0x07, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x04, 0x04, 0x07, 0x00, 0x01,
|
|
||||||
0x60, 0x0c, 0x0c, 0x00, 0x00, 0x02,
|
|
||||||
0x54, 0x04, 0x04, 0x07, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
case TURBO:
|
|
||||||
var lut = [44]uint8{
|
|
||||||
0x00, 0x01, 0x01, 0x02, 0x00, 0x01,
|
|
||||||
0x00, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
||||||
0x00, 0x02, 0x02, 0x03, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00,
|
|
||||||
}
|
|
||||||
d.SendCommand(LUT_VCOM)
|
|
||||||
for i := 0; i < 44; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x01, 0x01, 0x02, 0x00, 0x01,
|
|
||||||
0x60, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
||||||
0xa8, 0x02, 0x02, 0x03, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x01, 0x01, 0x02, 0x00, 0x01,
|
|
||||||
0x60, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
||||||
0xa8, 0x02, 0x02, 0x03, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x01, 0x01, 0x02, 0x00, 0x01,
|
|
||||||
0x60, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
||||||
0x54, 0x02, 0x02, 0x03, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x01, 0x01, 0x02, 0x00, 0x01,
|
|
||||||
0x60, 0x02, 0x02, 0x00, 0x00, 0x02,
|
|
||||||
0x54, 0x02, 0x02, 0x03, 0x00, 0x02,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
var lut = [44]uint8{
|
|
||||||
0x00, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x00, 0x8c, 0x8c, 0x00, 0x00, 0x04,
|
|
||||||
0x00, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00,
|
|
||||||
}
|
|
||||||
d.SendCommand(LUT_VCOM)
|
|
||||||
for i := 0; i < 44; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x60, 0x8c, 0x8c, 0x00, 0x00, 0x04,
|
|
||||||
0xa8, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0x54, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x60, 0x8c, 0x8c, 0x00, 0x00, 0x04,
|
|
||||||
0xa8, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BW)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x60, 0x8c, 0x8c, 0x00, 0x00, 0x04,
|
|
||||||
0x54, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_WB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
lut = [44]uint8{
|
|
||||||
0xa8, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x60, 0x8c, 0x8c, 0x00, 0x00, 0x04,
|
|
||||||
0x54, 0x64, 0x64, 0x37, 0x00, 0x01,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
||||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
||||||
d.SendCommand(LUT_BB)
|
|
||||||
// do not send last two bytes
|
|
||||||
for i := 0; i < 42; i++ {
|
|
||||||
d.SendData(lut[i])
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -2,4 +2,4 @@ package drivers
|
|||||||
|
|
||||||
// Version returns a user-readable string showing the version of the drivers package for support purposes.
|
// Version returns a user-readable string showing the version of the drivers package for support purposes.
|
||||||
// Update this value before release of new version of software.
|
// Update this value before release of new version of software.
|
||||||
const Version = "0.21.0"
|
const Version = "0.20.0"
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"fmt" // used only in debug printouts and is optimized out when debugging is disabled
|
"fmt" // used only in debug printouts and is optimized out when debugging is disabled
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"machine"
|
"machine"
|
||||||
@@ -289,7 +288,6 @@ type Device struct {
|
|||||||
proto uint8
|
proto uint8
|
||||||
ip uint32
|
ip uint32
|
||||||
port uint16
|
port uint16
|
||||||
mu sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new Wifinina device.
|
// New returns a new Wifinina device.
|
||||||
@@ -365,9 +363,6 @@ func (d *Device) GetClientState(sock uint8) (uint8, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) SendData(buf []byte, sock uint8) (uint16, error) {
|
func (d *Device) SendData(buf []byte, sock uint8) (uint16, error) {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
if err := d.waitForChipSelect(); err != nil {
|
if err := d.waitForChipSelect(); err != nil {
|
||||||
d.spiChipDeselect()
|
d.spiChipDeselect()
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -381,9 +376,6 @@ func (d *Device) SendData(buf []byte, sock uint8) (uint16, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) CheckDataSent(sock uint8) (bool, error) {
|
func (d *Device) CheckDataSent(sock uint8) (bool, error) {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
var lastErr error
|
var lastErr error
|
||||||
for timeout := 0; timeout < 10; timeout++ {
|
for timeout := 0; timeout < 10; timeout++ {
|
||||||
sent, err := d.getUint8(d.reqUint8(CmdDataSentTCP, sock))
|
sent, err := d.getUint8(d.reqUint8(CmdDataSentTCP, sock))
|
||||||
@@ -399,9 +391,6 @@ func (d *Device) CheckDataSent(sock uint8) (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) GetDataBuf(sock uint8, buf []byte) (int, error) {
|
func (d *Device) GetDataBuf(sock uint8, buf []byte) (int, error) {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
if err := d.waitForChipSelect(); err != nil {
|
if err := d.waitForChipSelect(); err != nil {
|
||||||
d.spiChipDeselect()
|
d.spiChipDeselect()
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -422,9 +411,6 @@ func (d *Device) GetDataBuf(sock uint8, buf []byte) (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) StopClient(sock uint8) error {
|
func (d *Device) StopClient(sock uint8) error {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
if _debug {
|
if _debug {
|
||||||
println("[StopClient] called StopClient()\r")
|
println("[StopClient] called StopClient()\r")
|
||||||
}
|
}
|
||||||
@@ -433,9 +419,6 @@ func (d *Device) StopClient(sock uint8) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Device) StartServer(port uint16, sock uint8, mode uint8) error {
|
func (d *Device) StartServer(port uint16, sock uint8, mode uint8) error {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
if err := d.waitForChipSelect(); err != nil {
|
if err := d.waitForChipSelect(); err != nil {
|
||||||
d.spiChipDeselect()
|
d.spiChipDeselect()
|
||||||
return err
|
return err
|
||||||
@@ -452,9 +435,6 @@ func (d *Device) StartServer(port uint16, sock uint8, mode uint8) error {
|
|||||||
|
|
||||||
// InsertDataBuf adds data to the buffer used for sending UDP data
|
// InsertDataBuf adds data to the buffer used for sending UDP data
|
||||||
func (d *Device) InsertDataBuf(buf []byte, sock uint8) (bool, error) {
|
func (d *Device) InsertDataBuf(buf []byte, sock uint8) (bool, error) {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
if err := d.waitForChipSelect(); err != nil {
|
if err := d.waitForChipSelect(); err != nil {
|
||||||
d.spiChipDeselect()
|
d.spiChipDeselect()
|
||||||
return false, err
|
return false, err
|
||||||
@@ -470,9 +450,6 @@ func (d *Device) InsertDataBuf(buf []byte, sock uint8) (bool, error) {
|
|||||||
|
|
||||||
// SendUDPData sends the data previously added to the UDP buffer
|
// SendUDPData sends the data previously added to the UDP buffer
|
||||||
func (d *Device) SendUDPData(sock uint8) (bool, error) {
|
func (d *Device) SendUDPData(sock uint8) (bool, error) {
|
||||||
d.mu.Lock()
|
|
||||||
defer d.mu.Unlock()
|
|
||||||
|
|
||||||
if err := d.waitForChipSelect(); err != nil {
|
if err := d.waitForChipSelect(); err != nil {
|
||||||
d.spiChipDeselect()
|
d.spiChipDeselect()
|
||||||
return false, err
|
return false, err
|
||||||
|
|||||||
+31
-12
@@ -18,16 +18,8 @@ import (
|
|||||||
// the new assembly implementation - no fiddly timings to calculate and no nops
|
// the new assembly implementation - no fiddly timings to calculate and no nops
|
||||||
// to count!
|
// to count!
|
||||||
//
|
//
|
||||||
// Right now this is specific to Cortex-M chips and assume the following things:
|
// Using templates, this code targets various microcontroller architectures: ARM
|
||||||
// - Arithmetic operations (shift, add, sub) take up 1 clock cycle.
|
// (Cortex-M), RISC-V, and Xtensa.
|
||||||
// - The nop instruction also takes up 1 clock cycle.
|
|
||||||
// - Store instructions (to the GPIO pins) take up 2 clock cycles.
|
|
||||||
// - Branch instructions can take up 1 to 3 clock cycles. On the Cortex-M0, this
|
|
||||||
// depends on whether the branch is taken or not. On the M4, the documentation
|
|
||||||
// is less clear but it appears the instruction is still 1 to 3 cycles
|
|
||||||
// (possibly including some branch prediction).
|
|
||||||
// It is certainly possible to extend this to other architectures, such as AVR
|
|
||||||
// and RISC-V if needed.
|
|
||||||
//
|
//
|
||||||
// Here are two important resources. For the timings:
|
// Here are two important resources. For the timings:
|
||||||
// https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
|
// https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
|
||||||
@@ -104,6 +96,34 @@ var architectures = map[string]architectureImpl{
|
|||||||
@DELAY3
|
@DELAY3
|
||||||
addi %[i], %[i], -1 // [1]
|
addi %[i], %[i], -1 // [1]
|
||||||
bnez %[i], 1b // [1/3] send_bit
|
bnez %[i], 1b // [1/3] send_bit
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
"xtensa": {
|
||||||
|
// ESP8266 and ESP32
|
||||||
|
// Because I do not know the exact instruction timings, I'm going to
|
||||||
|
// assume that every instruction executes in one cycle. Branches and
|
||||||
|
// load/stores will probably be slower than that, but as long as all
|
||||||
|
// timings are only increased a little bit this should not be a problem.
|
||||||
|
buildTag: "xtensa",
|
||||||
|
minBaseCyclesT0H: 1 + 1 + 1, // shift + branch (not taken) + store
|
||||||
|
maxBaseCyclesT0H: 1 + 1 + 1, // shift + branch (not taken) + store
|
||||||
|
minBaseCyclesT1H: 1 + 1 + 1, // shift + branch (taken) + store
|
||||||
|
maxBaseCyclesT1H: 1 + 1 + 1, // shift + branch (taken) + store
|
||||||
|
minBaseCyclesTLD: 1 + 1 + 1, // subtraction + branch + store (in next cycle)
|
||||||
|
valueTemplate: "(uint32_t)c",
|
||||||
|
template: `
|
||||||
|
1: // send_bit
|
||||||
|
s32i %[maskSet], %[portSet] // [1] T0H and T1H start here
|
||||||
|
@DELAY1
|
||||||
|
slli %[value], %[value], 1 // [1] shift value to the left by 1
|
||||||
|
bbsi %[value], 8, 2f // [1] branch to skip_store if bit 8 is set
|
||||||
|
s32i %[maskClear], %[portClear] // [1] T0H -> T0L transition
|
||||||
|
2: // skip_store
|
||||||
|
@DELAY2
|
||||||
|
s32i %[maskClear], %[portClear] // [1] T1H -> T1L transition
|
||||||
|
@DELAY3
|
||||||
|
addi %[i], %[i], -1 // [1]
|
||||||
|
bnez %[i], 1b // [1] send_bit, T1H and T1L end here
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -252,7 +272,7 @@ func writeGoWrapper(f *os.File, arch string, megahertz int) error {
|
|||||||
fmt.Fprintf(buf, " portClear, maskClear := d.Pin.PortMaskClear()\n")
|
fmt.Fprintf(buf, " portClear, maskClear := d.Pin.PortMaskClear()\n")
|
||||||
fmt.Fprintf(buf, "\n")
|
fmt.Fprintf(buf, "\n")
|
||||||
fmt.Fprintf(buf, " mask := interrupt.Disable()\n")
|
fmt.Fprintf(buf, " mask := interrupt.Disable()\n")
|
||||||
fmt.Fprintf(buf, " C.ws2812_writeByte%d(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)\n", megahertz)
|
fmt.Fprintf(buf, " C.ws2812_writeByte%d(C.char(c), portSet, portClear, maskSet, maskClear)\n", megahertz)
|
||||||
buf.WriteString(`
|
buf.WriteString(`
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
@@ -293,7 +313,6 @@ package ws2812
|
|||||||
// gen-ws2812.go and run "go generate".
|
// gen-ws2812.go and run "go generate".
|
||||||
|
|
||||||
import "runtime/interrupt"
|
import "runtime/interrupt"
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package ws2812
|
|||||||
// gen-ws2812.go and run "go generate".
|
// gen-ws2812.go and run "go generate".
|
||||||
|
|
||||||
import "runtime/interrupt"
|
import "runtime/interrupt"
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -637,301 +636,6 @@ void ws2812_writeByte120(char c, uint32_t *portSet, uint32_t *portClear, uint32_
|
|||||||
[portClear]"m"(*portClear));
|
[portClear]"m"(*portClear));
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((always_inline))
|
|
||||||
void ws2812_writeByte125(char c, uint32_t *portSet, uint32_t *portClear, uint32_t maskSet, uint32_t maskClear) {
|
|
||||||
// Timings:
|
|
||||||
// T0H: 44 - 46 cycles or 352.0ns - 368.0ns
|
|
||||||
// T1H: 132 - 134 cycles or 1056.0ns - 1072.0ns
|
|
||||||
// TLD: 144 - cycles or 1152.0ns -
|
|
||||||
uint32_t value = (uint32_t)c << 24;
|
|
||||||
char i = 8;
|
|
||||||
__asm__ __volatile__(
|
|
||||||
"1: @ send_bit\n"
|
|
||||||
"\t str %[maskSet], %[portSet] @ [2] T0H and T0L start here\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t lsls %[value], #1 @ [1]\n"
|
|
||||||
"\t bcs.n 2f @ [1/3] skip_store\n"
|
|
||||||
"\t str %[maskClear], %[portClear] @ [2] T0H -> T0L transition\n"
|
|
||||||
"\t2: @ skip_store\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t str %[maskClear], %[portClear] @ [2] T1H -> T1L transition\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t nop\n"
|
|
||||||
"\t subs %[i], #1 @ [1]\n"
|
|
||||||
"\t beq.n 3f @ [1/3] end\n"
|
|
||||||
"\t b 1b @ [1/3] send_bit\n"
|
|
||||||
"\t3: @ end\n"
|
|
||||||
: [value]"+r"(value),
|
|
||||||
[i]"+r"(i)
|
|
||||||
: [maskSet]"r"(maskSet),
|
|
||||||
[portSet]"m"(*portSet),
|
|
||||||
[maskClear]"r"(maskClear),
|
|
||||||
[portClear]"m"(*portClear));
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline))
|
__attribute__((always_inline))
|
||||||
void ws2812_writeByte168(char c, uint32_t *portSet, uint32_t *portClear, uint32_t maskSet, uint32_t maskClear) {
|
void ws2812_writeByte168(char c, uint32_t *portSet, uint32_t *portClear, uint32_t maskSet, uint32_t maskClear) {
|
||||||
// Timings:
|
// Timings:
|
||||||
@@ -1329,7 +1033,7 @@ func (d Device) writeByte16(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte16(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte16(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
@@ -1339,7 +1043,7 @@ func (d Device) writeByte48(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte48(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte48(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
@@ -1349,7 +1053,7 @@ func (d Device) writeByte64(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte64(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte64(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
@@ -1359,17 +1063,7 @@ func (d Device) writeByte120(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte120(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte120(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Device) writeByte125(c byte) {
|
|
||||||
portSet, maskSet := d.Pin.PortMaskSet()
|
|
||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
|
||||||
C.ws2812_writeByte125(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
@@ -1379,7 +1073,7 @@ func (d Device) writeByte168(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte168(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte168(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ package ws2812
|
|||||||
// gen-ws2812.go and run "go generate".
|
// gen-ws2812.go and run "go generate".
|
||||||
|
|
||||||
import "runtime/interrupt"
|
import "runtime/interrupt"
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -1115,7 +1114,7 @@ func (d Device) writeByte160(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte160(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte160(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
@@ -1125,7 +1124,7 @@ func (d Device) writeByte320(c byte) {
|
|||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
mask := interrupt.Disable()
|
mask := interrupt.Disable()
|
||||||
C.ws2812_writeByte320(C.char(c), (*uint32)(unsafe.Pointer(portSet)), (*uint32)(unsafe.Pointer(portClear)), maskSet, maskClear)
|
C.ws2812_writeByte320(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
interrupt.Restore(mask)
|
interrupt.Restore(mask)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,602 @@
|
|||||||
|
//go:build xtensa
|
||||||
|
// +build xtensa
|
||||||
|
|
||||||
|
package ws2812
|
||||||
|
|
||||||
|
// Warning: autogenerated file. Instead of modifying this file, change
|
||||||
|
// gen-ws2812.go and run "go generate".
|
||||||
|
|
||||||
|
import "runtime/interrupt"
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
__attribute__((always_inline))
|
||||||
|
void ws2812_writeByte80(char c, uint32_t *portSet, uint32_t *portClear, uint32_t maskSet, uint32_t maskClear) {
|
||||||
|
// Timings:
|
||||||
|
// T0H: 28 - 28 cycles or 350.0ns - 350.0ns
|
||||||
|
// T1H: 84 - 84 cycles or 1050.0ns - 1050.0ns
|
||||||
|
// TLD: 92 - cycles or 1150.0ns -
|
||||||
|
uint32_t value = (uint32_t)c;
|
||||||
|
char i = 8;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"1: // send_bit\n"
|
||||||
|
"\t s32i %[maskSet], %[portSet] // [1] T0H and T1H start here\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t slli %[value], %[value], 1 // [1] shift value to the left by 1\n"
|
||||||
|
"\t bbsi %[value], 8, 2f // [1] branch to skip_store if bit 8 is set\n"
|
||||||
|
"\t s32i %[maskClear], %[portClear] // [1] T0H -> T0L transition\n"
|
||||||
|
"\t2: // skip_store\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t s32i %[maskClear], %[portClear] // [1] T1H -> T1L transition\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t addi %[i], %[i], -1 // [1]\n"
|
||||||
|
"\t bnez %[i], 1b // [1] send_bit, T1H and T1L end here\n"
|
||||||
|
: [value]"+r"(value),
|
||||||
|
[i]"+r"(i)
|
||||||
|
: [maskSet]"r"(maskSet),
|
||||||
|
[portSet]"m"(*portSet),
|
||||||
|
[maskClear]"r"(maskClear),
|
||||||
|
[portClear]"m"(*portClear));
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((always_inline))
|
||||||
|
void ws2812_writeByte160(char c, uint32_t *portSet, uint32_t *portClear, uint32_t maskSet, uint32_t maskClear) {
|
||||||
|
// Timings:
|
||||||
|
// T0H: 56 - 56 cycles or 350.0ns - 350.0ns
|
||||||
|
// T1H: 168 - 168 cycles or 1050.0ns - 1050.0ns
|
||||||
|
// TLD: 184 - cycles or 1150.0ns -
|
||||||
|
uint32_t value = (uint32_t)c;
|
||||||
|
char i = 8;
|
||||||
|
__asm__ __volatile__(
|
||||||
|
"1: // send_bit\n"
|
||||||
|
"\t s32i %[maskSet], %[portSet] // [1] T0H and T1H start here\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t slli %[value], %[value], 1 // [1] shift value to the left by 1\n"
|
||||||
|
"\t bbsi %[value], 8, 2f // [1] branch to skip_store if bit 8 is set\n"
|
||||||
|
"\t s32i %[maskClear], %[portClear] // [1] T0H -> T0L transition\n"
|
||||||
|
"\t2: // skip_store\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t s32i %[maskClear], %[portClear] // [1] T1H -> T1L transition\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t nop\n"
|
||||||
|
"\t addi %[i], %[i], -1 // [1]\n"
|
||||||
|
"\t bnez %[i], 1b // [1] send_bit, T1H and T1L end here\n"
|
||||||
|
: [value]"+r"(value),
|
||||||
|
[i]"+r"(i)
|
||||||
|
: [maskSet]"r"(maskSet),
|
||||||
|
[portSet]"m"(*portSet),
|
||||||
|
[maskClear]"r"(maskClear),
|
||||||
|
[portClear]"m"(*portClear));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
func (d Device) writeByte80(c byte) {
|
||||||
|
portSet, maskSet := d.Pin.PortMaskSet()
|
||||||
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
|
mask := interrupt.Disable()
|
||||||
|
C.ws2812_writeByte80(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
|
interrupt.Restore(mask)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d Device) writeByte160(c byte) {
|
||||||
|
portSet, maskSet := d.Pin.PortMaskSet()
|
||||||
|
portClear, maskClear := d.Pin.PortMaskClear()
|
||||||
|
|
||||||
|
mask := interrupt.Disable()
|
||||||
|
C.ws2812_writeByte160(C.char(c), portSet, portClear, maskSet, maskClear)
|
||||||
|
|
||||||
|
interrupt.Restore(mask)
|
||||||
|
}
|
||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
// Package ws2812 implements a driver for WS2812 and SK6812 RGB LED strips.
|
// Package ws2812 implements a driver for WS2812 and SK6812 RGB LED strips.
|
||||||
package ws2812 // import "tinygo.org/x/drivers/ws2812"
|
package ws2812 // import "tinygo.org/x/drivers/ws2812"
|
||||||
|
|
||||||
//go:generate go run gen-ws2812.go -arch=cortexm 16 48 64 120 125 168
|
//go:generate go run gen-ws2812.go -arch=cortexm 16 48 64 120 168
|
||||||
//go:generate go run gen-ws2812.go -arch=tinygoriscv 160 320
|
//go:generate go run gen-ws2812.go -arch=tinygoriscv 160 320
|
||||||
|
//go:generate go run gen-ws2812.go -arch=xtensa 80 160
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|||||||
@@ -29,9 +29,6 @@ func (d Device) WriteByte(c byte) error {
|
|||||||
case 120_000_000: // 120MHz
|
case 120_000_000: // 120MHz
|
||||||
d.writeByte120(c)
|
d.writeByte120(c)
|
||||||
return nil
|
return nil
|
||||||
case 125_000_000: // 125 MHz e.g. rp2040
|
|
||||||
d.writeByte125(c)
|
|
||||||
return nil
|
|
||||||
case 168_000_000: // 168MHz, e.g. stm32f405
|
case 168_000_000: // 168MHz, e.g. stm32f405
|
||||||
d.writeByte168(c)
|
d.writeByte168(c)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
+2
-330
@@ -4,346 +4,18 @@
|
|||||||
package ws2812
|
package ws2812
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"device"
|
|
||||||
"machine"
|
"machine"
|
||||||
"runtime/interrupt"
|
|
||||||
"unsafe"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d Device) WriteByte(c byte) error {
|
func (d Device) WriteByte(c byte) error {
|
||||||
portSet, maskSet := d.Pin.PortMaskSet()
|
|
||||||
portClear, maskClear := d.Pin.PortMaskClear()
|
|
||||||
mask := interrupt.Disable()
|
|
||||||
|
|
||||||
switch machine.CPUFrequency() {
|
switch machine.CPUFrequency() {
|
||||||
case 160e6: // 160MHz
|
case 160e6: // 160MHz
|
||||||
// See:
|
d.writeByte160(c)
|
||||||
// https://wp.josh.com/2014/05/13/ws2812-neopixels-are-not-so-finicky-once-you-get-to-know-them/
|
|
||||||
// Because I do not know the exact instruction timings, I'm going to
|
|
||||||
// assume that every instruction executes in one cycle. Branches and
|
|
||||||
// load/stores will probably be slower than that, but as long as all
|
|
||||||
// timings are only increased a little bit this should not be a problem
|
|
||||||
// (see above post).
|
|
||||||
// T0H: 40 cycles or 333.3ns
|
|
||||||
// T0L: 131 cycles or 1091.7ns
|
|
||||||
// +: 171 cycles or 1425.0ns
|
|
||||||
// T1H: 95 cycles or 791.7ns
|
|
||||||
// T1L: 75 cycles or 625.0ns
|
|
||||||
// +: 170 cycles or 1416.7ns
|
|
||||||
// Some documentation:
|
|
||||||
// http://cholla.mmto.org/esp8266/xtensa.html
|
|
||||||
// https://0x04.net/~mwk/doc/xtensa.pdf
|
|
||||||
device.AsmFull(`
|
|
||||||
1: // send_bit
|
|
||||||
s32i {maskSet}, {portSet}, 0 // [1] T0H and T1H start here
|
|
||||||
nop // [37]
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
slli {value}, {value}, 1 // [1] shift {value} to the left by 1
|
|
||||||
bbsi {value}, 8, 2f // [1] branch to skip_store if bit 8 is set
|
|
||||||
s32i {maskClear}, {portClear}, 0 // [1] T0H -> T0L transition
|
|
||||||
2: // skip_store
|
|
||||||
nop // [55]
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
s32i {maskClear}, {portClear}, 0 // [1] T1H -> T1L transition
|
|
||||||
nop // [72]
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
addi {i}, {i}, -1 // [1]
|
|
||||||
bnez {i}, 1b // [1] send_bit, T1H and T1L end here
|
|
||||||
|
|
||||||
// Restore original values after modifying them in the inline
|
|
||||||
// assembly. Not doing that would result in undefined behavior as
|
|
||||||
// the compiler doesn't know we're modifying these values.
|
|
||||||
movi.n {i}, 8
|
|
||||||
slli {value}, {value}, 8
|
|
||||||
`, map[string]interface{}{
|
|
||||||
// Note: casting pointers to uintptr here because of what might be
|
|
||||||
// an Xtensa backend bug with inline assembly.
|
|
||||||
"value": uint32(c),
|
|
||||||
"i": 8,
|
|
||||||
"maskSet": maskSet,
|
|
||||||
"portSet": uintptr(unsafe.Pointer(portSet)),
|
|
||||||
"maskClear": maskClear,
|
|
||||||
"portClear": uintptr(unsafe.Pointer(portClear)),
|
|
||||||
})
|
|
||||||
interrupt.Restore(mask)
|
|
||||||
return nil
|
return nil
|
||||||
case 80e6: // 80MHz
|
case 80e6: // 80MHz
|
||||||
// See docs for 160MHz.
|
d.writeByte80(c)
|
||||||
// T0H: 21 cycles or 262.5ns
|
|
||||||
// T0L: 67 cycles or 837.5ns
|
|
||||||
// +: 88 cycles or 1100.0ns
|
|
||||||
// T1H: 47 cycles or 587.5ns
|
|
||||||
// T1L: 39 cycles or 487.5ns
|
|
||||||
// +: 86 cycles or 1075.0ns
|
|
||||||
device.AsmFull(`
|
|
||||||
1: // send_bit
|
|
||||||
s32i {maskSet}, {portSet}, 0 // [1] T0H and T1H start here
|
|
||||||
nop // [18]
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
slli {value}, {value}, 1 // [1] shift {value} to the left by 1
|
|
||||||
bbsi {value}, 8, 2f // [1] branch to skip_store if bit 8 is set
|
|
||||||
s32i {maskClear}, {portClear}, 0 // [1] T0H -> T0L transition
|
|
||||||
2: // skip_store
|
|
||||||
nop // [27]
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
s32i {maskClear}, {portClear}, 0 // [1] T1H -> T1L transition
|
|
||||||
nop // [36]
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
nop
|
|
||||||
addi {i}, {i}, -1 // [1]
|
|
||||||
bnez {i}, 1b // [1] send_bit, T1H and T1L end here
|
|
||||||
|
|
||||||
// Restore original values after modifying them in the inline
|
|
||||||
// assembly. Not doing that would result in undefined behavior as
|
|
||||||
// the compiler doesn't know we're modifying these values.
|
|
||||||
movi.n {i}, 8
|
|
||||||
slli {value}, {value}, 8
|
|
||||||
`, map[string]interface{}{
|
|
||||||
// Note: casting pointers to uintptr here because of what might be
|
|
||||||
// an Xtensa backend bug with inline assembly.
|
|
||||||
"value": uint32(c),
|
|
||||||
"i": 8,
|
|
||||||
"maskSet": maskSet,
|
|
||||||
"portSet": uintptr(unsafe.Pointer(portSet)),
|
|
||||||
"maskClear": maskClear,
|
|
||||||
"portClear": uintptr(unsafe.Pointer(portClear)),
|
|
||||||
})
|
|
||||||
interrupt.Restore(mask)
|
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
interrupt.Restore(mask)
|
|
||||||
return errUnknownClockSpeed
|
return errUnknownClockSpeed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user