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.
This commit is contained in:
Ayke van Laethem
2021-09-16 18:04:55 +02:00
committed by Ron Evans
parent c7c874a487
commit c830f878c6
+16
View File
@@ -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)
}