Compare commits

...

9 Commits

Author SHA1 Message Date
deadprogram 38c606d813 refactor: add display.Pin interface and use it everywhere that is easy to do so
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-07-06 11:41:03 +02:00
JP Hastings-Spital d02d21ecea feat: allow gps init with address
Adafruit's Mini GPS PA1010D Module works with this device driver, but requires 0x10 as the address, rather than 0x42.

This change allows the device to be initialised with whatever i2c address is needed, while maintaining backward compatibility.

Adds new constants to allow easy configuration of both the ublox device and the PA1010D.
2025-06-30 14:00:55 +02:00
Yurii Soldak 805e2a02f8 lsm6ds3tr: avoid unnecessary heap allocations (#766)
* lsm6ds3tr: avoid unnecessary heap allocations
* lsm6ds3tr: use helper functions, for readability
* lsm6ds3tr: return slice of the internal buffer on readBytes
2025-06-25 10:03:41 +02:00
deadprogram c4ff8242a7 all: updates for drivers release v0.32.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2025-06-15 22:36:34 +02:00
soypat 82c41dbf14 add driver design pointer to CONTRIBUTING.md 2025-05-28 11:03:09 +02:00
Hikmatulloh Hari Mukti c4168864fd bmp280: remove alloc on read sensor data 2025-05-28 10:29:08 +02:00
Leon Matthews dbc9022f6a ws2812: add 200MHz support for the Cortex-M0/rp2040 2025-05-20 13:09:35 +02:00
Mateusz Nowak d41bc0b85f fix: remove time.Sleep from SSD1306 SPI transfer code 2025-05-20 12:43:13 +02:00
Craig Swank e7f90166ad tmc2209 bug fixes (#755)
* Make write buffer big enough for crc
* crc according to datasheet
* fix build
* a correct crc func already exists
2025-05-20 12:27:30 +02:00
40 changed files with 731 additions and 291 deletions
+27
View File
@@ -1,3 +1,30 @@
0.32.0
---
- **enhancements**
- **bmp280**
- remove alloc on read sensor data
- **ws2812**
- add 200MHz support for the Cortex-M0/rp2040
- **bugfixes**
- **ssd1306**
- remove time.Sleep from SSD1306 SPI transfer code
- **tmc2209**
- tmc2209 bug fixes (#755)
- **docs**
- **contributing**
- add driver design pointer to CONTRIBUTING.md
0.31.0
---
---
- **enhancements**
- **spi**
- update all SPI usage to use either *machine.SPI or drivers.SPI
0.30.0 0.30.0
--- ---
- **new devices** - **new devices**
+3
View File
@@ -8,6 +8,9 @@ We would like your help to make this project better, so we appreciate any contri
We'd love to get your feedback on getting started with TinyGo. Run into any difficulty, confusion, or anything else? You are not alone. We want to know about your experience, so we can help the next people. Please open a Github issue with your questions, or you can also get in touch directly with us on our Slack channel at [https://gophers.slack.com/messages/CDJD3SUP6](https://gophers.slack.com/messages/CDJD3SUP6). We'd love to get your feedback on getting started with TinyGo. Run into any difficulty, confusion, or anything else? You are not alone. We want to know about your experience, so we can help the next people. Please open a Github issue with your questions, or you can also get in touch directly with us on our Slack channel at [https://gophers.slack.com/messages/CDJD3SUP6](https://gophers.slack.com/messages/CDJD3SUP6).
### Driver design
Before porting or writing a driver from scratch please read **[Driver Design for TinyGo](https://tinygo.org/docs/guides/driver-design)**.
### One of the TinyGo drivers is not working as you expect ### One of the TinyGo drivers is not working as you expect
Please open a Github issue with your problem, and we will be happy to assist. Please open a Github issue with your problem, and we will be happy to assist.
+1 -2
View File
@@ -5,7 +5,6 @@ package apa102 // import "tinygo.org/x/drivers/apa102"
import ( import (
"image/color" "image/color"
"machine"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
) )
@@ -37,7 +36,7 @@ func New(b drivers.SPI) *Device {
// NewSoftwareSPI returns a new APA102 driver that will use a software based // NewSoftwareSPI returns a new APA102 driver that will use a software based
// implementation of the SPI protocol. // implementation of the SPI protocol.
func NewSoftwareSPI(sckPin, sdoPin machine.Pin, delay uint32) *Device { func NewSoftwareSPI(sckPin, sdoPin drivers.Pin, delay uint32) *Device {
return New(&bbSPI{SCK: sckPin, SDO: sdoPin, Delay: delay}) return New(&bbSPI{SCK: sckPin, SDO: sdoPin, Delay: delay})
} }
+7 -6
View File
@@ -1,6 +1,8 @@
package apa102 package apa102
import "machine" import (
"tinygo.org/x/drivers"
)
// bbSPI is a dumb bit-bang implementation of SPI protocol that is hardcoded // bbSPI is a dumb bit-bang implementation of SPI protocol that is hardcoded
// to mode 0 and ignores trying to receive data. Just enough for the APA102. // to mode 0 and ignores trying to receive data. Just enough for the APA102.
@@ -8,15 +10,14 @@ import "machine"
// most purposes other than the APA102 package. It might be desirable to make // most purposes other than the APA102 package. It might be desirable to make
// this more generic and include it in the TinyGo "machine" package instead. // this more generic and include it in the TinyGo "machine" package instead.
type bbSPI struct { type bbSPI struct {
SCK machine.Pin SCK drivers.Pin
SDO machine.Pin SDO drivers.Pin
Delay uint32 Delay uint32
} }
// Configure sets up the SCK and SDO pins as outputs and sets them low // Configure sets the SCK and SDO pins to low.
// Note that the SCK and SDO pins must already be configured as outputs.
func (s *bbSPI) Configure() { func (s *bbSPI) Configure() {
s.SCK.Configure(machine.PinConfig{Mode: machine.PinOutput})
s.SDO.Configure(machine.PinConfig{Mode: machine.PinOutput})
s.SCK.Low() s.SCK.Low()
s.SDO.Low() s.SDO.Low()
if s.Delay == 0 { if s.Delay == 0 {
+4 -7
View File
@@ -1,7 +1,6 @@
package bmi160 package bmi160
import ( import (
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -11,7 +10,7 @@ import (
// also an I2C interface, but it is not yet supported. // also an I2C interface, but it is not yet supported.
type DeviceSPI struct { type DeviceSPI struct {
// Chip select pin // Chip select pin
CSB machine.Pin CSB drivers.Pin
buf [7]byte buf [7]byte
@@ -22,18 +21,16 @@ type DeviceSPI struct {
// NewSPI returns a new device driver. The pin and SPI interface are not // NewSPI returns a new device driver. The pin and SPI interface are not
// touched, provide a fully configured SPI object and call Configure to start // touched, provide a fully configured SPI object and call Configure to start
// using this device. // using this device.
func NewSPI(csb machine.Pin, spi drivers.SPI) *DeviceSPI { func NewSPI(csb drivers.Pin, spi drivers.SPI) *DeviceSPI {
return &DeviceSPI{ return &DeviceSPI{
CSB: csb, // chip select CSB: csb, // chip select
Bus: spi, Bus: spi,
} }
} }
// Configure configures the BMI160 for use. It configures the CSB pin and // Configure configures the BMI160 for use. The CSB pin anf the SPI interface
// configures the BMI160, but it does not configure the SPI interface (it is // should be configured already. This function configures the BMI160 only.
// assumed to be up and running).
func (d *DeviceSPI) Configure() error { func (d *DeviceSPI) Configure() error {
d.CSB.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.CSB.High() d.CSB.High()
// The datasheet recommends doing a register read from address 0x7F to get // The datasheet recommends doing a register read from address 0x7F to get
+7 -8
View File
@@ -23,6 +23,7 @@ type Filter uint
type Device struct { type Device struct {
bus drivers.I2C bus drivers.I2C
Address uint16 Address uint16
buf [6]byte
cali calibrationCoefficients cali calibrationCoefficients
Temperature Oversampling Temperature Oversampling
Pressure Oversampling Pressure Oversampling
@@ -134,8 +135,8 @@ func (d *Device) PrintCali() {
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000). // ReadTemperature returns the temperature in celsius milli degrees (°C/1000).
func (d *Device) ReadTemperature() (temperature int32, err error) { func (d *Device) ReadTemperature() (temperature int32, err error) {
data, err := d.readData(REG_TEMP, 3) data := d.buf[:3]
if err != nil { if err = d.readData(REG_TEMP, data); err != nil {
return return
} }
@@ -158,8 +159,8 @@ func (d *Device) ReadTemperature() (temperature int32, err error) {
// ReadPressure returns the pressure in milli pascals (mPa). // ReadPressure returns the pressure in milli pascals (mPa).
func (d *Device) ReadPressure() (pressure int32, err error) { func (d *Device) ReadPressure() (pressure int32, err error) {
// First 3 bytes are Pressure, last 3 bytes are Temperature // First 3 bytes are Pressure, last 3 bytes are Temperature
data, err := d.readData(REG_PRES, 6) data := d.buf[:6]
if err != nil { if err = d.readData(REG_PRES, data); err != nil {
return return
} }
@@ -203,7 +204,7 @@ func (d *Device) ReadPressure() (pressure int32, err error) {
} }
// readData reads n number of bytes of the specified register // readData reads n number of bytes of the specified register
func (d *Device) readData(register int, n int) ([]byte, error) { func (d *Device) readData(register int, data []byte) error {
// If not in normal mode, set the mode to FORCED mode, to prevent incorrect measurements // If not in normal mode, set the mode to FORCED mode, to prevent incorrect measurements
// After the measurement in FORCED mode, the sensor will return to SLEEP mode // After the measurement in FORCED mode, the sensor will return to SLEEP mode
if d.Mode != MODE_NORMAL { if d.Mode != MODE_NORMAL {
@@ -218,9 +219,7 @@ func (d *Device) readData(register int, n int) ([]byte, error) {
} }
// Read the requested register // Read the requested register
data := make([]byte, n) return legacy.ReadRegister(d.bus, uint8(d.Address), uint8(register), data[:])
err := legacy.ReadRegister(d.bus, uint8(d.Address), uint8(register), data[:])
return data, err
} }
// convert3Bytes converts three bytes to int32 // convert3Bytes converts three bytes to int32
+4 -4
View File
@@ -2,20 +2,20 @@
package buzzer // import "tinygo.org/x/drivers/buzzer" package buzzer // import "tinygo.org/x/drivers/buzzer"
import ( import (
"machine"
"time" "time"
"tinygo.org/x/drivers"
) )
// Device wraps a GPIO connection to a buzzer. // Device wraps a GPIO connection to a buzzer.
type Device struct { type Device struct {
pin machine.Pin pin drivers.Pin
High bool High bool
BPM float64 BPM float64
} }
// New returns a new buzzer driver given which pin to use // New returns a new buzzer driver given which pin to use
func New(pin machine.Pin) Device { func New(pin drivers.Pin) Device {
return Device{ return Device{
pin: pin, pin: pin,
High: false, High: false,
+8 -9
View File
@@ -3,8 +3,9 @@ package easystepper // import "tinygo.org/x/drivers/easystepper"
import ( import (
"errors" "errors"
"machine"
"time" "time"
"tinygo.org/x/drivers"
) )
// StepMode determines the coil sequence used to perform a single step // StepMode determines the coil sequence used to perform a single step
@@ -33,7 +34,7 @@ func (sm StepMode) stepCount() uint {
// DeviceConfig contains the configuration data for a single easystepper driver // DeviceConfig contains the configuration data for a single easystepper driver
type DeviceConfig struct { type DeviceConfig struct {
// Pin1 ... Pin4 determines the pins to configure and use for the device // Pin1 ... Pin4 determines the pins to configure and use for the device
Pin1, Pin2, Pin3, Pin4 machine.Pin Pin1, Pin2, Pin3, Pin4 drivers.Pin
// StepCount is the number of steps required to perform a full revolution of the stepper motor // StepCount is the number of steps required to perform a full revolution of the stepper motor
StepCount uint StepCount uint
// RPM determines the speed of the stepper motor in 'Revolutions per Minute' // RPM determines the speed of the stepper motor in 'Revolutions per Minute'
@@ -46,12 +47,12 @@ type DeviceConfig struct {
type DualDeviceConfig struct { type DualDeviceConfig struct {
DeviceConfig DeviceConfig
// Pin5 ... Pin8 determines the pins to configure and use for the second device // Pin5 ... Pin8 determines the pins to configure and use for the second device
Pin5, Pin6, Pin7, Pin8 machine.Pin Pin5, Pin6, Pin7, Pin8 drivers.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]drivers.Pin
stepDelay time.Duration stepDelay time.Duration
stepNumber uint8 stepNumber uint8
stepMode StepMode stepMode StepMode
@@ -68,17 +69,15 @@ func New(config DeviceConfig) (*Device, error) {
return nil, errors.New("config.StepCount and config.RPM must be > 0") return nil, errors.New("config.StepCount and config.RPM must be > 0")
} }
return &Device{ return &Device{
pins: [4]machine.Pin{config.Pin1, config.Pin2, config.Pin3, config.Pin4}, pins: [4]drivers.Pin{config.Pin1, config.Pin2, config.Pin3, config.Pin4},
stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)), stepDelay: time.Second * 60 / time.Duration((config.StepCount * config.RPM)),
stepMode: config.Mode, stepMode: config.Mode,
}, nil }, nil
} }
// Configure configures the pins of the Device // Configure does nothing, as it assumes that the pins of the Device have already
// been configured by the user as outputs.
func (d *Device) Configure() { func (d *Device) Configure() {
for _, pin := range d.pins {
pin.Configure(machine.PinConfig{Mode: machine.PinOutput})
}
} }
// 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
+1 -1
View File
@@ -10,7 +10,7 @@ import (
func main() { func main() {
println("GPS I2C Example") println("GPS I2C Example")
machine.I2C0.Configure(machine.I2CConfig{}) machine.I2C0.Configure(machine.I2CConfig{})
ublox := gps.NewI2C(machine.I2C0) ublox := gps.NewI2CWithAddress(machine.I2C0, gps.UBLOX_I2C_ADDRESS)
parser := gps.NewParser() parser := gps.NewParser()
var fix gps.Fix var fix gps.Fix
for { for {
+4 -6
View File
@@ -5,8 +5,6 @@
package ft6336 package ft6336
import ( import (
"machine"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy" "tinygo.org/x/drivers/internal/legacy"
"tinygo.org/x/drivers/touch" "tinygo.org/x/drivers/touch"
@@ -17,11 +15,11 @@ type Device struct {
bus drivers.I2C bus drivers.I2C
buf []byte buf []byte
Address uint8 Address uint8
intPin machine.Pin intPin drivers.Pin
} }
// New returns FT6336 device for the provided I2C bus using default address. // New returns FT6336 device for the provided I2C bus using default address.
func New(i2c drivers.I2C, intPin machine.Pin) *Device { func New(i2c drivers.I2C, intPin drivers.Pin) *Device {
return &Device{ return &Device{
bus: i2c, bus: i2c,
buf: make([]byte, 11), buf: make([]byte, 11),
@@ -34,10 +32,10 @@ func New(i2c drivers.I2C, intPin machine.Pin) *Device {
type Config struct { type Config struct {
} }
// Configure the FT6336 device. // Configure the FT6336 device. Note that the interrupt pin must be configured
// separately as an input.
func (d *Device) Configure(config Config) error { func (d *Device) Configure(config Config) error {
d.write1Byte(0xA4, 0x00) d.write1Byte(0xA4, 0x00)
d.intPin.Configure(machine.PinConfig{Mode: machine.PinInputPulldown})
return nil return nil
} }
+7 -11
View File
@@ -5,7 +5,6 @@ package gc9a01 // import "tinygo.org/x/drivers/gc9a01"
import ( import (
"image/color" "image/color"
"machine"
"time" "time"
"errors" "errors"
@@ -22,10 +21,10 @@ type FrameRate uint8
// Device wraps an SPI connection. // Device wraps an SPI connection.
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
resetPin machine.Pin resetPin drivers.Pin
csPin machine.Pin csPin drivers.Pin
blPin machine.Pin blPin drivers.Pin
width int16 width int16
height int16 height int16
columnOffsetCfg int16 columnOffsetCfg int16
@@ -51,12 +50,9 @@ type Config struct {
Height int16 Height int16
} }
// New creates a new ST7789 connection. The SPI wire must already be configured. // New creates a new ST7789 connection. The SPI wire must already be configured, along with the
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device { // data/command and reset pins as outputs.
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
return Device{ return Device{
bus: bus, bus: bus,
resetPin: resetPin, resetPin: resetPin,
+7 -1
View File
@@ -69,10 +69,16 @@ func NewUART(uart drivers.UART) Device {
} }
// NewI2C creates a new I2C GPS connection. // NewI2C creates a new I2C GPS connection.
// Uses the default i2c address (0x42) for backward compatibility reasons.
func NewI2C(bus drivers.I2C) Device { func NewI2C(bus drivers.I2C) Device {
return NewI2CWithAddress(bus, I2C_ADDRESS)
}
// NewI2CWithAddress creates a new I2C GPS connection on the provided address
func NewI2CWithAddress(bus drivers.I2C, i2cAddress uint16) Device {
return Device{ return Device{
bus: bus, bus: bus,
address: I2C_ADDRESS, address: i2cAddress,
buffer: make([]byte, bufferSize), buffer: make([]byte, bufferSize),
bufIdx: bufferSize, bufIdx: bufferSize,
sentence: strings.Builder{}, sentence: strings.Builder{},
+5 -1
View File
@@ -4,7 +4,11 @@ package gps
// The I2C address which this device listens to. // The I2C address which this device listens to.
const ( const (
I2C_ADDRESS = 0x42 // To ensure backward compatibility
I2C_ADDRESS = UBLOX_I2C_ADDRESS
UBLOX_I2C_ADDRESS = 0x42
PA1010D_I2C_ADDRESS = 0x10
) )
const ( const (
+8 -7
View File
@@ -5,30 +5,31 @@
package hcsr04 package hcsr04
import ( import (
"machine"
"time" "time"
"tinygo.org/x/drivers"
) )
const TIMEOUT = 23324 // max sensing distance (4m) const TIMEOUT = 23324 // max sensing distance (4m)
// Device holds the pins // Device holds the pins
type Device struct { type Device struct {
trigger machine.Pin trigger drivers.Pin
echo machine.Pin echo drivers.Pin
} }
// New returns a new ultrasonic driver given 2 pins // New returns a new ultrasonic driver given 2 pins
func New(trigger, echo machine.Pin) Device { func New(trigger, echo drivers.Pin) Device {
return Device{ return Device{
trigger: trigger, trigger: trigger,
echo: echo, echo: echo,
} }
} }
// Configure configures the pins of the Device // Configure expects that the pins of the Device have already
// been configured by the user. Trigger pin should be an output
// and echo pin should be an input.
func (d *Device) Configure() { func (d *Device) Configure() {
d.trigger.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.echo.Configure(machine.PinConfig{Mode: machine.PinInput})
} }
// ReadDistance returns the distance of the object in mm // ReadDistance returns the distance of the object in mm
+35 -24
View File
@@ -8,7 +8,6 @@ import (
"errors" "errors"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
) )
type AccelRange uint8 type AccelRange uint8
@@ -26,7 +25,7 @@ type Device struct {
accelSampleRate AccelSampleRate accelSampleRate AccelSampleRate
gyroRange GyroRange gyroRange GyroRange
gyroSampleRate GyroSampleRate gyroSampleRate GyroSampleRate
buf [6]uint8 buf [7]uint8 // up to 6 bytes for read + 1 byte for the register address
} }
// Configuration for LSM6DS3TR device. // Configuration for LSM6DS3TR device.
@@ -84,30 +83,20 @@ func (d *Device) doConfigure(cfg Configuration) (err error) {
d.gyroSampleRate = GYRO_SR_104 d.gyroSampleRate = GYRO_SR_104
} }
data := d.buf[:1]
// Configure accelerometer // Configure accelerometer
data[0] = uint8(d.accelRange) | uint8(d.accelSampleRate) err = d.writeByte(CTRL1_XL, uint8(d.accelRange)|uint8(d.accelSampleRate))
err = legacy.WriteRegister(d.bus, uint8(d.Address), CTRL1_XL, data)
if err != nil { if err != nil {
return return
} }
// Set ODR bit // Enable ODR scaling
err = legacy.ReadRegister(d.bus, uint8(d.Address), CTRL4_C, data) err = d.setBits(CTRL4_C, BW_SCAL_ODR_ENABLED)
if err != nil {
return
}
data[0] = data[0] &^ BW_SCAL_ODR_ENABLED
data[0] |= BW_SCAL_ODR_ENABLED
err = legacy.WriteRegister(d.bus, uint8(d.Address), CTRL4_C, data)
if err != nil { if err != nil {
return return
} }
// Configure gyroscope // Configure gyroscope
data[0] = uint8(d.gyroRange) | uint8(d.gyroSampleRate) err = d.writeByte(CTRL2_G, uint8(d.gyroRange)|uint8(d.gyroSampleRate))
err = legacy.WriteRegister(d.bus, uint8(d.Address), CTRL2_G, data)
if err != nil { if err != nil {
return return
} }
@@ -118,8 +107,10 @@ func (d *Device) doConfigure(cfg Configuration) (err error) {
// Connected returns whether a LSM6DS3TR has been found. // Connected returns whether a LSM6DS3TR has been found.
// It does a "who am I" request and checks the response. // It does a "who am I" request and checks the response.
func (d *Device) Connected() bool { func (d *Device) Connected() bool {
data := d.buf[:1] data, err := d.readBytes(WHO_AM_I, 1)
legacy.ReadRegister(d.bus, uint8(d.Address), WHO_AM_I, data) if err != nil {
return false
}
return data[0] == 0x6A return data[0] == 0x6A
} }
@@ -128,8 +119,7 @@ func (d *Device) Connected() bool {
// and the sensor is not moving the returned value will be around 1000000 or // and the sensor is not moving the returned value will be around 1000000 or
// -1000000. // -1000000.
func (d *Device) ReadAcceleration() (x, y, z int32, err error) { func (d *Device) ReadAcceleration() (x, y, z int32, err error) {
data := d.buf[:6] data, err := d.readBytes(OUTX_L_XL, 6)
err = legacy.ReadRegister(d.bus, uint8(d.Address), OUTX_L_XL, data)
if err != nil { if err != nil {
return return
} }
@@ -153,8 +143,7 @@ func (d *Device) ReadAcceleration() (x, y, z int32, err error) {
// rotation along one axis and while doing so integrate all values over time, // rotation along one axis and while doing so integrate all values over time,
// you would get a value close to 360000000. // you would get a value close to 360000000.
func (d *Device) ReadRotation() (x, y, z int32, err error) { func (d *Device) ReadRotation() (x, y, z int32, err error) {
data := d.buf[:6] data, err := d.readBytes(OUTX_L_G, 6)
err = legacy.ReadRegister(d.bus, uint8(d.Address), OUTX_L_G, data)
if err != nil { if err != nil {
return return
} }
@@ -177,8 +166,7 @@ func (d *Device) ReadRotation() (x, y, z int32, err error) {
// ReadTemperature returns the temperature in celsius milli degrees (°C/1000) // ReadTemperature returns the temperature in celsius milli degrees (°C/1000)
func (d *Device) ReadTemperature() (t int32, err error) { func (d *Device) ReadTemperature() (t int32, err error) {
data := d.buf[:2] data, err := d.readBytes(OUT_TEMP_L, 2)
err = legacy.ReadRegister(d.bus, uint8(d.Address), OUT_TEMP_L, data)
if err != nil { if err != nil {
return return
} }
@@ -187,3 +175,26 @@ func (d *Device) ReadTemperature() (t int32, err error) {
t = 25000 + (int32(int16((int16(data[1])<<8)|int16(data[0])))*125)/32 t = 25000 + (int32(int16((int16(data[1])<<8)|int16(data[0])))*125)/32
return return
} }
func (d *Device) readBytes(reg, size uint8) ([]byte, error) {
d.buf[0] = reg
err := d.bus.Tx(d.Address, d.buf[0:1], d.buf[1:size+1])
if err != nil {
return nil, err
}
return d.buf[1 : size+1], nil
}
func (d *Device) writeByte(reg, value uint8) error {
d.buf[0] = reg
d.buf[1] = value
return d.bus.Tx(d.Address, d.buf[0:2], nil)
}
func (d *Device) setBits(reg, bits uint8) error {
data, err := d.readBytes(reg, 1)
if err != nil {
return err
}
return d.writeByte(reg, (data[0]&^bits)|bits)
}
+2 -3
View File
@@ -3,7 +3,6 @@ package max6675
import ( import (
"errors" "errors"
"machine"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
) )
@@ -14,13 +13,13 @@ var ErrThermocoupleOpen = errors.New("thermocouple input open")
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
} }
// Create a new Device to read from a MAX6675 thermocouple. // Create a new Device to read from a MAX6675 thermocouple.
// Pins must be configured before use. Frequency for SPI // Pins must be configured before use. Frequency for SPI
// should be 4.3MHz maximum. // should be 4.3MHz maximum.
func NewDevice(bus drivers.SPI, cs machine.Pin) *Device { func NewDevice(bus drivers.SPI, cs drivers.Pin) *Device {
return &Device{ return &Device{
bus: bus, bus: bus,
cs: cs, cs: cs,
+3 -8
View File
@@ -3,31 +3,26 @@
package max72xx package max72xx
import ( import (
"machine"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
) )
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
} }
// NewDriver creates a new max7219 connection. The SPI wire must already be configured // NewDriver creates a new max7219 connection. The SPI wire must already be configured
// The SPI frequency must not be higher than 10MHz. // The SPI frequency must not be higher than 10MHz.
// parameter cs: the datasheet also refers to this pin as "load" pin. // parameter cs: the datasheet also refers to this pin as "load" pin.
func NewDevice(bus drivers.SPI, cs machine.Pin) *Device { func NewDevice(bus drivers.SPI, cs drivers.Pin) *Device {
return &Device{ return &Device{
bus: bus, bus: bus,
cs: cs, cs: cs,
} }
} }
// Configure setups the pins. // Configure expects that the pin of the Device has already been configured by the user as output.
func (driver *Device) Configure() { func (driver *Device) Configure() {
outPutConfig := machine.PinConfig{Mode: machine.PinOutput}
driver.cs.Configure(outPutConfig)
} }
// SetScanLimit sets the scan limit. Maximum is 8. // SetScanLimit sets the scan limit. Maximum is 8.
+4 -5
View File
@@ -8,7 +8,6 @@ package mcp2515 // import "tinygo.org/x/drivers/mcp2515"
import ( import (
"errors" "errors"
"fmt" "fmt"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -17,7 +16,7 @@ import (
// Device wraps MCP2515 SPI CAN Module. // Device wraps MCP2515 SPI CAN Module.
type Device struct { type Device struct {
spi SPI spi SPI
cs machine.Pin cs drivers.Pin
msg *CANMsg msg *CANMsg
mcpMode byte mcpMode byte
} }
@@ -36,7 +35,7 @@ const (
) )
// New returns a new MCP2515 driver. Pass in a fully configured SPI bus. // New returns a new MCP2515 driver. Pass in a fully configured SPI bus.
func New(b drivers.SPI, csPin machine.Pin) *Device { func New(b drivers.SPI, csPin drivers.Pin) *Device {
d := &Device{ d := &Device{
spi: SPI{ spi: SPI{
bus: b, bus: b,
@@ -50,9 +49,9 @@ func New(b drivers.SPI, csPin machine.Pin) *Device {
return d return d
} }
// Configure sets up the device for communication. // Configure sets up the device for communication. It expects the SPI interface to be already
// configured, and the CS configured as output.
func (d *Device) Configure() { func (d *Device) Configure() {
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
} }
const beginTimeoutValue int = 10 const beginTimeoutValue int = 10
+5 -6
View File
@@ -6,7 +6,6 @@ package pcd8544 // import "tinygo.org/x/drivers/pcd8544"
import ( import (
"errors" "errors"
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -15,9 +14,9 @@ import (
// Device wraps an SPI connection. // Device wraps an SPI connection.
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
rstPin machine.Pin rstPin drivers.Pin
scePin machine.Pin scePin drivers.Pin
buffer []byte buffer []byte
width int16 width int16
height int16 height int16
@@ -29,8 +28,8 @@ type Config struct {
Height int16 Height int16
} }
// New creates a new PCD8544 connection. The SPI bus must already be configured. // New creates a new PCD8544 connection. The SPI bus and pins must already be configured.
func New(bus drivers.SPI, dcPin, rstPin, scePin machine.Pin) *Device { func New(bus drivers.SPI, dcPin, rstPin, scePin drivers.Pin) *Device {
return &Device{ return &Device{
bus: bus, bus: bus,
dcPin: dcPin, dcPin: dcPin,
+10
View File
@@ -0,0 +1,10 @@
package drivers
// Pin is a digital pin interface. It is notably implemented by the
// machine.Pin type.
type Pin interface {
Get() bool
High()
Low()
Set(high bool)
}
+6 -8
View File
@@ -2,7 +2,7 @@
package shiftregister package shiftregister
import ( import (
"machine" "tinygo.org/x/drivers"
) )
type NumberBit int8 type NumberBit int8
@@ -16,20 +16,20 @@ const (
// Device holds pin number // Device holds pin number
type Device struct { type Device struct {
latch, clock, out machine.Pin // IC wiring latch, clock, out drivers.Pin // IC wiring
bits NumberBit // Pin number bits NumberBit // Pin number
mask uint32 // keep all pins state mask uint32 // keep all pins state
} }
// ShiftPin is the implementation of the ShiftPin interface. // ShiftPin is the implementation of the ShiftPin interface.
// ShiftPin provide an interface like regular machine.Pin // ShiftPin provide an interface like regular drivers.Pin
type ShiftPin struct { type ShiftPin struct {
mask uint32 // Bit representing the pin mask uint32 // Bit representing the pin
d *Device // Reference to the register d *Device // Reference to the register
} }
// New returns a new shift output register device // New returns a new shift output register device
func New(Bits NumberBit, Latch, Clock, Out machine.Pin) *Device { func New(Bits NumberBit, Latch, Clock, Out drivers.Pin) *Device {
return &Device{ return &Device{
latch: Latch, latch: Latch,
clock: Clock, clock: Clock,
@@ -38,11 +38,9 @@ func New(Bits NumberBit, Latch, Clock, Out machine.Pin) *Device {
} }
} }
// Configure set hardware configuration // Configure set hardware configuration. Make sure that the pins are already configured
// as output.
func (d *Device) Configure() { func (d *Device) Configure() {
d.latch.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.clock.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.out.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.latch.High() d.latch.High()
} }
+7 -11
View File
@@ -5,8 +5,9 @@ package ssd1289
import ( import (
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers"
) )
type Bus interface { type Bus interface {
@@ -14,17 +15,17 @@ type Bus interface {
} }
type Device struct { type Device struct {
rs machine.Pin rs drivers.Pin
wr machine.Pin wr drivers.Pin
cs machine.Pin cs drivers.Pin
rst machine.Pin rst drivers.Pin
bus Bus bus Bus
} }
const width = int16(240) const width = int16(240)
const height = int16(320) const height = int16(320)
func New(rs machine.Pin, wr machine.Pin, cs machine.Pin, rst machine.Pin, bus Bus) Device { func New(rs drivers.Pin, wr drivers.Pin, cs drivers.Pin, rst drivers.Pin, bus Bus) Device {
d := Device{ d := Device{
rs: rs, rs: rs,
wr: wr, wr: wr,
@@ -33,11 +34,6 @@ func New(rs machine.Pin, wr machine.Pin, cs machine.Pin, rst machine.Pin, bus Bu
bus: bus, bus: bus,
} }
rs.Configure(machine.PinConfig{Mode: machine.PinOutput})
wr.Configure(machine.PinConfig{Mode: machine.PinOutput})
cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
cs.High() cs.High()
rst.High() rst.High()
wr.High() wr.High()
+5 -11
View File
@@ -6,7 +6,6 @@ package ssd1306 // import "tinygo.org/x/drivers/ssd1306"
import ( import (
"errors" "errors"
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -58,9 +57,9 @@ type I2CBus struct {
type SPIBus struct { type SPIBus struct {
wire drivers.SPI wire drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
resetPin machine.Pin resetPin drivers.Pin
csPin machine.Pin csPin drivers.Pin
} }
type Buser interface { type Buser interface {
@@ -81,11 +80,8 @@ func NewI2C(bus drivers.I2C) Device {
} }
} }
// NewSPI creates a new SSD1306 connection. The SPI wire must already be configured. // NewSPI creates a new SSD1306 connection. The SPI wire and pins must already be configured.
func NewSPI(bus drivers.SPI, dcPin, resetPin, csPin machine.Pin) Device { func NewSPI(bus drivers.SPI, dcPin, resetPin, csPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
return Device{ return Device{
bus: &SPIBus{ bus: &SPIBus{
wire: bus, wire: bus,
@@ -322,7 +318,6 @@ func (b *SPIBus) tx(data []byte, isCommand bool) error {
if isCommand { if isCommand {
b.csPin.High() b.csPin.High()
time.Sleep(1 * time.Millisecond)
b.dcPin.Low() b.dcPin.Low()
b.csPin.Low() b.csPin.Low()
@@ -330,7 +325,6 @@ func (b *SPIBus) tx(data []byte, isCommand bool) error {
b.csPin.High() b.csPin.High()
} else { } else {
b.csPin.High() b.csPin.High()
time.Sleep(1 * time.Millisecond)
b.dcPin.High() b.dcPin.High()
b.csPin.Low() b.csPin.Low()
+5 -9
View File
@@ -5,7 +5,6 @@ package ssd1331 // import "tinygo.org/x/drivers/ssd1331"
import ( import (
"image/color" "image/color"
"machine"
"errors" "errors"
"time" "time"
@@ -19,9 +18,9 @@ type Rotation uint8
// Device wraps an SPI connection. // Device wraps an SPI connection.
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
resetPin machine.Pin resetPin drivers.Pin
csPin machine.Pin csPin drivers.Pin
width int16 width int16
height int16 height int16
batchLength int16 batchLength int16
@@ -35,11 +34,8 @@ type Config struct {
Height int16 Height int16
} }
// New creates a new SSD1331 connection. The SPI wire must already be configured. // New creates a new SSD1331 connection. The SPI wire and pins must already be configured.
func New(bus drivers.SPI, resetPin, dcPin, csPin machine.Pin) Device { func New(bus drivers.SPI, resetPin, dcPin, csPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
return Device{ return Device{
bus: bus, bus: bus,
dcPin: dcPin, dcPin: dcPin,
+6 -14
View File
@@ -6,7 +6,6 @@ package ssd1351 // import "tinygo.org/x/drivers/ssd1351"
import ( import (
"errors" "errors"
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -20,11 +19,11 @@ var (
// Device wraps an SPI connection. // Device wraps an SPI connection.
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
resetPin machine.Pin resetPin drivers.Pin
csPin machine.Pin csPin drivers.Pin
enPin machine.Pin enPin drivers.Pin
rwPin machine.Pin rwPin drivers.Pin
width int16 width int16
height int16 height int16
rowOffset int16 rowOffset int16
@@ -41,7 +40,7 @@ type Config struct {
} }
// New creates a new SSD1351 connection. The SPI wire must already be configured. // New creates a new SSD1351 connection. The SPI wire must already be configured.
func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin machine.Pin) Device { func New(bus drivers.SPI, resetPin, dcPin, csPin, enPin, rwPin drivers.Pin) Device {
return Device{ return Device{
bus: bus, bus: bus,
dcPin: dcPin, dcPin: dcPin,
@@ -72,13 +71,6 @@ func (d *Device) Configure(cfg Config) {
d.bufferLength = d.height d.bufferLength = d.height
} }
// configure GPIO pins
d.dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.enPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rwPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
// reset the device // reset the device
d.resetPin.High() d.resetPin.High()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
+7 -12
View File
@@ -5,7 +5,6 @@ package st7735 // import "tinygo.org/x/drivers/st7735"
import ( import (
"image/color" "image/color"
"machine"
"time" "time"
"errors" "errors"
@@ -39,10 +38,10 @@ type Device = DeviceOf[pixel.RGB565BE]
// formats. // formats.
type DeviceOf[T Color] struct { type DeviceOf[T Color] struct {
bus drivers.SPI bus drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
resetPin machine.Pin resetPin drivers.Pin
csPin machine.Pin csPin drivers.Pin
blPin machine.Pin blPin drivers.Pin
width int16 width int16
height int16 height int16
columnOffset int16 columnOffset int16
@@ -65,17 +64,13 @@ type Config struct {
} }
// New creates a new ST7735 connection. The SPI wire must already be configured. // New creates a new ST7735 connection. The SPI wire must already be configured.
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device { func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) Device {
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin) return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
} }
// NewOf creates a new ST7735 connection with a particular pixel format. The SPI // NewOf creates a new ST7735 connection with a particular pixel format. The SPI
// wire must already be configured. // wire and pins must already be configured.
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) DeviceOf[T] { func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) DeviceOf[T] {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
return DeviceOf[T]{ return DeviceOf[T]{
bus: bus, bus: bus,
dcPin: dcPin, dcPin: dcPin,
+7 -11
View File
@@ -46,10 +46,10 @@ type Device = DeviceOf[pixel.RGB565BE]
// formats. // formats.
type DeviceOf[T Color] struct { type DeviceOf[T Color] struct {
bus drivers.SPI bus drivers.SPI
dcPin machine.Pin dcPin drivers.Pin
resetPin machine.Pin resetPin drivers.Pin
csPin machine.Pin csPin drivers.Pin
blPin machine.Pin blPin drivers.Pin
width int16 width int16
height int16 height int16
columnOffsetCfg int16 columnOffsetCfg int16
@@ -83,17 +83,13 @@ type Config struct {
} }
// New creates a new ST7789 connection. The SPI wire must already be configured. // New creates a new ST7789 connection. The SPI wire must already be configured.
func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) Device { func New(bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) Device {
return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin) return NewOf[pixel.RGB565BE](bus, resetPin, dcPin, csPin, blPin)
} }
// NewOf creates a new ST7789 connection with a particular pixel format. The SPI // NewOf creates a new ST7789 connection with a particular pixel format. The SPI
// wire must already be configured. // wire and pins must already be configured.
func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin machine.Pin) DeviceOf[T] { func NewOf[T Color](bus drivers.SPI, resetPin, dcPin, csPin, blPin drivers.Pin) DeviceOf[T] {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
resetPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
blPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
return DeviceOf[T]{ return DeviceOf[T]{
bus: bus, bus: bus,
dcPin: dcPin, dcPin: dcPin,
+2 -3
View File
@@ -6,7 +6,6 @@ package sx127x
import ( import (
"errors" "errors"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -22,7 +21,7 @@ const (
// Device wraps an SPI connection to a SX127x device. // Device wraps an SPI connection to a SX127x device.
type Device struct { type Device struct {
spi drivers.SPI // SPI bus for module communication spi drivers.SPI // SPI bus for module communication
rstPin machine.Pin // GPIO for reset rstPin drivers.Pin // GPIO for reset
radioEventChan chan lora.RadioEvent // Channel for Receiving events radioEventChan chan lora.RadioEvent // Channel for Receiving events
loraConf lora.Config // Current Lora configuration loraConf lora.Config // Current Lora configuration
controller RadioController // to manage interactions with the radio controller RadioController // to manage interactions with the radio
@@ -43,7 +42,7 @@ func (d *Device) GetRadioEventChan() chan lora.RadioEvent {
} }
// New creates a new SX127x connection. The SPI bus must already be configured. // New creates a new SX127x connection. The SPI bus must already be configured.
func New(spi drivers.SPI, rstPin machine.Pin) *Device { func New(spi drivers.SPI, rstPin drivers.Pin) *Device {
k := Device{ k := Device{
spi: spi, spi: spi,
rstPin: rstPin, rstPin: rstPin,
+7 -15
View File
@@ -57,14 +57,10 @@ func (comm *UARTComm) WriteRegister(register uint8, value uint32, driverIndex ui
byte((value >> 16) & 0xFF), // Middle byte byte((value >> 16) & 0xFF), // Middle byte
byte((value >> 8) & 0xFF), // Next byte byte((value >> 8) & 0xFF), // Next byte
byte(value & 0xFF), // LSB of value byte(value & 0xFF), // LSB of value
0, // CRC
} }
// Calculate checksum by XORing all bytes buffer[7] = CalculateCRC(buffer[:7])
checksum := byte(0)
for _, b := range buffer[:7] {
checksum ^= b
}
buffer[7] = checksum // Set checksum byte
// Write the data to the TMC2209 // Write the data to the TMC2209
done := make(chan error, 1) done := make(chan error, 1)
@@ -86,10 +82,10 @@ func (comm *UARTComm) WriteRegister(register uint8, value uint32, driverIndex ui
// ReadRegister sends a register read command to the TMC2209 with a timeout. // ReadRegister sends a register read command to the TMC2209 with a timeout.
func (comm *UARTComm) ReadRegister(register uint8, driverIndex uint8) (uint32, error) { func (comm *UARTComm) ReadRegister(register uint8, driverIndex uint8) (uint32, error) {
var writeBuffer [4]byte var writeBuffer [4]byte
writeBuffer[0] = 0x05 // Sync byte writeBuffer[0] = 0x05 // Sync byte
writeBuffer[1] = 0x00 // Slave address writeBuffer[1] = 0x00 // Slave address
writeBuffer[2] = register & 0x7F // Read command (MSB clear for read) writeBuffer[2] = register & 0x7F // Read command (MSB clear for read)
writeBuffer[3] = writeBuffer[0] ^ writeBuffer[1] ^ writeBuffer[2] // Checksum writeBuffer[3] = CalculateCRC(writeBuffer[:3])
// Send the read command // Send the read command
done := make(chan []byte, 1) done := make(chan []byte, 1)
@@ -103,11 +99,7 @@ func (comm *UARTComm) ReadRegister(register uint8, driverIndex uint8) (uint32, e
// Implementing timeout using a 100ms timer // Implementing timeout using a 100ms timer
select { select {
case readBuffer := <-done: case readBuffer := <-done:
// Validate checksum checksum := CalculateCRC(readBuffer[:7])
checksum := byte(0)
for i := 0; i < 7; i++ {
checksum ^= readBuffer[i]
}
if checksum != readBuffer[7] { if checksum != readBuffer[7] {
return 0, CustomError("checksum error") return 0, CustomError("checksum error")
} }
+7 -11
View File
@@ -8,7 +8,6 @@ package uc8151 // import "tinygo.org/x/drivers/uc8151"
import ( import (
"errors" "errors"
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -31,10 +30,10 @@ type Config struct {
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
width int16 width int16
height int16 height int16
buffer []uint8 buffer []uint8
@@ -48,12 +47,9 @@ type Device struct {
type Speed uint8 type Speed uint8
// New returns a new uc8151 driver. Pass in a fully configured SPI bus. // New returns a new uc8151 driver. Pass in a fully configured SPI bus and pins.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { // busyPin should be set and input, the others as outputs.
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
return Device{ return Device{
bus: bus, bus: bus,
cs: csPin, cs: csPin,
+1 -1
View File
@@ -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.30.0" const Version = "0.32.0"
+7 -15
View File
@@ -12,6 +12,8 @@ import (
"image/color" "image/color"
"machine" "machine"
"time" "time"
"tinygo.org/x/drivers"
) )
type Config struct { type Config struct {
@@ -23,10 +25,10 @@ type Config struct {
type Device struct { type Device struct {
bus *machine.SPI bus *machine.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
buffer []uint8 buffer []uint8
rotation Rotation rotation Rotation
@@ -79,7 +81,7 @@ var partialRefresh = [159]uint8{
} }
// New returns a new epd1in54 driver. Pass in a fully configured SPI bus. // New returns a new epd1in54 driver. Pass in a fully configured SPI bus.
func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
return Device{ return Device{
buffer: make([]uint8, (uint32(Width)*uint32(Height))/8), buffer: make([]uint8, (uint32(Width)*uint32(Height))/8),
bus: bus, bus: bus,
@@ -91,11 +93,6 @@ func New(bus *machine.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device {
} }
func (d *Device) LDirInit(cfg Config) { func (d *Device) LDirInit(cfg Config) {
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
d.bus.Configure(machine.SPIConfig{ d.bus.Configure(machine.SPIConfig{
Frequency: 2000000, Frequency: 2000000,
Mode: 0, Mode: 0,
@@ -150,11 +147,6 @@ func (d *Device) LDirInit(cfg Config) {
} }
func (d *Device) HDirInit(cfg Config) { func (d *Device) HDirInit(cfg Config) {
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
d.bus.Configure(machine.SPIConfig{ d.bus.Configure(machine.SPIConfig{
Frequency: 2000000, Frequency: 2000000,
Mode: 0, Mode: 0,
+7 -11
View File
@@ -6,7 +6,6 @@ package epd2in13 // import "tinygo.org/x/drivers/waveshare-epd/epd2in13"
import ( import (
"errors" "errors"
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -21,10 +20,10 @@ type Config struct {
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
logicalWidth int16 logicalWidth int16
width int16 width int16
height int16 height int16
@@ -52,12 +51,9 @@ var lutPartialUpdate = [30]uint8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
} }
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus. // New returns a new epd2in13x driver. Pass in a fully configured SPI bus and pins.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { // Busy pin should input, the rest should be output.
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
return Device{ return Device{
bus: bus, bus: bus,
cs: csPin, cs: csPin,
+7 -11
View File
@@ -6,7 +6,6 @@ package epd2in13x // import "tinygo.org/x/drivers/waveshare-epd/epd2in13x"
import ( import (
"errors" "errors"
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -20,10 +19,10 @@ type Config struct {
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
width int16 width int16
height int16 height int16
buffer [][]uint8 buffer [][]uint8
@@ -32,12 +31,9 @@ type Device struct {
type Color uint8 type Color uint8
// New returns a new epd2in13x driver. Pass in a fully configured SPI bus. // New returns a new epd2in13x driver. Pass in a fully configured SPI bus and pins.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { // Busy pin should input, the rest should be output.
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
return Device{ return Device{
bus: bus, bus: bus,
cs: csPin, cs: csPin,
+10 -15
View File
@@ -5,7 +5,6 @@ package epd2in66b
import ( import (
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -19,18 +18,18 @@ const (
const Baudrate = 4_000_000 // 4 MHz const Baudrate = 4_000_000 // 4 MHz
type Config struct { type Config struct {
ResetPin machine.Pin ResetPin drivers.Pin
DataPin machine.Pin DataPin drivers.Pin
ChipSelectPin machine.Pin ChipSelectPin drivers.Pin
BusyPin machine.Pin BusyPin drivers.Pin
} }
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
blackBuffer []byte blackBuffer []byte
redBuffer []byte redBuffer []byte
@@ -50,18 +49,14 @@ func New(bus drivers.SPI) Device {
} }
} }
// Configure configures the device and its pins. // Configure configures the device. Note that pins should already
// be configured. Busy pin should be input, the rest should be output.
func (d *Device) Configure(c Config) error { func (d *Device) Configure(c Config) error {
d.cs = c.ChipSelectPin d.cs = c.ChipSelectPin
d.dc = c.DataPin d.dc = c.DataPin
d.rst = c.ResetPin d.rst = c.ResetPin
d.busy = c.BusyPin d.busy = c.BusyPin
d.cs.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.dc.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.rst.Configure(machine.PinConfig{Mode: machine.PinOutput})
d.busy.Configure(machine.PinConfig{Mode: machine.PinInput})
return nil return nil
} }
+7 -11
View File
@@ -13,7 +13,6 @@ package epd2in9 // import "tinygo.org/x/drivers/waveshare-epd/epd2in9"
import ( import (
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -28,10 +27,10 @@ type Config struct {
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
logicalWidth int16 logicalWidth int16
width int16 width int16
height int16 height int16
@@ -60,12 +59,9 @@ var lutPartialUpdate = [30]uint8{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
} }
// New returns a new epd2in9 driver. Pass in a fully configured SPI bus. // New returns a new epd2in9 driver. Pass in a fully configured SPI bus and pins.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { // Busy pin should input, the rest should be output.
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
return Device{ return Device{
bus: bus, bus: bus,
cs: csPin, cs: csPin,
+7 -11
View File
@@ -10,7 +10,6 @@ package epd4in2
import ( import (
"image/color" "image/color"
"machine"
"time" "time"
"tinygo.org/x/drivers" "tinygo.org/x/drivers"
@@ -25,10 +24,10 @@ type Config struct {
type Device struct { type Device struct {
bus drivers.SPI bus drivers.SPI
cs machine.Pin cs drivers.Pin
dc machine.Pin dc drivers.Pin
rst machine.Pin rst drivers.Pin
busy machine.Pin busy drivers.Pin
logicalWidth int16 logicalWidth int16
width int16 width int16
height int16 height int16
@@ -39,12 +38,9 @@ type Device struct {
type Rotation uint8 type Rotation uint8
// New returns a new epd4in2 driver. Pass in a fully configured SPI bus. // New returns a new epd4in2 driver. Pass in a fully configured SPI bus and pins.
func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin machine.Pin) Device { // Busy pin should input, the rest should be output.
csPin.Configure(machine.PinConfig{Mode: machine.PinOutput}) func New(bus drivers.SPI, csPin, dcPin, rstPin, busyPin drivers.Pin) Device {
dcPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
rstPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
busyPin.Configure(machine.PinConfig{Mode: machine.PinInput})
return Device{ return Device{
bus: bus, bus: bus,
cs: csPin, cs: csPin,
+469
View File
@@ -1320,6 +1320,465 @@ void ws2812_writeByte168(char c, uint32_t *portSet, uint32_t *portClear, uint32_
[maskClear]"r"(maskClear), [maskClear]"r"(maskClear),
[portClear]"m"(*portClear)); [portClear]"m"(*portClear));
} }
__attribute__((always_inline))
void ws2812_writeByte200(char c, uint32_t *portSet, uint32_t *portClear, uint32_t maskSet, uint32_t maskClear) {
// Timings:
// T0H: 70 - 72 cycles or 350.0ns - 360.0ns
// T1H: 210 - 212 cycles or 1050.0ns - 1060.0ns
// TLD: 230 - cycles or 1150.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 nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t 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 nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t 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 nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t nop\n"
"\t 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));
}
*/ */
import "C" import "C"
@@ -1382,3 +1841,13 @@ func (d Device) writeByte168(c byte) {
interrupt.Restore(mask) interrupt.Restore(mask)
} }
func (d Device) writeByte200(c byte) {
portSet, maskSet := d.Pin.PortMaskSet()
portClear, maskClear := d.Pin.PortMaskClear()
mask := interrupt.Disable()
C.ws2812_writeByte200(C.char(c), (*C.uint32_t)(unsafe.Pointer(portSet)), (*C.uint32_t)(unsafe.Pointer(portClear)), C.uint32_t(maskSet), C.uint32_t(maskClear))
interrupt.Restore(mask)
}
+1 -1
View File
@@ -1,7 +1,7 @@
// 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 125 168 200
//go:generate go run gen-ws2812.go -arch=tinygoriscv 160 320 //go:generate go run gen-ws2812.go -arch=tinygoriscv 160 320
import ( import (
+4 -1
View File
@@ -28,12 +28,15 @@ 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 case 125_000_000: // 125 MHz e.g. rp2040 originally
d.writeByte125(c) d.writeByte125(c)
return nil 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
case 200_000_000: // 200MHz, e.g. rp2040 starting with TinyGo v0.37
d.writeByte200(c)
return nil
default: default:
return errUnknownClockSpeed return errUnknownClockSpeed
} }