aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYurii Soldak <[email protected]>2021-06-09 02:59:57 +0200
committerRon Evans <[email protected]>2021-06-09 12:27:05 +0200
commit95af44489634d769d95af838b85a5fddc3e0829e (patch)
treeeeaf44fae535088d5d49cfca44e383817f1918a1
parent1f5e4e79aa6b691a54fbfac76b8d1f83650aff4d (diff)
downloadtinygo-95af44489634d769d95af838b85a5fddc3e0829e.tar.gz
tinygo-95af44489634d769d95af838b85a5fddc3e0829e.zip
machine/rp2040: gpio and adc pin definitions
-rw-r--r--src/machine/board_pico.go64
-rw-r--r--src/machine/machine_rp2040.go40
-rw-r--r--src/machine/machine_rp2040_adc.go10
3 files changed, 72 insertions, 42 deletions
diff --git a/src/machine/board_pico.go b/src/machine/board_pico.go
index 6ab32c394..3a4d67b45 100644
--- a/src/machine/board_pico.go
+++ b/src/machine/board_pico.go
@@ -4,45 +4,35 @@ package machine
// GPIO pins
const (
- GP0 Pin = 0
- GP1 Pin = 1
- GP2 Pin = 2
- GP3 Pin = 3
- GP4 Pin = 4
- GP5 Pin = 5
- GP6 Pin = 6
- GP7 Pin = 7
- GP8 Pin = 8
- GP9 Pin = 9
- GP10 Pin = 10
- GP11 Pin = 11
- GP12 Pin = 12
- GP13 Pin = 13
- GP14 Pin = 14
- GP15 Pin = 15
- GP16 Pin = 16
- GP17 Pin = 17
- GP18 Pin = 18
- GP19 Pin = 19
- GP20 Pin = 20
- GP21 Pin = 21
- GP22 Pin = 22
- GP23 Pin = 23
- GP24 Pin = 24
- GP25 Pin = 25
- GP26 Pin = 26
- GP27 Pin = 27
- GP28 Pin = 28
- GP29 Pin = 29
+ GP0 Pin = GPIO0
+ GP1 Pin = GPIO1
+ GP2 Pin = GPIO2
+ GP3 Pin = GPIO3
+ GP4 Pin = GPIO4
+ GP5 Pin = GPIO5
+ GP6 Pin = GPIO6
+ GP7 Pin = GPIO7
+ GP8 Pin = GPIO8
+ GP9 Pin = GPIO9
+ GP10 Pin = GPIO10
+ GP11 Pin = GPIO11
+ GP12 Pin = GPIO12
+ GP13 Pin = GPIO13
+ GP14 Pin = GPIO14
+ GP15 Pin = GPIO15
+ GP16 Pin = GPIO16
+ GP17 Pin = GPIO17
+ GP18 Pin = GPIO18
+ GP19 Pin = GPIO19
+ GP20 Pin = GPIO20
+ GP21 Pin = GPIO21
+ GP22 Pin = GPIO22
+ GP26 Pin = GPIO26
+ GP27 Pin = GPIO27
+ GP28 Pin = GPIO28
// Onboard LED
- LED Pin = GP25
-
- // Analog pins
- ADC0 = GP26
- ADC1 = GP27
- ADC2 = GP28
- ADC3 = GP29
+ LED Pin = GPIO25
// Onboard crystal oscillator frequency, in MHz.
xoscFreq = 12 // MHz
diff --git a/src/machine/machine_rp2040.go b/src/machine/machine_rp2040.go
index ecab6688d..7f0a71c43 100644
--- a/src/machine/machine_rp2040.go
+++ b/src/machine/machine_rp2040.go
@@ -7,6 +7,46 @@ import (
_ "unsafe"
)
+const (
+ // GPIO pins
+ GPIO0 Pin = 0
+ GPIO1 Pin = 1
+ GPIO2 Pin = 2
+ GPIO3 Pin = 3
+ GPIO4 Pin = 4
+ GPIO5 Pin = 5
+ GPIO6 Pin = 6
+ GPIO7 Pin = 7
+ GPIO8 Pin = 8
+ GPIO9 Pin = 9
+ GPIO10 Pin = 10
+ GPIO11 Pin = 11
+ GPIO12 Pin = 12
+ GPIO13 Pin = 13
+ GPIO14 Pin = 14
+ GPIO15 Pin = 15
+ GPIO16 Pin = 16
+ GPIO17 Pin = 17
+ GPIO18 Pin = 18
+ GPIO19 Pin = 19
+ GPIO20 Pin = 20
+ GPIO21 Pin = 21
+ GPIO22 Pin = 22
+ GPIO23 Pin = 23
+ GPIO24 Pin = 24
+ GPIO25 Pin = 25
+ GPIO26 Pin = 26
+ GPIO27 Pin = 27
+ GPIO28 Pin = 28
+ GPIO29 Pin = 29
+
+ // 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_adc.go b/src/machine/machine_rp2040_adc.go
index 2101abbaf..5598c6b73 100644
--- a/src/machine/machine_rp2040_adc.go
+++ b/src/machine/machine_rp2040_adc.go
@@ -22,7 +22,7 @@ func InitADC() {
// Configure configures a ADC pin to be able to be used to read data.
func (a ADC) Configure(config ADCConfig) {
switch a.Pin {
- case GP26, GP27, GP28, GP29:
+ case ADC0, ADC1, ADC2, ADC3:
a.Pin.Configure(PinConfig{Mode: PinAnalog})
default:
// invalid ADC
@@ -47,13 +47,13 @@ func waitForReady() {
func (a ADC) getADCChannel() uint8 {
switch a.Pin {
- case GP26:
+ case ADC0:
return 0
- case GP27:
+ case ADC1:
return 1
- case GP28:
+ case ADC2:
return 2
- case GP29:
+ case ADC3:
return 3
default:
return 0