From efd9cf72bab54cb3c7272e7833ecca312b916c6d Mon Sep 17 00:00:00 2001 From: cn Date: Mon, 16 Sep 2019 12:49:29 +0200 Subject: [PATCH] machine/stm32f103xx: add machine.Pin.Get method for reading GPIO values Writing pin values was already possible but reading was missing. --- src/machine/machine_stm32f103xx.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/machine/machine_stm32f103xx.go b/src/machine/machine_stm32f103xx.go index 552e540b..44fa8742 100644 --- a/src/machine/machine_stm32f103xx.go +++ b/src/machine/machine_stm32f103xx.go @@ -99,6 +99,14 @@ func (p Pin) Set(high bool) { } } +// Get returns the current value of a GPIO pin. +func (p Pin) Get() bool { + port := p.getPort() + pin := uint8(p) % 16 + val := port.IDR.Get() & (1 << pin) + return (val > 0) +} + // UART type UART struct { Buffer *RingBuffer