machine/avr: implement raw GPIO access for bitbanged drivers

This commit is contained in:
Ayke van Laethem
2018-11-20 21:04:43 +01:00
parent 9392ef900d
commit bf4a43ef04
3 changed files with 43 additions and 24 deletions
+8 -17
View File
@@ -23,23 +23,6 @@ func (p GPIO) Configure(config GPIOConfig) {
}
}
// Set changes the value of the GPIO pin. The pin must be configured as output.
func (p GPIO) Set(value bool) {
if value { // set bits
if p.Pin < 8 {
*avr.PORTD |= 1 << p.Pin
} else {
*avr.PORTB |= 1 << (p.Pin - 8)
}
} else { // clear bits
if p.Pin < 8 {
*avr.PORTD &^= 1 << p.Pin
} else {
*avr.PORTB &^= 1 << (p.Pin - 8)
}
}
}
// Get returns the current value of a GPIO pin.
func (p GPIO) Get() bool {
if p.Pin < 8 {
@@ -51,6 +34,14 @@ func (p GPIO) Get() bool {
}
}
func (p GPIO) getPortMask() (*avr.RegValue, uint8) {
if p.Pin < 8 {
return avr.PORTD, 1 << p.Pin
} else {
return avr.PORTB, 1 << (p.Pin - 8)
}
}
// InitPWM initializes the registers needed for PWM.
func InitPWM() {
// use waveform generation