aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-29 23:13:53 +0100
committerRon Evans <[email protected]>2021-11-30 00:47:11 +0100
commit3d73ee77d37683384277f1ea9cef5bb64d2a76f9 (patch)
tree929e3cfb0abbb12cd0759035b4c74ca488cb1da6
parent6b0f2cd6973ca629e9d5076727730837df97e8e2 (diff)
downloadtinygo-3d73ee77d37683384277f1ea9cef5bb64d2a76f9.tar.gz
tinygo-3d73ee77d37683384277f1ea9cef5bb64d2a76f9.zip
machine: add Device constant
This field contains the microcontroller name that we're compiling for, or "generic" if we're not running on a microcontroller.
-rw-r--r--src/machine/machine.go7
-rw-r--r--src/machine/machine_atsamd21.go2
-rw-r--r--src/machine/machine_atsamd51.go2
-rw-r--r--src/machine/machine_avr.go2
-rw-r--r--src/machine/machine_esp32.go2
-rw-r--r--src/machine/machine_esp32c3.go2
-rw-r--r--src/machine/machine_esp8266.go2
-rw-r--r--src/machine/machine_fe310.go2
-rw-r--r--src/machine/machine_gameboyadvance.go4
-rw-r--r--src/machine/machine_generic.go2
-rw-r--r--src/machine/machine_k210.go2
-rw-r--r--src/machine/machine_mimxrt1062.go2
-rw-r--r--src/machine/machine_nrf.go2
-rw-r--r--src/machine/machine_nxpmk66f18.go2
-rw-r--r--src/machine/machine_rp2040.go2
-rw-r--r--src/machine/machine_stm32.go4
16 files changed, 41 insertions, 0 deletions
diff --git a/src/machine/machine.go b/src/machine/machine.go
index aa1a2f6bd..0d7dc53ec 100644
--- a/src/machine/machine.go
+++ b/src/machine/machine.go
@@ -10,6 +10,13 @@ var (
ErrNoPinChangeChannel = errors.New("machine: no channel available for pin interrupt")
)
+// Device is the running program's chip name, such as "ATSAMD51J19A" or
+// "nrf52840". It is not the same as the CPU name.
+//
+// The constant is some hardcoded default value if the program does not target a
+// particular chip but instead runs in WebAssembly for example.
+const Device = deviceName
+
// PinMode sets the direction and pull mode of the pin. For example, PinOutput
// sets the pin as an output and PinInputPullup sets the pin as an input with a
// pull-up.
diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go
index 5bcf72556..cb151703a 100644
--- a/src/machine/machine_atsamd21.go
+++ b/src/machine/machine_atsamd21.go
@@ -16,6 +16,8 @@ import (
"unsafe"
)
+const deviceName = sam.Device
+
const (
PinAnalog PinMode = 1
PinSERCOM PinMode = 2
diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go
index 8723e82ae..9b6780416 100644
--- a/src/machine/machine_atsamd51.go
+++ b/src/machine/machine_atsamd51.go
@@ -16,6 +16,8 @@ import (
"unsafe"
)
+const deviceName = sam.Device
+
func CPUFrequency() uint32 {
return 120000000
}
diff --git a/src/machine/machine_avr.go b/src/machine/machine_avr.go
index ce9b7803e..22863846c 100644
--- a/src/machine/machine_avr.go
+++ b/src/machine/machine_avr.go
@@ -8,6 +8,8 @@ import (
"unsafe"
)
+const deviceName = avr.DEVICE
+
const (
PinInput PinMode = iota
PinInputPullup
diff --git a/src/machine/machine_esp32.go b/src/machine/machine_esp32.go
index 90dc2c664..31a324829 100644
--- a/src/machine/machine_esp32.go
+++ b/src/machine/machine_esp32.go
@@ -9,6 +9,8 @@ import (
"unsafe"
)
+const deviceName = esp.Device
+
const peripheralClock = 80000000 // 80MHz
// CPUFrequency returns the current CPU frequency of the chip.
diff --git a/src/machine/machine_esp32c3.go b/src/machine/machine_esp32c3.go
index 0e45ed461..1393f2cdd 100644
--- a/src/machine/machine_esp32c3.go
+++ b/src/machine/machine_esp32c3.go
@@ -8,6 +8,8 @@ import (
"unsafe"
)
+const deviceName = esp.Device
+
// CPUFrequency returns the current CPU frequency of the chip.
// Currently it is a fixed frequency but it may allow changing in the future.
func CPUFrequency() uint32 {
diff --git a/src/machine/machine_esp8266.go b/src/machine/machine_esp8266.go
index 7e98b5970..a5fbbc672 100644
--- a/src/machine/machine_esp8266.go
+++ b/src/machine/machine_esp8266.go
@@ -7,6 +7,8 @@ import (
"runtime/volatile"
)
+const deviceName = esp.Device
+
func CPUFrequency() uint32 {
return 80000000 // 80MHz
}
diff --git a/src/machine/machine_fe310.go b/src/machine/machine_fe310.go
index 5fdf581d7..609571ea2 100644
--- a/src/machine/machine_fe310.go
+++ b/src/machine/machine_fe310.go
@@ -8,6 +8,8 @@ import (
"unsafe"
)
+const deviceName = sifive.Device
+
func CPUFrequency() uint32 {
return 320000000 // 320MHz
}
diff --git a/src/machine/machine_gameboyadvance.go b/src/machine/machine_gameboyadvance.go
index 9387749e4..c35b7ef3b 100644
--- a/src/machine/machine_gameboyadvance.go
+++ b/src/machine/machine_gameboyadvance.go
@@ -9,6 +9,10 @@ import (
"unsafe"
)
+// Not sure what name to pick here. Not using ARM7TDMI because that's the CPU
+// name, not the device name.
+const deviceName = "GBA"
+
// Interrupt numbers as used on the GameBoy Advance. Register them with
// runtime/interrupt.New.
const (
diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go
index 7cf89a86b..cbcc98ecf 100644
--- a/src/machine/machine_generic.go
+++ b/src/machine/machine_generic.go
@@ -4,6 +4,8 @@ package machine
// Dummy machine package that calls out to external functions.
+const deviceName = "generic"
+
var (
UART0 = &UART{0}
USB = &UART{100}
diff --git a/src/machine/machine_k210.go b/src/machine/machine_k210.go
index 232c942bf..4a8bc98f1 100644
--- a/src/machine/machine_k210.go
+++ b/src/machine/machine_k210.go
@@ -10,6 +10,8 @@ import (
"unsafe"
)
+const deviceName = kendryte.Device
+
func CPUFrequency() uint32 {
return 390000000
}
diff --git a/src/machine/machine_mimxrt1062.go b/src/machine/machine_mimxrt1062.go
index 38cb71f7e..bcb06021a 100644
--- a/src/machine/machine_mimxrt1062.go
+++ b/src/machine/machine_mimxrt1062.go
@@ -11,6 +11,8 @@ import (
// Peripheral abstraction layer for the MIMXRT1062
+const deviceName = nxp.Device
+
func CPUFrequency() uint32 {
return 600000000
}
diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go
index a288298c7..635e314ba 100644
--- a/src/machine/machine_nrf.go
+++ b/src/machine/machine_nrf.go
@@ -13,6 +13,8 @@ var (
ErrTxInvalidSliceSize = errors.New("SPI write and read slices must be same size")
)
+const deviceName = nrf.Device
+
const (
PinInput PinMode = (nrf.GPIO_PIN_CNF_DIR_Input << nrf.GPIO_PIN_CNF_DIR_Pos) | (nrf.GPIO_PIN_CNF_INPUT_Connect << nrf.GPIO_PIN_CNF_INPUT_Pos)
PinInputPullup PinMode = PinInput | (nrf.GPIO_PIN_CNF_PULL_Pullup << nrf.GPIO_PIN_CNF_PULL_Pos)
diff --git a/src/machine/machine_nxpmk66f18.go b/src/machine/machine_nxpmk66f18.go
index 35e48e5c5..aaecee536 100644
--- a/src/machine/machine_nxpmk66f18.go
+++ b/src/machine/machine_nxpmk66f18.go
@@ -37,6 +37,8 @@ import (
"unsafe"
)
+const deviceName = nxp.Device
+
const (
PinInput PinMode = iota
PinInputPullUp
diff --git a/src/machine/machine_rp2040.go b/src/machine/machine_rp2040.go
index 1d86f2082..dd8b5c708 100644
--- a/src/machine/machine_rp2040.go
+++ b/src/machine/machine_rp2040.go
@@ -8,6 +8,8 @@ import (
"runtime/interrupt"
)
+const deviceName = rp.Device
+
const (
// GPIO pins
GPIO0 Pin = 0
diff --git a/src/machine/machine_stm32.go b/src/machine/machine_stm32.go
index 865ab68fe..01748628d 100644
--- a/src/machine/machine_stm32.go
+++ b/src/machine/machine_stm32.go
@@ -2,6 +2,10 @@
package machine
+import "device/stm32"
+
+const deviceName = stm32.Device
+
// Peripheral abstraction layer for the stm32.
const (