all: move Register{8,16,32} values into runtime/volatile

This avoids duplication of code. None of the smoke tests have changed
their output.
This commit is contained in:
Ayke van Laethem
2019-06-06 13:50:46 +02:00
committed by Ron Evans
parent 66aca428ba
commit 9673ad3774
7 changed files with 189 additions and 236 deletions
+2 -1
View File
@@ -4,6 +4,7 @@ package machine
import (
"device/avr"
"runtime/volatile"
)
// Configure sets the pin to input or output.
@@ -34,7 +35,7 @@ func (p Pin) Get() bool {
}
}
func (p Pin) getPortMask() (*avr.Register8, uint8) {
func (p Pin) getPortMask() (*volatile.Register8, uint8) {
if p < 8 {
return avr.PORTD, 1 << uint8(p)
} else {
+2 -1
View File
@@ -4,6 +4,7 @@ package machine
import (
"device/avr"
"runtime/volatile"
)
// Configure sets the pin to input or output.
@@ -15,7 +16,7 @@ func (p Pin) Configure(config PinConfig) {
}
}
func (p Pin) getPortMask() (*avr.Register8, uint8) {
func (p Pin) getPortMask() (*volatile.Register8, uint8) {
return avr.PORTB, 1 << uint8(p)
}
+3 -2
View File
@@ -4,6 +4,7 @@ package machine
import (
"device/avr"
"runtime/volatile"
)
type PinMode uint8
@@ -30,7 +31,7 @@ func (p Pin) Set(value bool) {
// Warning: there are no separate pin set/clear registers on the AVR. The
// returned mask is only valid as long as no other pin in the same port has been
// changed.
func (p Pin) PortMaskSet() (*avr.Register8, uint8) {
func (p Pin) PortMaskSet() (*volatile.Register8, uint8) {
port, mask := p.getPortMask()
return port, port.Get() | mask
}
@@ -41,7 +42,7 @@ func (p Pin) PortMaskSet() (*avr.Register8, uint8) {
// Warning: there are no separate pin set/clear registers on the AVR. The
// returned mask is only valid as long as no other pin in the same port has been
// changed.
func (p Pin) PortMaskClear() (*avr.Register8, uint8) {
func (p Pin) PortMaskClear() (*volatile.Register8, uint8) {
port, mask := p.getPortMask()
return port, port.Get() &^ mask
}
+6 -6
View File
@@ -4,9 +4,9 @@ package machine
import (
"bytes"
"device/sam"
"encoding/binary"
"errors"
"runtime/volatile"
)
const deviceDescriptorSize = 18
@@ -484,11 +484,11 @@ const (
// RoReg8 Reserved1[0x5];
// } UsbDeviceDescBank;
type usbDeviceDescBank struct {
ADDR sam.Register32
PCKSIZE sam.Register32
EXTREG sam.Register16
STATUS_BK sam.Register8
_reserved [5]sam.Register8
ADDR volatile.Register32
PCKSIZE volatile.Register32
EXTREG volatile.Register16
STATUS_BK volatile.Register8
_reserved [5]volatile.Register8
}
type usbDeviceDescriptor struct {