mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-10 14:03:39 +00:00
Minimal NXP/Teensy support
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// +build nxp,mk66f18,teensy36
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/nxp"
|
||||
)
|
||||
|
||||
//go:keep
|
||||
//go:section .flashconfig
|
||||
var FlashConfig = [16]byte{
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xDE, 0xF9, 0xFF, 0xFF,
|
||||
}
|
||||
|
||||
func CPUFrequency() uint32 {
|
||||
return 180000000
|
||||
}
|
||||
|
||||
// LED on the Teensy
|
||||
const LED Pin = 13
|
||||
|
||||
var _pinRegisters [64]pinRegisters
|
||||
|
||||
func init() {
|
||||
_pinRegisters[13].Bit = 5
|
||||
_pinRegisters[13].PCR = &nxp.PORTC.PCR5
|
||||
_pinRegisters[13].PDOR = nxp.GPIOC.PDOR.Bit(5)
|
||||
_pinRegisters[13].PSOR = nxp.GPIOC.PSOR.Bit(5)
|
||||
_pinRegisters[13].PCOR = nxp.GPIOC.PCOR.Bit(5)
|
||||
_pinRegisters[13].PTOR = nxp.GPIOC.PTOR.Bit(5)
|
||||
_pinRegisters[13].PDIR = nxp.GPIOC.PDIR.Bit(5)
|
||||
_pinRegisters[13].PDDR = nxp.GPIOC.PDDR.Bit(5)
|
||||
}
|
||||
|
||||
//go:inline
|
||||
func (p Pin) registers() pinRegisters {
|
||||
return _pinRegisters[p]
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// +build nxp
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/arm"
|
||||
"device/nxp"
|
||||
)
|
||||
|
||||
type PinMode uint8
|
||||
|
||||
const (
|
||||
PinInput PinMode = iota
|
||||
PinOutput
|
||||
)
|
||||
|
||||
// Stop enters STOP (deep sleep) mode
|
||||
func Stop() {
|
||||
// set SLEEPDEEP to enable deep sleep
|
||||
nxp.SystemControl.SCR.SetBits(nxp.SystemControl_SCR_SLEEPDEEP)
|
||||
|
||||
// enter STOP mode
|
||||
arm.Asm("wfi")
|
||||
}
|
||||
|
||||
// Wait enters WAIT (sleep) mode
|
||||
func Wait() {
|
||||
// clear SLEEPDEEP bit to disable deep sleep
|
||||
nxp.SystemControl.SCR.ClearBits(nxp.SystemControl_SCR_SLEEPDEEP)
|
||||
|
||||
// enter WAIT mode
|
||||
arm.Asm("wfi")
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
// +build nxp,mk66f18
|
||||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/nxp"
|
||||
"runtime/volatile"
|
||||
)
|
||||
|
||||
const (
|
||||
PortControlRegisterSRE = nxp.PORT_PCR0_SRE
|
||||
PortControlRegisterDSE = nxp.PORT_PCR0_DSE
|
||||
PortControlRegisterODE = nxp.PORT_PCR0_ODE
|
||||
)
|
||||
|
||||
func PortControlRegisterMUX(v uint8) uint32 {
|
||||
return (uint32(v) << nxp.PORT_PCR0_MUX_Pos) & nxp.PORT_PCR0_MUX_Msk
|
||||
}
|
||||
|
||||
type pinRegisters struct {
|
||||
Bit uintptr
|
||||
PCR *volatile.Register32
|
||||
PDOR *volatile.BitRegister
|
||||
PSOR *volatile.BitRegister
|
||||
PCOR *volatile.BitRegister
|
||||
PTOR *volatile.BitRegister
|
||||
PDIR *volatile.BitRegister
|
||||
PDDR *volatile.BitRegister
|
||||
}
|
||||
|
||||
// Configure this pin with the given configuration.
|
||||
func (p Pin) Configure(config PinConfig) {
|
||||
switch config.Mode {
|
||||
case PinInput:
|
||||
panic("todo")
|
||||
|
||||
case PinOutput:
|
||||
p.registers().PDDR.Set()
|
||||
p.registers().PCR.SetBits(PortControlRegisterSRE | PortControlRegisterDSE | PortControlRegisterMUX(1))
|
||||
p.registers().PCR.ClearBits(PortControlRegisterODE)
|
||||
}
|
||||
}
|
||||
|
||||
// Set changes the value of the GPIO pin. The pin must be configured as output.
|
||||
func (p Pin) Set(value bool) {
|
||||
if value {
|
||||
p.registers().PSOR.Set()
|
||||
} else {
|
||||
p.registers().PCOR.Set()
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the current value of a GPIO pin.
|
||||
func (p Pin) Get() bool {
|
||||
return p.registers().PDIR.Get()
|
||||
}
|
||||
Reference in New Issue
Block a user