mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 16:33:40 +00:00
machine: refactor pins to be of Pin type
This commit is contained in:
committed by
Ron Evans
parent
421ef04efb
commit
94b8214529
@@ -7,21 +7,21 @@ import (
|
||||
)
|
||||
|
||||
// Configure sets the pin to input or output.
|
||||
func (p GPIO) Configure(config GPIOConfig) {
|
||||
if config.Mode == GPIO_OUTPUT { // set output bit
|
||||
avr.DDRB.SetBits(1 << p.Pin)
|
||||
func (p Pin) Configure(config PinConfig) {
|
||||
if config.Mode == PinOutput { // set output bit
|
||||
avr.DDRB.SetBits(1 << uint8(p))
|
||||
} else { // configure input: clear output bit
|
||||
avr.DDRB.ClearBits(1 << p.Pin)
|
||||
avr.DDRB.ClearBits(1 << uint8(p))
|
||||
}
|
||||
}
|
||||
|
||||
func (p GPIO) getPortMask() (*avr.Register8, uint8) {
|
||||
return avr.PORTB, 1 << p.Pin
|
||||
func (p Pin) getPortMask() (*avr.Register8, uint8) {
|
||||
return avr.PORTB, 1 << uint8(p)
|
||||
}
|
||||
|
||||
// Get returns the current value of a GPIO pin.
|
||||
func (p GPIO) Get() bool {
|
||||
val := avr.PINB.Get() & (1 << p.Pin)
|
||||
func (p Pin) Get() bool {
|
||||
val := avr.PINB.Get() & (1 << uint8(p))
|
||||
return (val > 0)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user