mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 20:43:40 +00:00
machine/avr: implement raw GPIO access for bitbanged drivers
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user