From c830f878c6effe3397aea326b5e97f6f63e9457d Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 16 Sep 2021 18:04:55 +0200 Subject: [PATCH] stm32: add support for PortMask* functions for WS2812 support This also requires support in the tinygo.org/x/drivers/ws2812 package, which I've already partially written. --- src/machine/machine_stm32.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/machine/machine_stm32.go b/src/machine/machine_stm32.go index 0ba9ef8d..9acf22ae 100644 --- a/src/machine/machine_stm32.go +++ b/src/machine/machine_stm32.go @@ -58,3 +58,19 @@ func (p Pin) Get() bool { val := port.IDR.Get() & (1 << pin) return (val > 0) } + +// PortMaskSet returns the register and mask to enable a given GPIO pin. This +// can be used to implement bit-banged drivers. +func (p Pin) PortMaskSet() (*uint32, uint32) { + port := p.getPort() + pin := uint8(p) % 16 + return &port.BSRR.Reg, 1 << pin +} + +// PortMaskClear returns the register and mask to disable a given port. This can +// be used to implement bit-banged drivers. +func (p Pin) PortMaskClear() (*uint32, uint32) { + port := p.getPort() + pin := uint8(p) % 16 + return &port.BSRR.Reg, 1 << (pin + 16) +}