mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
f459992f3c
This adds hardware timing support for driving WS2812 LEDs on Cortex-M microcontrollers running at 160MHz (such as the STM32U585). - Updated `go:generate` directive to include 160MHz. - Generated the corresponding `ws2812_writeByte160` assembly routine. - Added a switch case in `WriteByte` to handle generic 160MHz processors. Signed-off-by: deadprogram <ron@hybridgroup.com>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
//go:build cortexm
|
|
|
|
package ws2812
|
|
|
|
// This file implements the WS2812 protocol for various Cortex-M
|
|
// microcontrollers. It is intended to work with various variants: M0, M0+, M3,
|
|
// and M4. Because machine.CPUFrequency() is usually a constant, the value will
|
|
// usually be constant-propagated and the switch below will be a direct
|
|
// (inlinable function) - thus there is usually no code size penalty over build
|
|
// tags per CPU speed.
|
|
|
|
import (
|
|
"machine"
|
|
)
|
|
|
|
// Send a single byte using the WS2812 protocol.
|
|
func (d Device) WriteByte(c byte) error {
|
|
switch machine.CPUFrequency() {
|
|
case 16_000_000: // 16MHz
|
|
d.writeByte16(c)
|
|
return nil
|
|
case 48_000_000: // 48MHz
|
|
d.writeByte48(c)
|
|
return nil
|
|
case 64_000_000: // 64MHz
|
|
d.writeByte64(c)
|
|
return nil
|
|
case 120_000_000: // 120MHz
|
|
d.writeByte120(c)
|
|
return nil
|
|
case 125_000_000: // 125 MHz e.g. rp2040 originally
|
|
d.writeByte125(c)
|
|
return nil
|
|
case 150_000_000: // 150MHz, e.g. rp2350
|
|
d.writeByte150(c)
|
|
return nil
|
|
case 160_000_000: // 160MHz, e.g. stm32u585
|
|
d.writeByte160(c)
|
|
return nil
|
|
case 168_000_000: // 168MHz, e.g. stm32f405
|
|
d.writeByte168(c)
|
|
return nil
|
|
case 200_000_000: // 200MHz, e.g. rp2040 starting with TinyGo v0.37
|
|
d.writeByte200(c)
|
|
return nil
|
|
default:
|
|
return errUnknownClockSpeed
|
|
}
|
|
}
|