avr: add Arduino Mega 2560

This commit is contained in:
Travis McLane
2020-03-24 16:24:47 -05:00
committed by GitHub
parent 26aba72729
commit 83426edcdc
7 changed files with 341 additions and 48 deletions
-46
View File
@@ -5,54 +5,8 @@ package machine
import (
"device/avr"
"runtime/interrupt"
"runtime/volatile"
)
// Configure sets the pin to input or output.
func (p Pin) Configure(config PinConfig) {
if config.Mode == PinOutput { // set output bit
if p < 8 {
avr.DDRD.SetBits(1 << uint8(p))
} else if p < 14 {
avr.DDRB.SetBits(1 << uint8(p-8))
} else {
avr.DDRC.SetBits(1 << uint8(p-14))
}
} else { // configure input: clear output bit
if p < 8 {
avr.DDRD.ClearBits(1 << uint8(p))
} else if p < 14 {
avr.DDRB.ClearBits(1 << uint8(p-8))
} else {
avr.DDRC.ClearBits(1 << uint8(p-14))
}
}
}
// Get returns the current value of a GPIO pin.
func (p Pin) Get() bool {
if p < 8 {
val := avr.PIND.Get() & (1 << uint8(p))
return (val > 0)
} else if p < 14 {
val := avr.PINB.Get() & (1 << uint8(p-8))
return (val > 0)
} else {
val := avr.PINC.Get() & (1 << uint8(p-14))
return (val > 0)
}
}
func (p Pin) getPortMask() (*volatile.Register8, uint8) {
if p < 8 {
return avr.PORTD, 1 << uint8(p)
} else if p < 14 {
return avr.PORTB, 1 << uint8(p-8)
} else {
return avr.PORTC, 1 << uint8(p-14)
}
}
// InitPWM initializes the registers needed for PWM.
func InitPWM() {
// use waveform generation