esp32: export machine.PortMask* for bitbanging implementations
This is useful for some drivers, in particular for the WS2812 driver.
Этот коммит содержится в:
родитель
475135f546
коммит
98dbbbfda6
1 изменённых файлов: 48 добавлений и 11 удалений
|
@ -2,10 +2,19 @@
|
||||||
|
|
||||||
package machine
|
package machine
|
||||||
|
|
||||||
import "device/esp"
|
import (
|
||||||
|
"device/esp"
|
||||||
|
"runtime/volatile"
|
||||||
|
)
|
||||||
|
|
||||||
const peripheralClock = 80000000 // 80MHz
|
const peripheralClock = 80000000 // 80MHz
|
||||||
|
|
||||||
|
// CPUFrequency returns the current CPU frequency of the chip.
|
||||||
|
// Currently it is a fixed frequency but it may allow changing in the future.
|
||||||
|
func CPUFrequency() uint32 {
|
||||||
|
return 160e6 // 160MHz
|
||||||
|
}
|
||||||
|
|
||||||
type PinMode uint8
|
type PinMode uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -36,17 +45,45 @@ func (p Pin) Configure(config PinConfig) {
|
||||||
// Warning: only use this on an output pin!
|
// Warning: only use this on an output pin!
|
||||||
func (p Pin) Set(value bool) {
|
func (p Pin) Set(value bool) {
|
||||||
if value {
|
if value {
|
||||||
if p < 32 {
|
reg, mask := p.portMaskSet()
|
||||||
esp.GPIO.OUT_W1TS.Set(1 << p)
|
reg.Set(mask)
|
||||||
} else {
|
|
||||||
esp.GPIO.OUT1_W1TS.Set(1 << (p - 32))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if p < 32 {
|
reg, mask := p.portMaskClear()
|
||||||
esp.GPIO.OUT_W1TC.Set(1 << p)
|
reg.Set(mask)
|
||||||
} else {
|
}
|
||||||
esp.GPIO.OUT1_W1TC.Set(1 << (p - 32))
|
}
|
||||||
}
|
|
||||||
|
// Return the register and mask to enable a given GPIO pin. This can be used to
|
||||||
|
// implement bit-banged drivers.
|
||||||
|
//
|
||||||
|
// Warning: only use this on an output pin!
|
||||||
|
func (p Pin) PortMaskSet() (*uint32, uint32) {
|
||||||
|
reg, mask := p.portMaskSet()
|
||||||
|
return ®.Reg, mask
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the register and mask to disable a given GPIO pin. This can be used to
|
||||||
|
// implement bit-banged drivers.
|
||||||
|
//
|
||||||
|
// Warning: only use this on an output pin!
|
||||||
|
func (p Pin) PortMaskClear() (*uint32, uint32) {
|
||||||
|
reg, mask := p.portMaskClear()
|
||||||
|
return ®.Reg, mask
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Pin) portMaskSet() (*volatile.Register32, uint32) {
|
||||||
|
if p < 32 {
|
||||||
|
return &esp.GPIO.OUT_W1TS, 1 << p
|
||||||
|
} else {
|
||||||
|
return &esp.GPIO.OUT1_W1TS, 1 << (p - 32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Pin) portMaskClear() (*volatile.Register32, uint32) {
|
||||||
|
if p < 32 {
|
||||||
|
return &esp.GPIO.OUT_W1TC, 1 << p
|
||||||
|
} else {
|
||||||
|
return &esp.GPIO.OUT1_W1TC, 1 << (p - 32)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче