From 8c86eae924e39568546830079eeb3dc079240475 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sun, 15 Mar 2020 22:06:32 +0100 Subject: [PATCH] avr: clean up ATtiny definitions Add definitions for constants like PB0. --- src/machine/board_digispark.go | 12 +++++------ src/machine/machine_attiny.go | 24 ---------------------- src/machine/machine_attiny85.go | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 30 deletions(-) create mode 100644 src/machine/machine_attiny85.go diff --git a/src/machine/board_digispark.go b/src/machine/board_digispark.go index 1448e345..af89656d 100644 --- a/src/machine/board_digispark.go +++ b/src/machine/board_digispark.go @@ -8,12 +8,12 @@ func CPUFrequency() uint32 { } const ( - P0 Pin = 0 - P1 Pin = 1 - P2 Pin = 2 - P3 Pin = 3 - P4 Pin = 4 - P5 Pin = 5 + P0 Pin = PB0 + P1 Pin = PB1 + P2 Pin = PB2 + P3 Pin = PB3 + P4 Pin = PB4 + P5 Pin = PB5 LED = P1 ) diff --git a/src/machine/machine_attiny.go b/src/machine/machine_attiny.go index dd2444ac..ecafae87 100644 --- a/src/machine/machine_attiny.go +++ b/src/machine/machine_attiny.go @@ -2,30 +2,6 @@ package machine -import ( - "device/avr" - "runtime/volatile" -) - -// Configure sets the pin to input or output. -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 << uint8(p)) - } -} - -func (p Pin) getPortMask() (*volatile.Register8, uint8) { - return avr.PORTB, 1 << uint8(p) -} - -// Get returns the current value of a GPIO pin. -func (p Pin) Get() bool { - val := avr.PINB.Get() & (1 << uint8(p)) - return (val > 0) -} - // UART on the AVR is a dummy implementation. UART has not been implemented for ATtiny // devices. type UART struct { diff --git a/src/machine/machine_attiny85.go b/src/machine/machine_attiny85.go new file mode 100644 index 00000000..b3de12fc --- /dev/null +++ b/src/machine/machine_attiny85.go @@ -0,0 +1,36 @@ +// +build attiny85 + +package machine + +import ( + "device/avr" + "runtime/volatile" +) + +const ( + PB0 Pin = iota + PB1 + PB2 + PB3 + PB4 + PB5 +) + +// Configure sets the pin to input or output. +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 << uint8(p)) + } +} + +func (p Pin) getPortMask() (*volatile.Register8, uint8) { + return avr.PORTB, 1 << uint8(p) +} + +// Get returns the current value of a GPIO pin. +func (p Pin) Get() bool { + val := avr.PINB.Get() & (1 << uint8(p)) + return (val > 0) +}