mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
Add AVR support
This requires support in LLVM, as AVR support is still experimental. For example, in bindings/go/build.sh, add -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR to cmake_flags.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
|
||||
// +build avr
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/avr"
|
||||
)
|
||||
|
||||
type GPIOMode uint8
|
||||
|
||||
const (
|
||||
GPIO_INPUT = iota
|
||||
GPIO_OUTPUT
|
||||
)
|
||||
|
||||
// LED on the Arduino
|
||||
const LED = 13
|
||||
|
||||
func (p GPIO) Configure(config GPIOConfig) {
|
||||
if config.Mode == GPIO_OUTPUT { // set output bit
|
||||
if p.Pin < 8 {
|
||||
avr.PORT.DDRD |= 1 << p.Pin
|
||||
} else {
|
||||
avr.PORT.DDRB |= 1 << (p.Pin - 8)
|
||||
}
|
||||
} else { // configure input: clear output bit
|
||||
if p.Pin < 8 {
|
||||
avr.PORT.DDRD &^= 1 << p.Pin
|
||||
} else {
|
||||
avr.PORT.DDRB &^= 1 << (p.Pin - 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p GPIO) Set(value bool) {
|
||||
if value { // set bits
|
||||
if p.Pin < 8 {
|
||||
avr.PORT.PORTD |= 1 << p.Pin
|
||||
} else {
|
||||
avr.PORT.PORTB |= 1 << (p.Pin - 8)
|
||||
}
|
||||
} else { // clear bits
|
||||
if p.Pin < 8 {
|
||||
avr.PORT.PORTB &^= 1 << p.Pin
|
||||
} else {
|
||||
avr.PORT.PORTB &^= 1 << (p.Pin - 8)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user