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.
Этот коммит содержится в:
родитель
0e6d2af028
коммит
753162f4e0
4 изменённых файлов: 57 добавлений и 2 удалений
2
Makefile
2
Makefile
|
@ -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
|
||||
|
|
6
src/machine/board_esp32-wroom-32.go
Обычный файл
6
src/machine/board_esp32-wroom-32.go
Обычный файл
|
@ -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()}
|
||||
|
|
4
targets/esp32-wroom-32.json
Обычный файл
4
targets/esp32-wroom-32.json
Обычный файл
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"inherits": ["esp32"],
|
||||
"build-tags": ["esp32_wroom_32"]
|
||||
}
|
Загрузка…
Создание таблицы
Сослаться в новой задаче