mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
esp32: add support for basic GPIO
GPIO is much more advanced on the ESP32, but this is a starting point. It gets examples/blinky1 to work.
This commit is contained in:
committed by
Ron Evans
parent
0e6d2af028
commit
753162f4e0
@@ -347,7 +347,7 @@ ifneq ($(AVR), 0)
|
||||
@$(MD5SUM) test.hex
|
||||
endif
|
||||
ifneq ($(XTENSA), 0)
|
||||
$(TINYGO) build -size short -o test.bin -target=esp32 examples/serial
|
||||
$(TINYGO) build -size short -o test.bin -target=esp32-wroom-32 examples/blinky1
|
||||
endif
|
||||
$(TINYGO) build -size short -o test.hex -target=hifive1b examples/blinky1
|
||||
@$(MD5SUM) test.hex
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// +build esp32_wroom_32
|
||||
|
||||
package machine
|
||||
|
||||
// Blue LED on the ESP32-WROOM-32 module.
|
||||
const LED = Pin(2)
|
||||
@@ -13,7 +13,52 @@ const (
|
||||
PinInput
|
||||
)
|
||||
|
||||
func (p Pin) Set(value bool)
|
||||
// Configure this pin with the given configuration.
|
||||
func (p Pin) Configure(config PinConfig) {
|
||||
if config.Mode == PinOutput {
|
||||
// Set the 'output enable' bit.
|
||||
if p < 32 {
|
||||
esp.GPIO.ENABLE_W1TS.Set(1 << p)
|
||||
} else {
|
||||
esp.GPIO.ENABLE1_W1TS.Set(1 << (p - 32))
|
||||
}
|
||||
} else {
|
||||
// Clear the 'output enable' bit.
|
||||
if p < 32 {
|
||||
esp.GPIO.ENABLE_W1TC.Set(1 << p)
|
||||
} else {
|
||||
esp.GPIO.ENABLE1_W1TC.Set(1 << (p - 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the pin to high or low.
|
||||
// Warning: only use this on an output pin!
|
||||
func (p Pin) Set(value bool) {
|
||||
if value {
|
||||
if p < 32 {
|
||||
esp.GPIO.OUT_W1TS.Set(1 << p)
|
||||
} else {
|
||||
esp.GPIO.OUT1_W1TS.Set(1 << (p - 32))
|
||||
}
|
||||
} else {
|
||||
if p < 32 {
|
||||
esp.GPIO.OUT_W1TC.Set(1 << p)
|
||||
} else {
|
||||
esp.GPIO.OUT1_W1TC.Set(1 << (p - 32))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the current value of a GPIO pin when the pin is configured as an
|
||||
// input.
|
||||
func (p Pin) Get() bool {
|
||||
if p < 32 {
|
||||
return esp.GPIO.IN.Get()&(1<<p) != 0
|
||||
} else {
|
||||
return esp.GPIO.IN1.Get()&(1<<(p-32)) != 0
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
UART0 = UART{Bus: esp.UART0, Buffer: NewRingBuffer()}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"inherits": ["esp32"],
|
||||
"build-tags": ["esp32_wroom_32"]
|
||||
}
|
||||
Reference in New Issue
Block a user