Skip to content

Commit c830f87

Browse files
aykevldeadprogram
authored andcommitted
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.
1 parent c7c874a commit c830f87

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/machine/machine_stm32.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,19 @@ func (p Pin) Get() bool {
5858
val := port.IDR.Get() & (1 << pin)
5959
return (val > 0)
6060
}
61+
62+
// PortMaskSet returns the register and mask to enable a given GPIO pin. This
63+
// can be used to implement bit-banged drivers.
64+
func (p Pin) PortMaskSet() (*uint32, uint32) {
65+
port := p.getPort()
66+
pin := uint8(p) % 16
67+
return &port.BSRR.Reg, 1 << pin
68+
}
69+
70+
// PortMaskClear returns the register and mask to disable a given port. This can
71+
// be used to implement bit-banged drivers.
72+
func (p Pin) PortMaskClear() (*uint32, uint32) {
73+
port := p.getPort()
74+
pin := uint8(p) % 16
75+
return &port.BSRR.Reg, 1 << (pin + 16)
76+
}

0 commit comments

Comments
 (0)