aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-03-30 13:37:52 +0100
committerRon Evans <[email protected]>2024-04-04 19:34:01 +0200
commit90b0bf646c271157f97aa59ffb2efec7eee4d2ec (patch)
treec6eee325c80df5f83530bd50628111a27134ca5b
parentc55ac9f28ecef310931318f197fbd7f8606875e9 (diff)
downloadtinygo-90b0bf646c271157f97aa59ffb2efec7eee4d2ec.tar.gz
tinygo-90b0bf646c271157f97aa59ffb2efec7eee4d2ec.zip
rp2040: make all RP2040 boards available for simulation
This makes all rp2040 boards available for simulation using -tags=<board_name>. Importantly, this includes the Gopher Badge which I'm working on to add to the TinyGo Playground.
-rw-r--r--GNUmakefile2
-rw-r--r--src/machine/machine_generic.go10
-rw-r--r--src/machine/machine_generic_peripherals.go7
-rw-r--r--src/machine/machine_rp2040.go40
-rw-r--r--src/machine/machine_rp2040_pins.go43
5 files changed, 57 insertions, 45 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 2d7da5c59..18ab754e6 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -525,6 +525,8 @@ ifneq ($(WASM), 0)
@$(MD5SUM) test.wasm
$(TINYGO) build -size short -o test.wasm -tags=mch2022 examples/serial
@$(MD5SUM) test.wasm
+ $(TINYGO) build -size short -o test.wasm -tags=gopher_badge examples/blinky1
+ @$(MD5SUM) test.wasm
endif
# test all targets/boards
$(TINYGO) build -size short -o test.hex -target=pca10040-s132v6 examples/blinky1
diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go
index d1070a9a0..a981f5bff 100644
--- a/src/machine/machine_generic.go
+++ b/src/machine/machine_generic.go
@@ -7,15 +7,14 @@ package machine
const deviceName = "generic"
var (
- UART0 = &UART{0}
- USB = &UART{100}
+ USB = &UART{100}
)
// The Serial port always points to the default UART in a simulated environment.
//
// TODO: perhaps this should be a special serial object that outputs via WASI
// stdout calls.
-var Serial = UART0
+var Serial = hardwareUART0
const (
PinInput PinMode = iota
@@ -176,6 +175,11 @@ func uartRead(bus uint8, buf *byte, bufLen int) int
//export __tinygo_uart_write
func uartWrite(bus uint8, buf *byte, bufLen int) int
+var (
+ hardwareUART0 = &UART{0}
+ hardwareUART1 = &UART{1}
+)
+
// Some objects used by Atmel SAM D chips (samd21, samd51).
// Defined here (without build tag) for convenience.
var (
diff --git a/src/machine/machine_generic_peripherals.go b/src/machine/machine_generic_peripherals.go
index 5491a2698..28539f0e7 100644
--- a/src/machine/machine_generic_peripherals.go
+++ b/src/machine/machine_generic_peripherals.go
@@ -6,6 +6,9 @@ package machine
// boards that define their peripherals in the board file (e.g. board_qtpy.go).
var (
- SPI0 = SPI{0}
- I2C0 = &I2C{0}
+ UART0 = hardwareUART0
+ UART1 = hardwareUART1
+ SPI0 = SPI{0}
+ SPI1 = SPI{1}
+ I2C0 = &I2C{0}
)
diff --git a/src/machine/machine_rp2040.go b/src/machine/machine_rp2040.go
index e76a85e19..45f9f510f 100644
--- a/src/machine/machine_rp2040.go
+++ b/src/machine/machine_rp2040.go
@@ -10,46 +10,6 @@ import (
const deviceName = rp.Device
-const (
- // GPIO pins
- GPIO0 Pin = 0 // peripherals: PWM0 channel A
- GPIO1 Pin = 1 // peripherals: PWM0 channel B
- GPIO2 Pin = 2 // peripherals: PWM1 channel A
- GPIO3 Pin = 3 // peripherals: PWM1 channel B
- GPIO4 Pin = 4 // peripherals: PWM2 channel A
- GPIO5 Pin = 5 // peripherals: PWM2 channel B
- GPIO6 Pin = 6 // peripherals: PWM3 channel A
- GPIO7 Pin = 7 // peripherals: PWM3 channel B
- GPIO8 Pin = 8 // peripherals: PWM4 channel A
- GPIO9 Pin = 9 // peripherals: PWM4 channel B
- GPIO10 Pin = 10 // peripherals: PWM5 channel A
- GPIO11 Pin = 11 // peripherals: PWM5 channel B
- GPIO12 Pin = 12 // peripherals: PWM6 channel A
- GPIO13 Pin = 13 // peripherals: PWM6 channel B
- GPIO14 Pin = 14 // peripherals: PWM7 channel A
- GPIO15 Pin = 15 // peripherals: PWM7 channel B
- GPIO16 Pin = 16 // peripherals: PWM0 channel A
- GPIO17 Pin = 17 // peripherals: PWM0 channel B
- GPIO18 Pin = 18 // peripherals: PWM1 channel A
- GPIO19 Pin = 19 // peripherals: PWM1 channel B
- GPIO20 Pin = 20 // peripherals: PWM2 channel A
- GPIO21 Pin = 21 // peripherals: PWM2 channel B
- GPIO22 Pin = 22 // peripherals: PWM3 channel A
- GPIO23 Pin = 23 // peripherals: PWM3 channel B
- GPIO24 Pin = 24 // peripherals: PWM4 channel A
- GPIO25 Pin = 25 // peripherals: PWM4 channel B
- GPIO26 Pin = 26 // peripherals: PWM5 channel A
- GPIO27 Pin = 27 // peripherals: PWM5 channel B
- GPIO28 Pin = 28 // peripherals: PWM6 channel A
- GPIO29 Pin = 29 // peripherals: PWM6 channel B
-
- // Analog pins
- ADC0 Pin = GPIO26
- ADC1 Pin = GPIO27
- ADC2 Pin = GPIO28
- ADC3 Pin = GPIO29
-)
-
//go:linkname machineInit runtime.machineInit
func machineInit() {
// Reset all peripherals to put system into a known state,
diff --git a/src/machine/machine_rp2040_pins.go b/src/machine/machine_rp2040_pins.go
new file mode 100644
index 000000000..9abbdb002
--- /dev/null
+++ b/src/machine/machine_rp2040_pins.go
@@ -0,0 +1,43 @@
+//go:build rp2040 || ae_rp2040 || badger2040 || challenger_rp2040 || feather_rp2040 || gopher_badge || kb2040 || macropad_rp2040 || nano_rp2040 || pico || qtpy_rp2040 || thingplus_rp2040 || thumby || tufty2040 || waveshare_rp2040_zero || xiao_rp2040
+
+package machine
+
+const (
+ // GPIO pins
+ GPIO0 Pin = 0 // peripherals: PWM0 channel A
+ GPIO1 Pin = 1 // peripherals: PWM0 channel B
+ GPIO2 Pin = 2 // peripherals: PWM1 channel A
+ GPIO3 Pin = 3 // peripherals: PWM1 channel B
+ GPIO4 Pin = 4 // peripherals: PWM2 channel A
+ GPIO5 Pin = 5 // peripherals: PWM2 channel B
+ GPIO6 Pin = 6 // peripherals: PWM3 channel A
+ GPIO7 Pin = 7 // peripherals: PWM3 channel B
+ GPIO8 Pin = 8 // peripherals: PWM4 channel A
+ GPIO9 Pin = 9 // peripherals: PWM4 channel B
+ GPIO10 Pin = 10 // peripherals: PWM5 channel A
+ GPIO11 Pin = 11 // peripherals: PWM5 channel B
+ GPIO12 Pin = 12 // peripherals: PWM6 channel A
+ GPIO13 Pin = 13 // peripherals: PWM6 channel B
+ GPIO14 Pin = 14 // peripherals: PWM7 channel A
+ GPIO15 Pin = 15 // peripherals: PWM7 channel B
+ GPIO16 Pin = 16 // peripherals: PWM0 channel A
+ GPIO17 Pin = 17 // peripherals: PWM0 channel B
+ GPIO18 Pin = 18 // peripherals: PWM1 channel A
+ GPIO19 Pin = 19 // peripherals: PWM1 channel B
+ GPIO20 Pin = 20 // peripherals: PWM2 channel A
+ GPIO21 Pin = 21 // peripherals: PWM2 channel B
+ GPIO22 Pin = 22 // peripherals: PWM3 channel A
+ GPIO23 Pin = 23 // peripherals: PWM3 channel B
+ GPIO24 Pin = 24 // peripherals: PWM4 channel A
+ GPIO25 Pin = 25 // peripherals: PWM4 channel B
+ GPIO26 Pin = 26 // peripherals: PWM5 channel A
+ GPIO27 Pin = 27 // peripherals: PWM5 channel B
+ GPIO28 Pin = 28 // peripherals: PWM6 channel A
+ GPIO29 Pin = 29 // peripherals: PWM6 channel B
+
+ // Analog pins
+ ADC0 Pin = GPIO26
+ ADC1 Pin = GPIO27
+ ADC2 Pin = GPIO28
+ ADC3 Pin = GPIO29
+)