mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-17 03:03:27 +00:00
avr: implement Get() function on AVR, and leave stubs for NRF and dummy machines
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
committed by
Ayke van Laethem
parent
ec50db729d
commit
ab6757fe11
@@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"machine"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This example assumes that the button is connected to pin 8. Change the value
|
||||||
|
// below to use a different pin.
|
||||||
|
const buttonPin = 8
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
led := machine.GPIO{machine.LED}
|
||||||
|
led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
||||||
|
|
||||||
|
button := machine.GPIO{buttonPin}
|
||||||
|
button.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT})
|
||||||
|
|
||||||
|
for {
|
||||||
|
if button.Get() {
|
||||||
|
led.Low()
|
||||||
|
} else {
|
||||||
|
led.High()
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.Sleep(runtime.Millisecond * 10)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,3 +47,14 @@ func (p GPIO) Set(value bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get returns the current value of a GPIO pin.
|
||||||
|
func (p GPIO) Get() bool {
|
||||||
|
if p.Pin < 8 {
|
||||||
|
val := *avr.PIND & (1 << p.Pin)
|
||||||
|
return (val > 0)
|
||||||
|
} else {
|
||||||
|
val := *avr.PINB & (1 << (p.Pin - 8))
|
||||||
|
return (val > 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -25,3 +25,7 @@ func (p GPIO) Configure(config GPIOConfig) {
|
|||||||
|
|
||||||
func (p GPIO) Set(value bool) {
|
func (p GPIO) Set(value bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p GPIO) Get() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
@@ -39,3 +39,9 @@ func (p GPIO) Set(high bool) {
|
|||||||
nrf.P0.OUTCLR = 1 << p.Pin
|
nrf.P0.OUTCLR = 1 << p.Pin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get returns the current value of a GPIO pin.
|
||||||
|
func (p GPIO) Get() bool {
|
||||||
|
// TODO: implement
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user