aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKenneth Bell <[email protected]>2021-05-31 16:46:53 -0700
committerRon Evans <[email protected]>2021-06-11 09:07:32 +0200
commitc017ed224247c1627dcc81dad2d69fb266671678 (patch)
treeeeb1115c7ce4307250179a24f33e92804befbf24
parentd62a9e24e579dccc6ea849cf9044cec837e923f1 (diff)
downloadtinygo-c017ed224247c1627dcc81dad2d69fb266671678.tar.gz
tinygo-c017ed224247c1627dcc81dad2d69fb266671678.zip
bluepill: GPIO PinInputPullup / PinInputPulldown
Other chips support explicit control of pull-up vs pull-down for GPIO input. Support that with bluepill also. PinInputPullUpDown is maintained for back-compat. It is implicit pull-down.
-rw-r--r--src/machine/machine_stm32f103.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/machine/machine_stm32f103.go b/src/machine/machine_stm32f103.go
index 614697674..86ed14113 100644
--- a/src/machine/machine_stm32f103.go
+++ b/src/machine/machine_stm32f103.go
@@ -37,6 +37,11 @@ const (
PinOutputModeGPOpenDrain PinMode = 4 // Output mode general purpose open drain
PinOutputModeAltPushPull PinMode = 8 // Output mode alt. purpose push/pull
PinOutputModeAltOpenDrain PinMode = 12 // Output mode alt. purpose open drain
+
+ // Pull-up vs Pull down is not part of the CNF0 / CNF1 bits, but is
+ // controlled by PxODR. Encoded using the 'spare' bit 5.
+ PinInputPulldown PinMode = PinInputModePullUpDown
+ PinInputPullup PinMode = PinInputModePullUpDown | 0x10
)
// Pin constants for all stm32f103 package sizes
@@ -157,6 +162,16 @@ func (p Pin) Configure(config PinConfig) {
} else {
port.CRH.ReplaceBits(uint32(config.Mode), 0xf, pos)
}
+
+ // If configured for input pull-up or pull-down, set ODR
+ // for desired pull-up or pull-down.
+ if (config.Mode & 0xf) == PinInputModePullUpDown {
+ var pullup uint32
+ if config.Mode == PinInputPullup {
+ pullup = 1
+ }
+ port.ODR.ReplaceBits(pullup, 0x1, pin)
+ }
}
func (p Pin) getPort() *stm32.GPIO_Type {
@@ -215,6 +230,47 @@ func enableAltFuncClock(bus unsafe.Pointer) {
}
}
+func (p Pin) registerInterrupt() interrupt.Interrupt {
+ pin := uint8(p) % 16
+
+ switch pin {
+ case 0:
+ return interrupt.New(stm32.IRQ_EXTI0, func(interrupt.Interrupt) { handlePinInterrupt(0) })
+ case 1:
+ return interrupt.New(stm32.IRQ_EXTI1, func(interrupt.Interrupt) { handlePinInterrupt(1) })
+ case 2:
+ return interrupt.New(stm32.IRQ_EXTI2, func(interrupt.Interrupt) { handlePinInterrupt(2) })
+ case 3:
+ return interrupt.New(stm32.IRQ_EXTI3, func(interrupt.Interrupt) { handlePinInterrupt(3) })
+ case 4:
+ return interrupt.New(stm32.IRQ_EXTI4, func(interrupt.Interrupt) { handlePinInterrupt(4) })
+ case 5:
+ return interrupt.New(stm32.IRQ_EXTI9_5, func(interrupt.Interrupt) { handlePinInterrupt(5) })
+ case 6:
+ return interrupt.New(stm32.IRQ_EXTI9_5, func(interrupt.Interrupt) { handlePinInterrupt(6) })
+ case 7:
+ return interrupt.New(stm32.IRQ_EXTI9_5, func(interrupt.Interrupt) { handlePinInterrupt(7) })
+ case 8:
+ return interrupt.New(stm32.IRQ_EXTI9_5, func(interrupt.Interrupt) { handlePinInterrupt(8) })
+ case 9:
+ return interrupt.New(stm32.IRQ_EXTI9_5, func(interrupt.Interrupt) { handlePinInterrupt(9) })
+ case 10:
+ return interrupt.New(stm32.IRQ_EXTI15_10, func(interrupt.Interrupt) { handlePinInterrupt(10) })
+ case 11:
+ return interrupt.New(stm32.IRQ_EXTI15_10, func(interrupt.Interrupt) { handlePinInterrupt(11) })
+ case 12:
+ return interrupt.New(stm32.IRQ_EXTI15_10, func(interrupt.Interrupt) { handlePinInterrupt(12) })
+ case 13:
+ return interrupt.New(stm32.IRQ_EXTI15_10, func(interrupt.Interrupt) { handlePinInterrupt(13) })
+ case 14:
+ return interrupt.New(stm32.IRQ_EXTI15_10, func(interrupt.Interrupt) { handlePinInterrupt(14) })
+ case 15:
+ return interrupt.New(stm32.IRQ_EXTI15_10, func(interrupt.Interrupt) { handlePinInterrupt(15) })
+ }
+
+ return interrupt.Interrupt{}
+}
+
//---------- UART related code
// Configure the TX and RX pins