mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-13 07:23:39 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b5ad81c884 | |||
| c2fb1e776a | |||
| 895c542076 | |||
| e91fae5756 | |||
| f52ecf3054 | |||
| 725864d8dc |
@@ -1,3 +1,87 @@
|
|||||||
|
0.26.0
|
||||||
|
---
|
||||||
|
|
||||||
|
* **general**
|
||||||
|
- remove support for LLVM 13
|
||||||
|
- remove calls to deprecated ioutil package
|
||||||
|
- move from `os.IsFoo` to `errors.Is(err, ErrFoo)`
|
||||||
|
- fix for builds using an Android host
|
||||||
|
- make interp timeout configurable from command line
|
||||||
|
- ignore ports with VID/PID if there is no candidates
|
||||||
|
- drop support for Go 1.16 and Go 1.17
|
||||||
|
- update serial package to v1.3.5 for latest bugfixes
|
||||||
|
- remove GOARM from `tinygo info`
|
||||||
|
- add flag for setting the goroutine stack size
|
||||||
|
- add serial port monitoring functionality
|
||||||
|
* **compiler**
|
||||||
|
- `cgo`: implement support for static functions
|
||||||
|
- `cgo`: fix panic when FuncType.Results is nil
|
||||||
|
- `compiler`: add aliases for `edwards25519/field.feMul` and `field.feSquare`
|
||||||
|
- `compiler`: fix incorrect DWARF type in some generic parameters
|
||||||
|
- `compiler`: use LLVM math builtins everywhere
|
||||||
|
- `compiler`: replace some math operation bodies with LLVM intrinsics
|
||||||
|
- `compiler`: replace math aliases with intrinsics
|
||||||
|
- `compiler`: fix `unsafe.Sizeof` for chan and map values
|
||||||
|
- `compileopts`: use tags parser from buildutil
|
||||||
|
- `compileopts`: use backticks for regexp to avoid extra escapes
|
||||||
|
- `compileopts`: fail fast on duplicate values in target field slices
|
||||||
|
- `compileopts`: fix windows/arm target triple
|
||||||
|
- `compileopts`: improve error handling when loading target/*.json
|
||||||
|
- `compileopts`: add support for stlink-dap programmer
|
||||||
|
- `compileopts`: do not complain about `-no-debug` on MacOS
|
||||||
|
- `goenv`: support `GOOS=android`
|
||||||
|
- `interp`: fix reading from external global
|
||||||
|
- `loader`: fix link error for `crypto/internal/boring/sig.StandardCrypto`
|
||||||
|
* **standard library**
|
||||||
|
- rename assembly files to .S extension
|
||||||
|
- `machine`: add PWM peripheral comments to pins
|
||||||
|
- `machine`: improve UARTParity slightly
|
||||||
|
- `machine`: do not export DFU_MAGIC_* constants on nrf52840
|
||||||
|
- `machine`: rename `PinInputPullUp`/`PinInputPullDown`
|
||||||
|
- `machine`: add `KHz`, `MHz`, `GHz` constants, deprecate `TWI_FREQ_*` constants
|
||||||
|
- `machine`: remove level triggered pin interrupts
|
||||||
|
- `machine`: do not expose `RESET_MAGIC_VALUE`
|
||||||
|
- `machine`: use `NoPin` constant where appropriate (instead of `0` for example)
|
||||||
|
- `net`: sync net.go with Go 1.18 stdlib
|
||||||
|
- `os`: add `SyscallError.Timeout`
|
||||||
|
- `os`: add `ErrProcessDone` error
|
||||||
|
- `reflect`: implement `CanInterface` and fix string `Index`
|
||||||
|
- `runtime`: make `MemStats` available to leaking collector
|
||||||
|
- `runtime`: add `MemStats.TotalAlloc`
|
||||||
|
- `runtime`: add `MemStats.Mallocs` and `Frees`
|
||||||
|
- `runtime`: add support for `time.NewTimer` and `time.NewTicker`
|
||||||
|
- `runtime`: implement `resetTimer`
|
||||||
|
- `runtime`: ensure some headroom for the GC to run
|
||||||
|
- `runtime`: make gc and scheduler asserts settable with build tags
|
||||||
|
- `runtime/pprof`: add `WriteHeapProfile`
|
||||||
|
- `runtime/pprof`: `runtime/trace`: stub some additional functions
|
||||||
|
- `sync`: implement `Map.LoadAndDelete`
|
||||||
|
- `syscall`: group WASI consts by purpose
|
||||||
|
- `syscall`: add WASI `{D,R}SYNC`, `NONBLOCK` FD flags
|
||||||
|
- `syscall`: add ENOTCONN on darwin
|
||||||
|
- `testing`: add support for -benchmem
|
||||||
|
* **targets**
|
||||||
|
- remove USB vid/pid pair of bootloader
|
||||||
|
- `esp32c3`: remove unused `UARTStopBits` constants
|
||||||
|
- `nrf`: implement `GetRNG` function
|
||||||
|
- `nrf`: `rp2040`: add `machine.ReadTemperature`
|
||||||
|
- `nrf52`: cleanup s140v6 and s140v7 uf2 targets
|
||||||
|
- `rp2040`: implement semi-random RNG based on ROSC based on pico-sdk
|
||||||
|
- `wasm`: add summary of wasm examples and fix callback bug
|
||||||
|
- `wasm`: do not allow undefined symbols (`--allow-undefined`)
|
||||||
|
- `wasm`: make sure buffers returned by `malloc` are kept until `free` is called
|
||||||
|
- `windows`: save and restore xmm registers when switching goroutines
|
||||||
|
* **boards**
|
||||||
|
- add Pimoroni's Tufty2040
|
||||||
|
- add XIAO ESP32C3
|
||||||
|
- add Adafruit QT2040
|
||||||
|
- add Adafruit QT Py RP2040
|
||||||
|
- `esp32c3-12f`: `matrixportal-m4`: `p1am-100`: remove duplicate build tags
|
||||||
|
- `hifive1-qemu`: remove this emulated board
|
||||||
|
- `wioterminal`: add UART3 for RTL8720DN
|
||||||
|
- `xiao-ble`: fix usbpid
|
||||||
|
|
||||||
|
|
||||||
0.25.0
|
0.25.0
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
+11
-14
@@ -700,21 +700,18 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
|
|||||||
// Add embedded files.
|
// Add embedded files.
|
||||||
linkerDependencies = append(linkerDependencies, embedFileObjects...)
|
linkerDependencies = append(linkerDependencies, embedFileObjects...)
|
||||||
|
|
||||||
|
// Determine whether the compilation configuration would result in debug
|
||||||
|
// (DWARF) information in the object files.
|
||||||
|
var hasDebug = true
|
||||||
|
if config.GOOS() == "darwin" {
|
||||||
|
// Debug information isn't stored in the binary itself on MacOS but
|
||||||
|
// is left in the object files by default. The binary does store the
|
||||||
|
// path to these object files though.
|
||||||
|
hasDebug = false
|
||||||
|
}
|
||||||
|
|
||||||
// Strip debug information with -no-debug.
|
// Strip debug information with -no-debug.
|
||||||
if !config.Debug() {
|
if hasDebug && !config.Debug() {
|
||||||
for _, tag := range config.BuildTags() {
|
|
||||||
if tag == "baremetal" {
|
|
||||||
// Don't use -no-debug on baremetal targets. It makes no sense:
|
|
||||||
// the debug information isn't flashed to the device anyway.
|
|
||||||
return fmt.Errorf("stripping debug information is unnecessary for baremetal targets")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if config.GOOS() == "darwin" {
|
|
||||||
// Debug information isn't stored in the binary itself on MacOS but
|
|
||||||
// is left in the object files by default. The binary does store the
|
|
||||||
// path to these object files though.
|
|
||||||
return errors.New("cannot remove debug information: MacOS doesn't store debug info in the executable by default")
|
|
||||||
}
|
|
||||||
if config.Target.Linker == "wasm-ld" {
|
if config.Target.Linker == "wasm-ld" {
|
||||||
// Don't just strip debug information, also compress relocations
|
// Don't just strip debug information, also compress relocations
|
||||||
// while we're at it. Relocations can only be compressed when debug
|
// while we're at it. Relocations can only be compressed when debug
|
||||||
|
|||||||
@@ -948,6 +948,9 @@ func (p *cgoPackage) isEquivalentAST(a, b ast.Node) bool {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if node == nil || b == nil {
|
||||||
|
return node == b
|
||||||
|
}
|
||||||
if len(node.List) != len(b.List) {
|
if len(node.List) != len(b.List) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,6 +115,84 @@ func TestCGo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_cgoPackage_isEquivalentAST(t *testing.T) {
|
||||||
|
fieldA := &ast.Field{Type: &ast.BasicLit{Kind: token.STRING, Value: "a"}}
|
||||||
|
fieldB := &ast.Field{Type: &ast.BasicLit{Kind: token.STRING, Value: "b"}}
|
||||||
|
listOfFieldA := &ast.FieldList{List: []*ast.Field{fieldA}}
|
||||||
|
listOfFieldB := &ast.FieldList{List: []*ast.Field{fieldB}}
|
||||||
|
funcDeclA := &ast.FuncDecl{Name: &ast.Ident{Name: "a"}, Type: &ast.FuncType{Params: &ast.FieldList{}, Results: listOfFieldA}}
|
||||||
|
funcDeclB := &ast.FuncDecl{Name: &ast.Ident{Name: "b"}, Type: &ast.FuncType{Params: &ast.FieldList{}, Results: listOfFieldB}}
|
||||||
|
funcDeclNoResults := &ast.FuncDecl{Name: &ast.Ident{Name: "C"}, Type: &ast.FuncType{Params: &ast.FieldList{}}}
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
a, b ast.Node
|
||||||
|
expected bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "both nil",
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "not same type",
|
||||||
|
a: fieldA,
|
||||||
|
b: &ast.FuncDecl{},
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Field same",
|
||||||
|
a: fieldA,
|
||||||
|
b: fieldA,
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Field different",
|
||||||
|
a: fieldA,
|
||||||
|
b: fieldB,
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FuncDecl Type Results nil",
|
||||||
|
a: funcDeclNoResults,
|
||||||
|
b: funcDeclNoResults,
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FuncDecl Type Results same",
|
||||||
|
a: funcDeclA,
|
||||||
|
b: funcDeclA,
|
||||||
|
expected: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FuncDecl Type Results different",
|
||||||
|
a: funcDeclA,
|
||||||
|
b: funcDeclB,
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FuncDecl Type Results a nil",
|
||||||
|
a: funcDeclNoResults,
|
||||||
|
b: funcDeclB,
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "FuncDecl Type Results b nil",
|
||||||
|
a: funcDeclA,
|
||||||
|
b: funcDeclNoResults,
|
||||||
|
expected: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
p := &cgoPackage{}
|
||||||
|
if got := p.isEquivalentAST(tc.a, tc.b); tc.expected != got {
|
||||||
|
t.Errorf("expected %v, got %v", tc.expected, got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// simpleImporter implements the types.Importer interface, but only allows
|
// simpleImporter implements the types.Importer interface, but only allows
|
||||||
// importing the unsafe package.
|
// importing the unsafe package.
|
||||||
type simpleImporter struct {
|
type simpleImporter struct {
|
||||||
|
|||||||
@@ -377,8 +377,8 @@ func (c *Config) VerifyIR() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Debug returns whether debug (DWARF) information should be retained by the
|
// Debug returns whether debug (DWARF) information should be retained by the
|
||||||
// linker. By default, debug information is retained but it can be removed with
|
// linker. By default, debug information is retained, but it can be removed
|
||||||
// the -no-debug flag.
|
// with the -no-debug flag.
|
||||||
func (c *Config) Debug() bool {
|
func (c *Config) Debug() bool {
|
||||||
return c.Options.Debug
|
return c.Options.Debug
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ import (
|
|||||||
|
|
||||||
// Version of TinyGo.
|
// Version of TinyGo.
|
||||||
// Update this value before release of new version of software.
|
// Update this value before release of new version of software.
|
||||||
const Version = "0.26.0-dev"
|
const Version = "0.26.0"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// This variable is set at build time using -ldflags parameters.
|
// This variable is set at build time using -ldflags parameters.
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ const (
|
|||||||
I2C0_SDA_PIN = GPIO20
|
I2C0_SDA_PIN = GPIO20
|
||||||
I2C0_SCL_PIN = GPIO21
|
I2C0_SCL_PIN = GPIO21
|
||||||
|
|
||||||
I2C1_SDA_PIN = 31 // not pinned out
|
I2C1_SDA_PIN = NoPin // not pinned out
|
||||||
I2C1_SCL_PIN = 31 // not pinned out
|
I2C1_SCL_PIN = NoPin // not pinned out
|
||||||
)
|
)
|
||||||
|
|
||||||
// SPI default pins
|
// SPI default pins
|
||||||
@@ -65,9 +65,9 @@ const (
|
|||||||
// Default Serial In Bus 1 for SPI communications
|
// Default Serial In Bus 1 for SPI communications
|
||||||
SPI1_SDI_PIN = GPIO28 // Rx
|
SPI1_SDI_PIN = GPIO28 // Rx
|
||||||
|
|
||||||
SPI0_SCK_PIN = 31 // not pinned out
|
SPI0_SCK_PIN = NoPin // not pinned out
|
||||||
SPI0_SDO_PIN = 31 // not pinned out
|
SPI0_SDO_PIN = NoPin // not pinned out
|
||||||
SPI0_SDI_PIN = 31 // not pinned out
|
SPI0_SDI_PIN = NoPin // not pinned out
|
||||||
)
|
)
|
||||||
|
|
||||||
// UART pins
|
// UART pins
|
||||||
|
|||||||
@@ -18,15 +18,15 @@ const (
|
|||||||
|
|
||||||
// MDBT50Q-RX dongle does not have pins broken out for the peripherals below,
|
// MDBT50Q-RX dongle does not have pins broken out for the peripherals below,
|
||||||
// however the machine_nrf*.go implementations of I2C/SPI/etc expect the pin
|
// however the machine_nrf*.go implementations of I2C/SPI/etc expect the pin
|
||||||
// constants to be defined, so we are defining them all as 0
|
// constants to be defined, so we are defining them all as NoPin
|
||||||
const (
|
const (
|
||||||
UART_TX_PIN = 0
|
UART_TX_PIN = NoPin
|
||||||
UART_RX_PIN = 0
|
UART_RX_PIN = NoPin
|
||||||
SDA_PIN = 0
|
SDA_PIN = NoPin
|
||||||
SCL_PIN = 0
|
SCL_PIN = NoPin
|
||||||
SPI0_SCK_PIN = 0
|
SPI0_SCK_PIN = NoPin
|
||||||
SPI0_SDO_PIN = 0
|
SPI0_SDO_PIN = NoPin
|
||||||
SPI0_SDI_PIN = 0
|
SPI0_SDI_PIN = NoPin
|
||||||
)
|
)
|
||||||
|
|
||||||
// USB CDC identifiers
|
// USB CDC identifiers
|
||||||
|
|||||||
@@ -17,20 +17,20 @@ import (
|
|||||||
const deviceName = sam.Device
|
const deviceName = sam.Device
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
PinAnalog PinMode = 1
|
||||||
|
PinSERCOM PinMode = 2
|
||||||
|
PinSERCOMAlt PinMode = 3
|
||||||
|
PinTimer PinMode = 4
|
||||||
|
PinTimerAlt PinMode = 5
|
||||||
|
PinCom PinMode = 6
|
||||||
|
//PinAC_CLK PinMode = 7
|
||||||
|
PinDigital PinMode = 8
|
||||||
PinInput PinMode = 9
|
PinInput PinMode = 9
|
||||||
PinInputPullup PinMode = 10
|
PinInputPullup PinMode = 10
|
||||||
PinOutput PinMode = 11
|
PinOutput PinMode = 11
|
||||||
|
PinTCC PinMode = PinTimer
|
||||||
|
PinTCCAlt PinMode = PinTimerAlt
|
||||||
PinInputPulldown PinMode = 12
|
PinInputPulldown PinMode = 12
|
||||||
|
|
||||||
// internal pin modes
|
|
||||||
pinAnalog PinMode = 1
|
|
||||||
pinSERCOM PinMode = 2
|
|
||||||
pinSERCOMAlt PinMode = 3
|
|
||||||
pinTCC PinMode = 4
|
|
||||||
pinTCCAlt PinMode = 5
|
|
||||||
pinCom PinMode = 6
|
|
||||||
//PinAC_CLK PinMode = 7
|
|
||||||
pinDigital PinMode = 8
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PinChange uint8
|
type PinChange uint8
|
||||||
@@ -149,7 +149,7 @@ func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok b
|
|||||||
if upper != 0 {
|
if upper != 0 {
|
||||||
// SERCOM
|
// SERCOM
|
||||||
if (upper>>1)-1 == sercom {
|
if (upper>>1)-1 == sercom {
|
||||||
pinMode = pinSERCOM
|
pinMode = PinSERCOM
|
||||||
pad |= uint32((upper & 1) << 1)
|
pad |= uint32((upper & 1) << 1)
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
@@ -157,7 +157,7 @@ func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok b
|
|||||||
if lower != 0 {
|
if lower != 0 {
|
||||||
// SERCOM-ALT
|
// SERCOM-ALT
|
||||||
if (lower>>1)-1 == sercom {
|
if (lower>>1)-1 == sercom {
|
||||||
pinMode = pinSERCOMAlt
|
pinMode = PinSERCOMAlt
|
||||||
pad |= uint32((lower & 1) << 1)
|
pad |= uint32((lower & 1) << 1)
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
@@ -381,7 +381,7 @@ func (a ADC) Configure(config ADCConfig) {
|
|||||||
// 1/2 VDDANA = 0.5 * 3V3 = 1.65V
|
// 1/2 VDDANA = 0.5 * 3V3 = 1.65V
|
||||||
sam.ADC.REFCTRL.SetBits(sam.ADC_REFCTRL_REFSEL_INTVCC1 << sam.ADC_REFCTRL_REFSEL_Pos)
|
sam.ADC.REFCTRL.SetBits(sam.ADC_REFCTRL_REFSEL_INTVCC1 << sam.ADC_REFCTRL_REFSEL_Pos)
|
||||||
|
|
||||||
a.Pin.Configure(PinConfig{Mode: pinAnalog})
|
a.Pin.Configure(PinConfig{Mode: PinAnalog})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1000,11 +1000,11 @@ func (i2s I2S) Configure(config I2SConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure pin for clock
|
// configure pin for clock
|
||||||
config.SCK.Configure(PinConfig{Mode: pinCom})
|
config.SCK.Configure(PinConfig{Mode: PinCom})
|
||||||
|
|
||||||
// configure pin for WS, if needed
|
// configure pin for WS, if needed
|
||||||
if config.WS != NoPin {
|
if config.WS != NoPin {
|
||||||
config.WS.Configure(PinConfig{Mode: pinCom})
|
config.WS.Configure(PinConfig{Mode: PinCom})
|
||||||
}
|
}
|
||||||
|
|
||||||
// now set serializer data size.
|
// now set serializer data size.
|
||||||
@@ -1043,7 +1043,7 @@ func (i2s I2S) Configure(config I2SConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure data pin
|
// configure data pin
|
||||||
config.SD.Configure(PinConfig{Mode: pinCom})
|
config.SD.Configure(PinConfig{Mode: PinCom})
|
||||||
|
|
||||||
// re-enable
|
// re-enable
|
||||||
i2s.Bus.CTRLA.SetBits(sam.I2S_CTRLA_ENABLE)
|
i2s.Bus.CTRLA.SetBits(sam.I2S_CTRLA_ENABLE)
|
||||||
@@ -1636,12 +1636,12 @@ func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) {
|
|||||||
if mapping&0x07 == timer+1 {
|
if mapping&0x07 == timer+1 {
|
||||||
// PWM output is on peripheral function E.
|
// PWM output is on peripheral function E.
|
||||||
evenChannel := ((mapping >> 3) & 1) * 2
|
evenChannel := ((mapping >> 3) & 1) * 2
|
||||||
return pinTCC, evenChannel + uint8(pin&1)
|
return PinTCC, evenChannel + uint8(pin&1)
|
||||||
}
|
}
|
||||||
if (mapping&0x70)>>4 == timer+1 {
|
if (mapping&0x70)>>4 == timer+1 {
|
||||||
// PWM output is on peripheral function F.
|
// PWM output is on peripheral function F.
|
||||||
evenChannel := ((mapping >> 7) & 1) * 2
|
evenChannel := ((mapping >> 7) & 1) * 2
|
||||||
return pinTCCAlt, evenChannel + uint8(pin&1)
|
return PinTCCAlt, evenChannel + uint8(pin&1)
|
||||||
}
|
}
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ func (dev *USBDevice) Configure(config UARTConfig) {
|
|||||||
sam.USB_DEVICE.DESCADD.Set(uint32(uintptr(unsafe.Pointer(&usbEndpointDescriptors))))
|
sam.USB_DEVICE.DESCADD.Set(uint32(uintptr(unsafe.Pointer(&usbEndpointDescriptors))))
|
||||||
|
|
||||||
// configure pins
|
// configure pins
|
||||||
USBCDC_DM_PIN.Configure(PinConfig{Mode: pinCom})
|
USBCDC_DM_PIN.Configure(PinConfig{Mode: PinCom})
|
||||||
USBCDC_DP_PIN.Configure(PinConfig{Mode: pinCom})
|
USBCDC_DP_PIN.Configure(PinConfig{Mode: PinCom})
|
||||||
|
|
||||||
// performs pad calibration from store fuses
|
// performs pad calibration from store fuses
|
||||||
handlePadCalibration()
|
handlePadCalibration()
|
||||||
|
|||||||
@@ -86,53 +86,53 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
sam.PORT.OUTSET0.Set(1 << uint8(p))
|
sam.PORT.OUTSET0.Set(1 << uint8(p))
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
||||||
|
|
||||||
case pinSERCOM:
|
case PinSERCOM:
|
||||||
if uint8(p)&1 > 0 {
|
if uint8(p)&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOM) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSERCOM) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOM) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSERCOM) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR | sam.PORT_PINCFG0_INEN)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR | sam.PORT_PINCFG0_INEN)
|
||||||
|
|
||||||
case pinSERCOMAlt:
|
case PinSERCOMAlt:
|
||||||
if uint8(p)&1 > 0 {
|
if uint8(p)&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOMAlt) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSERCOMAlt) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOMAlt) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSERCOMAlt) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
||||||
|
|
||||||
case pinCom:
|
case PinCom:
|
||||||
if uint8(p)&1 > 0 {
|
if uint8(p)&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinCom) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinCom) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinCom) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinCom) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN)
|
||||||
case pinAnalog:
|
case PinAnalog:
|
||||||
if uint8(p)&1 > 0 {
|
if uint8(p)&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinAnalog) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinAnalog) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinAnalog) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinAnalog) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
||||||
|
|||||||
@@ -137,53 +137,53 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
case pinSERCOM:
|
case PinSERCOM:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOM) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSERCOM) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOM) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSERCOM) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR | sam.PORT_PINCFG0_INEN)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR | sam.PORT_PINCFG0_INEN)
|
||||||
|
|
||||||
case pinSERCOMAlt:
|
case PinSERCOMAlt:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOMAlt) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSERCOMAlt) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOMAlt) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSERCOMAlt) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
||||||
|
|
||||||
case pinCom:
|
case PinCom:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinCom) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinCom) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinCom) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinCom) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN)
|
||||||
case pinAnalog:
|
case PinAnalog:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinAnalog) << sam.PORT_PMUX0_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinAnalog) << sam.PORT_PMUX0_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_PMUX0_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinAnalog) << sam.PORT_PMUX0_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinAnalog) << sam.PORT_PMUX0_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
p.setPinCfg(sam.PORT_PINCFG0_PMUXEN | sam.PORT_PINCFG0_DRVSTR)
|
||||||
|
|||||||
@@ -21,29 +21,30 @@ func CPUFrequency() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
PinAnalog PinMode = 1
|
||||||
|
PinSERCOM PinMode = 2
|
||||||
|
PinSERCOMAlt PinMode = 3
|
||||||
|
PinTimer PinMode = 4
|
||||||
|
PinTimerAlt PinMode = 5
|
||||||
|
PinTCCPDEC PinMode = 6
|
||||||
|
PinCom PinMode = 7
|
||||||
|
PinSDHC PinMode = 8
|
||||||
|
PinI2S PinMode = 9
|
||||||
|
PinPCC PinMode = 10
|
||||||
|
PinGMAC PinMode = 11
|
||||||
|
PinACCLK PinMode = 12
|
||||||
|
PinCCL PinMode = 13
|
||||||
|
PinDigital PinMode = 14
|
||||||
PinInput PinMode = 15
|
PinInput PinMode = 15
|
||||||
PinInputPullup PinMode = 16
|
PinInputPullup PinMode = 16
|
||||||
PinOutput PinMode = 17
|
PinOutput PinMode = 17
|
||||||
|
PinTCCE PinMode = PinTimer
|
||||||
|
PinTCCF PinMode = PinTimerAlt
|
||||||
|
PinTCCG PinMode = PinTCCPDEC
|
||||||
PinInputPulldown PinMode = 18
|
PinInputPulldown PinMode = 18
|
||||||
|
PinCAN PinMode = 19
|
||||||
// internal pin modes
|
PinCAN0 PinMode = PinSDHC
|
||||||
pinAnalog PinMode = 1
|
PinCAN1 PinMode = PinCom
|
||||||
pinSERCOM PinMode = 2
|
|
||||||
pinSERCOMAlt PinMode = 3
|
|
||||||
pinTCCE PinMode = 4
|
|
||||||
pinTCCF PinMode = 5
|
|
||||||
pinTCCG PinMode = 6
|
|
||||||
pinCom PinMode = 7
|
|
||||||
pinSDHC PinMode = 8
|
|
||||||
pinI2S PinMode = 9
|
|
||||||
pinPCC PinMode = 10
|
|
||||||
pinGMAC PinMode = 11
|
|
||||||
pinACCLK PinMode = 12
|
|
||||||
pinCCL PinMode = 13
|
|
||||||
pinDigital PinMode = 14
|
|
||||||
pinCAN PinMode = 19
|
|
||||||
pinCAN0 PinMode = pinSDHC
|
|
||||||
pinCAN1 PinMode = pinCom
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PinChange uint8
|
type PinChange uint8
|
||||||
@@ -337,7 +338,7 @@ func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok b
|
|||||||
if upper != 0 {
|
if upper != 0 {
|
||||||
// SERCOM
|
// SERCOM
|
||||||
if (upper>>4)-1 == sercom {
|
if (upper>>4)-1 == sercom {
|
||||||
pinMode = pinSERCOM
|
pinMode = PinSERCOM
|
||||||
pad |= uint32(upper % 4)
|
pad |= uint32(upper % 4)
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
@@ -345,7 +346,7 @@ func findPinPadMapping(sercom uint8, pin Pin) (pinMode PinMode, pad uint32, ok b
|
|||||||
if lower != 0 {
|
if lower != 0 {
|
||||||
// SERCOM-ALT
|
// SERCOM-ALT
|
||||||
if (lower>>4)-1 == sercom {
|
if (lower>>4)-1 == sercom {
|
||||||
pinMode = pinSERCOMAlt
|
pinMode = PinSERCOMAlt
|
||||||
pad |= uint32(lower % 4)
|
pad |= uint32(lower % 4)
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
@@ -579,65 +580,65 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
sam.PORT.GROUP[group].OUTSET.Set(1 << pin_in_group)
|
sam.PORT.GROUP[group].OUTSET.Set(1 << pin_in_group)
|
||||||
p.setPinCfg(sam.PORT_GROUP_PINCFG_INEN | sam.PORT_GROUP_PINCFG_PULLEN)
|
p.setPinCfg(sam.PORT_GROUP_PINCFG_INEN | sam.PORT_GROUP_PINCFG_PULLEN)
|
||||||
|
|
||||||
case pinSERCOM:
|
case PinSERCOM:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOM) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSERCOM) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOM) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSERCOM) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN | sam.PORT_GROUP_PINCFG_DRVSTR | sam.PORT_GROUP_PINCFG_INEN)
|
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN | sam.PORT_GROUP_PINCFG_DRVSTR | sam.PORT_GROUP_PINCFG_INEN)
|
||||||
|
|
||||||
case pinSERCOMAlt:
|
case PinSERCOMAlt:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOMAlt) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSERCOMAlt) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSERCOMAlt) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSERCOMAlt) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN | sam.PORT_GROUP_PINCFG_DRVSTR)
|
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN | sam.PORT_GROUP_PINCFG_DRVSTR)
|
||||||
|
|
||||||
case pinCom:
|
case PinCom:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinCom) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinCom) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinCom) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinCom) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN)
|
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN)
|
||||||
case pinAnalog:
|
case PinAnalog:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinAnalog) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinAnalog) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinAnalog) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinAnalog) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN | sam.PORT_GROUP_PINCFG_DRVSTR)
|
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN | sam.PORT_GROUP_PINCFG_DRVSTR)
|
||||||
case pinSDHC:
|
case PinSDHC:
|
||||||
if p&1 > 0 {
|
if p&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXE_Msk
|
||||||
p.setPMux(val | (uint8(pinSDHC) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
p.setPMux(val | (uint8(PinSDHC) << sam.PORT_GROUP_PMUX_PMUXO_Pos))
|
||||||
} else {
|
} else {
|
||||||
// even pin, so save the odd pins
|
// even pin, so save the odd pins
|
||||||
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
val := p.getPMux() & sam.PORT_GROUP_PMUX_PMUXO_Msk
|
||||||
p.setPMux(val | (uint8(pinSDHC) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
p.setPMux(val | (uint8(PinSDHC) << sam.PORT_GROUP_PMUX_PMUXE_Pos))
|
||||||
}
|
}
|
||||||
// enable port config
|
// enable port config
|
||||||
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN)
|
p.setPinCfg(sam.PORT_GROUP_PINCFG_PMUXEN)
|
||||||
@@ -813,7 +814,7 @@ func (a ADC) Configure(config ADCConfig) {
|
|||||||
adc.REFCTRL.SetBits(sam.ADC_REFCTRL_REFSEL_INTVCC1)
|
adc.REFCTRL.SetBits(sam.ADC_REFCTRL_REFSEL_INTVCC1)
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Pin.Configure(PinConfig{Mode: pinAnalog})
|
a.Pin.Configure(PinConfig{Mode: PinAnalog})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the current value of a ADC pin, in the range 0..0xffff.
|
// Get returns the current value of a ADC pin, in the range 0..0xffff.
|
||||||
@@ -1866,7 +1867,7 @@ var pinTimerMapping = [...]struct{ F, G uint8 }{
|
|||||||
PB02 / 2: {pinTCC2_2, 0},
|
PB02 / 2: {pinTCC2_2, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
// findPinPadMapping returns the pin mode (pinTCCF or pinTCCG) and the channel
|
// findPinPadMapping returns the pin mode (PinTCCF or PinTCCG) and the channel
|
||||||
// number for a given timer and pin. A zero PinMode is returned if no mapping
|
// number for a given timer and pin. A zero PinMode is returned if no mapping
|
||||||
// could be found.
|
// could be found.
|
||||||
func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) {
|
func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) {
|
||||||
@@ -1878,12 +1879,12 @@ func findPinTimerMapping(timer uint8, pin Pin) (PinMode, uint8) {
|
|||||||
|
|
||||||
// Check for column F in the datasheet.
|
// Check for column F in the datasheet.
|
||||||
if mapping.F>>4-1 == timer {
|
if mapping.F>>4-1 == timer {
|
||||||
return pinTCCF, mapping.F&0x0f + uint8(pin)&1
|
return PinTCCF, mapping.F&0x0f + uint8(pin)&1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for column G in the datasheet.
|
// Check for column G in the datasheet.
|
||||||
if mapping.G>>4-1 == timer {
|
if mapping.G>>4-1 == timer {
|
||||||
return pinTCCG, mapping.G&0x0f + uint8(pin)&1
|
return PinTCCG, mapping.G&0x0f + uint8(pin)&1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing found.
|
// Nothing found.
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ func (dev *USBDevice) Configure(config UARTConfig) {
|
|||||||
sam.USB_DEVICE.DESCADD.Set(uint32(uintptr(unsafe.Pointer(&usbEndpointDescriptors))))
|
sam.USB_DEVICE.DESCADD.Set(uint32(uintptr(unsafe.Pointer(&usbEndpointDescriptors))))
|
||||||
|
|
||||||
// configure pins
|
// configure pins
|
||||||
USBCDC_DM_PIN.Configure(PinConfig{Mode: pinCom})
|
USBCDC_DM_PIN.Configure(PinConfig{Mode: PinCom})
|
||||||
USBCDC_DP_PIN.Configure(PinConfig{Mode: pinCom})
|
USBCDC_DP_PIN.Configure(PinConfig{Mode: PinCom})
|
||||||
|
|
||||||
// performs pad calibration from store fuses
|
// performs pad calibration from store fuses
|
||||||
handlePadCalibration()
|
handlePadCalibration()
|
||||||
|
|||||||
@@ -68,9 +68,9 @@ func (can *CAN) Configure(config CANConfig) error {
|
|||||||
config.Standby.Low()
|
config.Standby.Low()
|
||||||
}
|
}
|
||||||
|
|
||||||
mode := pinCAN0
|
mode := PinCAN0
|
||||||
if can.instance() == 1 {
|
if can.instance() == 1 {
|
||||||
mode = pinCAN1
|
mode = PinCAN1
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Rx.Configure(PinConfig{Mode: mode})
|
config.Rx.Configure(PinConfig{Mode: mode})
|
||||||
|
|||||||
@@ -18,11 +18,9 @@ func CPUFrequency() uint32 {
|
|||||||
const (
|
const (
|
||||||
PinInput PinMode = iota
|
PinInput PinMode = iota
|
||||||
PinOutput
|
PinOutput
|
||||||
|
PinPWM
|
||||||
// internal pin modes
|
PinSPI
|
||||||
pinPWM
|
PinI2C = PinSPI
|
||||||
pinSPI
|
|
||||||
pinI2C = pinSPI
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Configure this pin with the given configuration.
|
// Configure this pin with the given configuration.
|
||||||
@@ -31,10 +29,10 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
switch config.Mode {
|
switch config.Mode {
|
||||||
case PinOutput:
|
case PinOutput:
|
||||||
sifive.GPIO0.OUTPUT_EN.SetBits(1 << uint8(p))
|
sifive.GPIO0.OUTPUT_EN.SetBits(1 << uint8(p))
|
||||||
case pinPWM:
|
case PinPWM:
|
||||||
sifive.GPIO0.IOF_EN.SetBits(1 << uint8(p))
|
sifive.GPIO0.IOF_EN.SetBits(1 << uint8(p))
|
||||||
sifive.GPIO0.IOF_SEL.SetBits(1 << uint8(p))
|
sifive.GPIO0.IOF_SEL.SetBits(1 << uint8(p))
|
||||||
case pinSPI:
|
case PinSPI:
|
||||||
sifive.GPIO0.IOF_EN.SetBits(1 << uint8(p))
|
sifive.GPIO0.IOF_EN.SetBits(1 << uint8(p))
|
||||||
sifive.GPIO0.IOF_SEL.ClearBits(1 << uint8(p))
|
sifive.GPIO0.IOF_SEL.ClearBits(1 << uint8(p))
|
||||||
}
|
}
|
||||||
@@ -147,9 +145,9 @@ func (spi SPI) Configure(config SPIConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// enable pins for SPI
|
// enable pins for SPI
|
||||||
config.SCK.Configure(PinConfig{Mode: pinSPI})
|
config.SCK.Configure(PinConfig{Mode: PinSPI})
|
||||||
config.SDO.Configure(PinConfig{Mode: pinSPI})
|
config.SDO.Configure(PinConfig{Mode: PinSPI})
|
||||||
config.SDI.Configure(PinConfig{Mode: pinSPI})
|
config.SDI.Configure(PinConfig{Mode: PinSPI})
|
||||||
|
|
||||||
// set default frequency
|
// set default frequency
|
||||||
if config.Frequency == 0 {
|
if config.Frequency == 0 {
|
||||||
@@ -253,8 +251,8 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
|||||||
// enable controller
|
// enable controller
|
||||||
i2c.Bus.CTR.SetBits(sifive.I2C_CTR_EN)
|
i2c.Bus.CTR.SetBits(sifive.I2C_CTR_EN)
|
||||||
|
|
||||||
config.SDA.Configure(PinConfig{Mode: pinI2C})
|
config.SDA.Configure(PinConfig{Mode: PinI2C})
|
||||||
config.SCL.Configure(PinConfig{Mode: pinI2C})
|
config.SCL.Configure(PinConfig{Mode: PinI2C})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,21 +28,21 @@ const (
|
|||||||
PinDisable
|
PinDisable
|
||||||
|
|
||||||
// ADC
|
// ADC
|
||||||
pinInputAnalog
|
PinInputAnalog
|
||||||
|
|
||||||
// UART
|
// UART
|
||||||
pinModeUARTTX
|
PinModeUARTTX
|
||||||
pinModeUARTRX
|
PinModeUARTRX
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
pinModeSPISDI
|
PinModeSPISDI
|
||||||
pinModeSPISDO
|
PinModeSPISDO
|
||||||
pinModeSPICLK
|
PinModeSPICLK
|
||||||
pinModeSPICS
|
PinModeSPICS
|
||||||
|
|
||||||
// I2C
|
// I2C
|
||||||
pinModeI2CSDA
|
PinModeI2CSDA
|
||||||
pinModeI2CSCL
|
PinModeI2CSCL
|
||||||
)
|
)
|
||||||
|
|
||||||
// Deprecated: use PinInputPullup and PinInputPulldown instead.
|
// Deprecated: use PinInputPullup and PinInputPulldown instead.
|
||||||
@@ -283,29 +283,29 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
gpio.GDIR.ClearBits(p.getMask())
|
gpio.GDIR.ClearBits(p.getMask())
|
||||||
pad.Set(dse(7) | hys)
|
pad.Set(dse(7) | hys)
|
||||||
|
|
||||||
case pinInputAnalog:
|
case PinInputAnalog:
|
||||||
gpio.GDIR.ClearBits(p.getMask())
|
gpio.GDIR.ClearBits(p.getMask())
|
||||||
pad.Set(dse(7))
|
pad.Set(dse(7))
|
||||||
|
|
||||||
case pinModeUARTTX:
|
case PinModeUARTTX:
|
||||||
pad.Set(sre | dse(3) | spd(3))
|
pad.Set(sre | dse(3) | spd(3))
|
||||||
|
|
||||||
case pinModeUARTRX:
|
case PinModeUARTRX:
|
||||||
pad.Set(dse(7) | pke | pue | pup(3) | hys)
|
pad.Set(dse(7) | pke | pue | pup(3) | hys)
|
||||||
|
|
||||||
case pinModeSPISDI:
|
case PinModeSPISDI:
|
||||||
pad.Set(dse(7) | spd(2))
|
pad.Set(dse(7) | spd(2))
|
||||||
|
|
||||||
case pinModeSPISDO:
|
case PinModeSPISDO:
|
||||||
pad.Set(dse(7) | spd(2))
|
pad.Set(dse(7) | spd(2))
|
||||||
|
|
||||||
case pinModeSPICLK:
|
case PinModeSPICLK:
|
||||||
pad.Set(dse(7) | spd(2))
|
pad.Set(dse(7) | spd(2))
|
||||||
|
|
||||||
case pinModeSPICS:
|
case PinModeSPICS:
|
||||||
pad.Set(dse(7))
|
pad.Set(dse(7))
|
||||||
|
|
||||||
case pinModeI2CSDA, pinModeI2CSCL:
|
case PinModeI2CSDA, PinModeI2CSCL:
|
||||||
pad.Set(ode | sre | dse(4) | spd(1) | pke | pue | pup(3))
|
pad.Set(ode | sre | dse(4) | spd(1) | pke | pue | pup(3))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -759,7 +759,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// ADC
|
// ADC
|
||||||
case pinInputAnalog:
|
case PinInputAnalog:
|
||||||
mode := uint32(0x5) // use alternate function 5 (GPIO)
|
mode := uint32(0x5) // use alternate function 5 (GPIO)
|
||||||
if forcePath {
|
if forcePath {
|
||||||
mode |= 0x10 // SION bit
|
mode |= 0x10 // SION bit
|
||||||
@@ -767,7 +767,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// UART RX/TX
|
// UART RX/TX
|
||||||
case pinModeUARTRX, pinModeUARTTX:
|
case PinModeUARTRX, PinModeUARTTX:
|
||||||
mode := uint32(0x2) // UART is usually alternate function 2 on Teensy 4.x
|
mode := uint32(0x2) // UART is usually alternate function 2 on Teensy 4.x
|
||||||
// Teensy 4.1 has a UART (LPUART5) with alternate function 1
|
// Teensy 4.1 has a UART (LPUART5) with alternate function 1
|
||||||
if p == PB28 || p == PB29 {
|
if p == PB28 || p == PB29 {
|
||||||
@@ -776,7 +776,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// SPI SDI
|
// SPI SDI
|
||||||
case pinModeSPISDI:
|
case PinModeSPISDI:
|
||||||
var mode uint32
|
var mode uint32
|
||||||
switch p {
|
switch p {
|
||||||
case PC15: // LPSPI1 SDI on PC15 alternate function 4
|
case PC15: // LPSPI1 SDI on PC15 alternate function 4
|
||||||
@@ -794,7 +794,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// SPI SDO
|
// SPI SDO
|
||||||
case pinModeSPISDO:
|
case PinModeSPISDO:
|
||||||
var mode uint32
|
var mode uint32
|
||||||
switch p {
|
switch p {
|
||||||
case PC14: // LPSPI1 SDO on PC14 alternate function 4
|
case PC14: // LPSPI1 SDO on PC14 alternate function 4
|
||||||
@@ -812,7 +812,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// SPI SCK
|
// SPI SCK
|
||||||
case pinModeSPICLK:
|
case PinModeSPICLK:
|
||||||
var mode uint32
|
var mode uint32
|
||||||
switch p {
|
switch p {
|
||||||
case PC12: // LPSPI1 SCK on PC12 alternate function 4
|
case PC12: // LPSPI1 SCK on PC12 alternate function 4
|
||||||
@@ -830,7 +830,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// SPI CS
|
// SPI CS
|
||||||
case pinModeSPICS:
|
case PinModeSPICS:
|
||||||
var mode uint32
|
var mode uint32
|
||||||
switch p {
|
switch p {
|
||||||
case PC13: // LPSPI1 CS on PC13 alternate function 4
|
case PC13: // LPSPI1 CS on PC13 alternate function 4
|
||||||
@@ -848,7 +848,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// I2C SDA
|
// I2C SDA
|
||||||
case pinModeI2CSDA:
|
case PinModeI2CSDA:
|
||||||
var mode uint32
|
var mode uint32
|
||||||
switch p {
|
switch p {
|
||||||
case PA13: // LPI2C4 SDA on PA13 alternate function 0
|
case PA13: // LPI2C4 SDA on PA13 alternate function 0
|
||||||
@@ -866,7 +866,7 @@ func (p Pin) getMuxMode(config PinConfig) uint32 {
|
|||||||
return mode
|
return mode
|
||||||
|
|
||||||
// I2C SCL
|
// I2C SCL
|
||||||
case pinModeI2CSCL:
|
case PinModeI2CSCL:
|
||||||
var mode uint32
|
var mode uint32
|
||||||
switch p {
|
switch p {
|
||||||
case PA12: // LPI2C4 SCL on PA12 alternate function 0
|
case PA12: // LPI2C4 SCL on PA12 alternate function 0
|
||||||
@@ -902,7 +902,7 @@ func (a ADC) Configure(config ADCConfig) {
|
|||||||
defaultSamples = uint32(4)
|
defaultSamples = uint32(4)
|
||||||
)
|
)
|
||||||
|
|
||||||
a.Pin.Configure(PinConfig{Mode: pinInputAnalog})
|
a.Pin.Configure(PinConfig{Mode: PinInputAnalog})
|
||||||
|
|
||||||
resolution, samples := config.Resolution, config.Samples
|
resolution, samples := config.Resolution, config.Samples
|
||||||
if 0 == resolution {
|
if 0 == resolution {
|
||||||
|
|||||||
@@ -156,8 +156,8 @@ func (i2c *I2C) Configure(config I2CConfig) {
|
|||||||
sda, scl := i2c.setPins(config)
|
sda, scl := i2c.setPins(config)
|
||||||
|
|
||||||
// configure the mux and pad control registers
|
// configure the mux and pad control registers
|
||||||
sda.Configure(PinConfig{Mode: pinModeI2CSDA})
|
sda.Configure(PinConfig{Mode: PinModeI2CSDA})
|
||||||
scl.Configure(PinConfig{Mode: pinModeI2CSCL})
|
scl.Configure(PinConfig{Mode: PinModeI2CSCL})
|
||||||
|
|
||||||
// configure the mux input selector
|
// configure the mux input selector
|
||||||
i2c.muxSDA.connect()
|
i2c.muxSDA.connect()
|
||||||
|
|||||||
@@ -77,10 +77,10 @@ func (spi *SPI) Configure(config SPIConfig) {
|
|||||||
spi.sdi, spi.sdo, spi.sck, spi.cs = config.getPins()
|
spi.sdi, spi.sdo, spi.sck, spi.cs = config.getPins()
|
||||||
|
|
||||||
// configure the mux and pad control registers
|
// configure the mux and pad control registers
|
||||||
spi.sdi.Configure(PinConfig{Mode: pinModeSPISDI})
|
spi.sdi.Configure(PinConfig{Mode: PinModeSPISDI})
|
||||||
spi.sdo.Configure(PinConfig{Mode: pinModeSPISDO})
|
spi.sdo.Configure(PinConfig{Mode: PinModeSPISDO})
|
||||||
spi.sck.Configure(PinConfig{Mode: pinModeSPICLK})
|
spi.sck.Configure(PinConfig{Mode: PinModeSPICLK})
|
||||||
spi.cs.Configure(PinConfig{Mode: pinModeSPICS})
|
spi.cs.Configure(PinConfig{Mode: PinModeSPICS})
|
||||||
|
|
||||||
// configure the mux input selector
|
// configure the mux input selector
|
||||||
spi.muxSDI.connect()
|
spi.muxSDI.connect()
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ func (uart *UART) Configure(config UARTConfig) {
|
|||||||
uart.tx = config.TX
|
uart.tx = config.TX
|
||||||
|
|
||||||
// configure the mux and pad control registers
|
// configure the mux and pad control registers
|
||||||
uart.rx.Configure(PinConfig{Mode: pinModeUARTRX})
|
uart.rx.Configure(PinConfig{Mode: PinModeUARTRX})
|
||||||
uart.tx.Configure(PinConfig{Mode: pinModeUARTTX})
|
uart.tx.Configure(PinConfig{Mode: PinModeUARTTX})
|
||||||
|
|
||||||
// configure the mux input selector
|
// configure the mux input selector
|
||||||
uart.muxRX.connect()
|
uart.muxRX.connect()
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ func (c ADCChannel) Configure(config ADCConfig) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.Configure(PinConfig{Mode: pinAnalog})
|
p.Configure(PinConfig{Mode: PinAnalog})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,13 +81,11 @@ const (
|
|||||||
PinInput
|
PinInput
|
||||||
PinInputPulldown
|
PinInputPulldown
|
||||||
PinInputPullup
|
PinInputPullup
|
||||||
|
PinAnalog
|
||||||
// internal pin modes
|
PinUART
|
||||||
pinAnalog
|
PinPWM
|
||||||
pinUART
|
PinI2C
|
||||||
pinPWM
|
PinSPI
|
||||||
pinI2C
|
|
||||||
pinSPI
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p Pin) PortMaskSet() (*uint32, uint32) {
|
func (p Pin) PortMaskSet() (*uint32, uint32) {
|
||||||
@@ -190,20 +188,20 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
case PinInputPullup:
|
case PinInputPullup:
|
||||||
p.setFunc(fnSIO)
|
p.setFunc(fnSIO)
|
||||||
p.pullup()
|
p.pullup()
|
||||||
case pinAnalog:
|
case PinAnalog:
|
||||||
p.setFunc(fnNULL)
|
p.setFunc(fnNULL)
|
||||||
p.pulloff()
|
p.pulloff()
|
||||||
case pinUART:
|
case PinUART:
|
||||||
p.setFunc(fnUART)
|
p.setFunc(fnUART)
|
||||||
case pinPWM:
|
case PinPWM:
|
||||||
p.setFunc(fnPWM)
|
p.setFunc(fnPWM)
|
||||||
case pinI2C:
|
case PinI2C:
|
||||||
// IO config according to 4.3.1.3 of rp2040 datasheet.
|
// IO config according to 4.3.1.3 of rp2040 datasheet.
|
||||||
p.setFunc(fnI2C)
|
p.setFunc(fnI2C)
|
||||||
p.pullup()
|
p.pullup()
|
||||||
p.setSchmitt(true)
|
p.setSchmitt(true)
|
||||||
p.setSlew(false)
|
p.setSlew(false)
|
||||||
case pinSPI:
|
case PinSPI:
|
||||||
p.setFunc(fnSPI)
|
p.setFunc(fnSPI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ func (i2c *I2C) Configure(config I2CConfig) error {
|
|||||||
if config.Frequency == 0 {
|
if config.Frequency == 0 {
|
||||||
config.Frequency = defaultBaud
|
config.Frequency = defaultBaud
|
||||||
}
|
}
|
||||||
config.SDA.Configure(PinConfig{pinI2C})
|
config.SDA.Configure(PinConfig{PinI2C})
|
||||||
config.SCL.Configure(PinConfig{pinI2C})
|
config.SCL.Configure(PinConfig{PinI2C})
|
||||||
return i2c.init(config)
|
return i2c.init(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ func (pwm *pwmGroup) Channel(pin Pin) (channel uint8, err error) {
|
|||||||
if pin > maxPWMPins || pwmGPIOToSlice(pin) != pwm.peripheral() {
|
if pin > maxPWMPins || pwmGPIOToSlice(pin) != pwm.peripheral() {
|
||||||
return 3, ErrInvalidOutputPin
|
return 3, ErrInvalidOutputPin
|
||||||
}
|
}
|
||||||
pin.Configure(PinConfig{pinPWM})
|
pin.Configure(PinConfig{PinPWM})
|
||||||
return pwmGPIOToChannel(pin), nil
|
return pwmGPIOToChannel(pin), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ func (uart *UART) Configure(config UARTConfig) error {
|
|||||||
rp.UART0_UARTCR_TXE)
|
rp.UART0_UARTCR_TXE)
|
||||||
|
|
||||||
// set GPIO mux to UART for the pins
|
// set GPIO mux to UART for the pins
|
||||||
config.TX.Configure(PinConfig{Mode: pinUART})
|
config.TX.Configure(PinConfig{Mode: PinUART})
|
||||||
config.RX.Configure(PinConfig{Mode: pinUART})
|
config.RX.Configure(PinConfig{Mode: PinUART})
|
||||||
|
|
||||||
// Enable RX IRQ.
|
// Enable RX IRQ.
|
||||||
uart.Interrupt.SetPriority(0x80)
|
uart.Interrupt.SetPriority(0x80)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func InitADC() {
|
|||||||
|
|
||||||
// Configure configures an ADC pin to be able to read analog data.
|
// Configure configures an ADC pin to be able to read analog data.
|
||||||
func (a ADC) Configure(ADCConfig) {
|
func (a ADC) Configure(ADCConfig) {
|
||||||
a.Pin.Configure(PinConfig{Mode: pinInputModeAnalog})
|
a.Pin.Configure(PinConfig{Mode: PinInputModeAnalog})
|
||||||
|
|
||||||
// set sample time
|
// set sample time
|
||||||
ch := a.getChannel()
|
ch := a.getChannel()
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func InitADC() {
|
|||||||
|
|
||||||
// Configure configures an ADC pin to be able to read analog data.
|
// Configure configures an ADC pin to be able to read analog data.
|
||||||
func (a ADC) Configure(ADCConfig) {
|
func (a ADC) Configure(ADCConfig) {
|
||||||
a.Pin.ConfigureAltFunc(PinConfig{Mode: pinInputAnalog}, 0)
|
a.Pin.ConfigureAltFunc(PinConfig{Mode: PinInputAnalog}, 0)
|
||||||
|
|
||||||
// set sample time
|
// set sample time
|
||||||
ch := a.getChannel()
|
ch := a.getChannel()
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i2c *I2C) configurePins(config I2CConfig) {
|
func (i2c *I2C) configurePins(config I2CConfig) {
|
||||||
config.SCL.ConfigureAltFunc(PinConfig{Mode: pinModeI2CSCL}, i2c.AltFuncSelector)
|
config.SCL.ConfigureAltFunc(PinConfig{Mode: PinModeI2CSCL}, i2c.AltFuncSelector)
|
||||||
config.SDA.ConfigureAltFunc(PinConfig{Mode: pinModeI2CSDA}, i2c.AltFuncSelector)
|
config.SDA.ConfigureAltFunc(PinConfig{Mode: PinModeI2CSDA}, i2c.AltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i2c *I2C) controllerTransmit(addr uint16, w []byte) error {
|
func (i2c *I2C) controllerTransmit(addr uint16, w []byte) error {
|
||||||
|
|||||||
@@ -14,28 +14,29 @@ import (
|
|||||||
const (
|
const (
|
||||||
// Mode Flag
|
// Mode Flag
|
||||||
PinOutput PinMode = 0
|
PinOutput PinMode = 0
|
||||||
PinInput PinMode = 1
|
PinInput PinMode = PinInputFloating
|
||||||
|
PinInputFloating PinMode = 1
|
||||||
PinInputPulldown PinMode = 2
|
PinInputPulldown PinMode = 2
|
||||||
PinInputPullup PinMode = 3
|
PinInputPullup PinMode = 3
|
||||||
|
|
||||||
// for UART
|
// for UART
|
||||||
pinModeUARTTX PinMode = 4
|
PinModeUARTTX PinMode = 4
|
||||||
pinModeUARTRX PinMode = 5
|
PinModeUARTRX PinMode = 5
|
||||||
|
|
||||||
// for I2C
|
// for I2C
|
||||||
pinModeI2CSCL PinMode = 6
|
PinModeI2CSCL PinMode = 6
|
||||||
pinModeI2CSDA PinMode = 7
|
PinModeI2CSDA PinMode = 7
|
||||||
|
|
||||||
// for SPI
|
// for SPI
|
||||||
pinModeSPICLK PinMode = 8
|
PinModeSPICLK PinMode = 8
|
||||||
pinModeSPISDO PinMode = 9
|
PinModeSPISDO PinMode = 9
|
||||||
pinModeSPISDI PinMode = 10
|
PinModeSPISDI PinMode = 10
|
||||||
|
|
||||||
// for analog/ADC
|
// for analog/ADC
|
||||||
pinInputAnalog PinMode = 11
|
PinInputAnalog PinMode = 11
|
||||||
|
|
||||||
// for PWM
|
// for PWM
|
||||||
pinModePWMOutput PinMode = 12
|
PinModePWMOutput PinMode = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
// Define several bitfields that have different names across chip families but
|
// Define several bitfields that have different names across chip families but
|
||||||
@@ -82,7 +83,7 @@ func (p Pin) ConfigureAltFunc(config PinConfig, altFunc uint8) {
|
|||||||
switch config.Mode {
|
switch config.Mode {
|
||||||
|
|
||||||
// GPIO
|
// GPIO
|
||||||
case PinInput:
|
case PinInputFloating:
|
||||||
port.MODER.ReplaceBits(gpioModeInput, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeInput, gpioModeMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
||||||
case PinInputPulldown:
|
case PinInputPulldown:
|
||||||
@@ -96,24 +97,24 @@ func (p Pin) ConfigureAltFunc(config PinConfig, altFunc uint8) {
|
|||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
||||||
|
|
||||||
// UART
|
// UART
|
||||||
case pinModeUARTTX:
|
case PinModeUARTTX:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullUp, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullUp, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
case pinModeUARTRX:
|
case PinModeUARTRX:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
|
|
||||||
// I2C
|
// I2C
|
||||||
case pinModeI2CSCL:
|
case PinModeI2CSCL:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OTYPER.ReplaceBits(stm32.GPIO_OTYPER_OT0_OpenDrain, stm32.GPIO_OTYPER_OT0_Msk, pos/2)
|
port.OTYPER.ReplaceBits(stm32.GPIO_OTYPER_OT0_OpenDrain, stm32.GPIO_OTYPER_OT0_Msk, pos/2)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullUp, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullUp, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
case pinModeI2CSDA:
|
case PinModeI2CSDA:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OTYPER.ReplaceBits(stm32.GPIO_OTYPER_OT0_OpenDrain, stm32.GPIO_OTYPER_OT0_Msk, pos/2)
|
port.OTYPER.ReplaceBits(stm32.GPIO_OTYPER_OT0_OpenDrain, stm32.GPIO_OTYPER_OT0_Msk, pos/2)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
||||||
@@ -121,31 +122,31 @@ func (p Pin) ConfigureAltFunc(config PinConfig, altFunc uint8) {
|
|||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
|
|
||||||
// SPI
|
// SPI
|
||||||
case pinModeSPICLK:
|
case PinModeSPICLK:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
case pinModeSPISDO:
|
case PinModeSPISDO:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
case pinModeSPISDI:
|
case PinModeSPISDI:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedLow, gpioOutputSpeedMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
case pinModePWMOutput:
|
case PinModePWMOutput:
|
||||||
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAlternate, gpioModeMask, pos)
|
||||||
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
port.OSPEEDR.ReplaceBits(gpioOutputSpeedHigh, gpioOutputSpeedMask, pos)
|
||||||
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
port.PUPDR.ReplaceBits(gpioPullFloating, gpioPullMask, pos)
|
||||||
p.SetAltFunc(altFunc)
|
p.SetAltFunc(altFunc)
|
||||||
|
|
||||||
// ADC
|
// ADC
|
||||||
case pinInputAnalog:
|
case PinInputAnalog:
|
||||||
port.MODER.ReplaceBits(gpioModeAnalog, gpioModeMask, pos)
|
port.MODER.ReplaceBits(gpioModeAnalog, gpioModeMask, pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func (t *TIM) Channel(pin Pin) (uint8, error) {
|
|||||||
for _, p := range ch.Pins {
|
for _, p := range ch.Pins {
|
||||||
if p.Pin == pin {
|
if p.Pin == pin {
|
||||||
t.configurePin(uint8(chi), p)
|
t.configurePin(uint8(chi), p)
|
||||||
//p.Pin.ConfigureAltFunc(PinConfig{Mode: pinModePWMOutput}, p.AltFunc)
|
//p.Pin.ConfigureAltFunc(PinConfig{Mode: PinModePWMOutput}, p.AltFunc)
|
||||||
return uint8(chi), nil
|
return uint8(chi), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ package machine
|
|||||||
// register (most MCUs except STM32F1 series).
|
// register (most MCUs except STM32F1 series).
|
||||||
|
|
||||||
func (t *TIM) configurePin(channel uint8, pf PinFunction) {
|
func (t *TIM) configurePin(channel uint8, pf PinFunction) {
|
||||||
pf.Pin.ConfigureAltFunc(PinConfig{Mode: pinModePWMOutput}, pf.AltFunc)
|
pf.Pin.ConfigureAltFunc(PinConfig{Mode: PinModePWMOutput}, pf.AltFunc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,20 +29,20 @@ const (
|
|||||||
PinOutput50MHz PinMode = 3 // Output mode, max speed 50MHz
|
PinOutput50MHz PinMode = 3 // Output mode, max speed 50MHz
|
||||||
PinOutput PinMode = PinOutput2MHz
|
PinOutput PinMode = PinOutput2MHz
|
||||||
|
|
||||||
pinInputModeAnalog PinMode = 0 // Input analog mode
|
PinInputModeAnalog PinMode = 0 // Input analog mode
|
||||||
pinInputModeFloating PinMode = 4 // Input floating mode
|
PinInputModeFloating PinMode = 4 // Input floating mode
|
||||||
pinInputModePullUpDown PinMode = 8 // Input pull up/down mode
|
PinInputModePullUpDown PinMode = 8 // Input pull up/down mode
|
||||||
pinInputModeReserved PinMode = 12 // Input mode (reserved)
|
PinInputModeReserved PinMode = 12 // Input mode (reserved)
|
||||||
|
|
||||||
pinOutputModeGPPushPull PinMode = 0 // Output mode general purpose push/pull
|
PinOutputModeGPPushPull PinMode = 0 // Output mode general purpose push/pull
|
||||||
pinOutputModeGPOpenDrain PinMode = 4 // Output mode general purpose open drain
|
PinOutputModeGPOpenDrain PinMode = 4 // Output mode general purpose open drain
|
||||||
pinOutputModeAltPushPull PinMode = 8 // Output mode alt. purpose push/pull
|
PinOutputModeAltPushPull PinMode = 8 // Output mode alt. purpose push/pull
|
||||||
pinOutputModeAltOpenDrain PinMode = 12 // Output mode alt. purpose open drain
|
PinOutputModeAltOpenDrain PinMode = 12 // Output mode alt. purpose open drain
|
||||||
|
|
||||||
// Pull-up vs Pull down is not part of the CNF0 / CNF1 bits, but is
|
// Pull-up vs Pull down is not part of the CNF0 / CNF1 bits, but is
|
||||||
// controlled by PxODR. Encoded using the 'spare' bit 5.
|
// controlled by PxODR. Encoded using the 'spare' bit 5.
|
||||||
PinInputPulldown PinMode = pinInputModePullUpDown
|
PinInputPulldown PinMode = PinInputModePullUpDown
|
||||||
PinInputPullup PinMode = pinInputModePullUpDown | 0x10
|
PinInputPullup PinMode = PinInputModePullUpDown | 0x10
|
||||||
)
|
)
|
||||||
|
|
||||||
// Pin constants for all stm32f103 package sizes
|
// Pin constants for all stm32f103 package sizes
|
||||||
@@ -166,7 +166,7 @@ func (p Pin) Configure(config PinConfig) {
|
|||||||
|
|
||||||
// If configured for input pull-up or pull-down, set ODR
|
// If configured for input pull-up or pull-down, set ODR
|
||||||
// for desired pull-up or pull-down.
|
// for desired pull-up or pull-down.
|
||||||
if (config.Mode & 0xf) == pinInputModePullUpDown {
|
if (config.Mode & 0xf) == PinInputModePullUpDown {
|
||||||
var pullup uint32
|
var pullup uint32
|
||||||
if config.Mode == PinInputPullup {
|
if config.Mode == PinInputPullup {
|
||||||
pullup = 1
|
pullup = 1
|
||||||
@@ -290,8 +290,8 @@ func (uart *UART) configurePins(config UARTConfig) {
|
|||||||
default:
|
default:
|
||||||
// use standard TX/RX pins PA9 and PA10
|
// use standard TX/RX pins PA9 and PA10
|
||||||
}
|
}
|
||||||
config.TX.Configure(PinConfig{Mode: PinOutput50MHz + pinOutputModeAltPushPull})
|
config.TX.Configure(PinConfig{Mode: PinOutput50MHz + PinOutputModeAltPushPull})
|
||||||
config.RX.Configure(PinConfig{Mode: pinInputModeFloating})
|
config.RX.Configure(PinConfig{Mode: PinInputModeFloating})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine the divisor for USARTs to get the given baudrate
|
// Determine the divisor for USARTs to get the given baudrate
|
||||||
@@ -363,9 +363,9 @@ func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
|||||||
|
|
||||||
// Configure SPI pins for input output and clock
|
// Configure SPI pins for input output and clock
|
||||||
func (spi SPI) configurePins(config SPIConfig) {
|
func (spi SPI) configurePins(config SPIConfig) {
|
||||||
config.SCK.Configure(PinConfig{Mode: PinOutput50MHz + pinOutputModeAltPushPull})
|
config.SCK.Configure(PinConfig{Mode: PinOutput50MHz + PinOutputModeAltPushPull})
|
||||||
config.SDO.Configure(PinConfig{Mode: PinOutput50MHz + pinOutputModeAltPushPull})
|
config.SDO.Configure(PinConfig{Mode: PinOutput50MHz + PinOutputModeAltPushPull})
|
||||||
config.SDI.Configure(PinConfig{Mode: pinInputModeFloating})
|
config.SDI.Configure(PinConfig{Mode: PinInputModeFloating})
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------- I2C related types and code
|
//---------- I2C related types and code
|
||||||
@@ -390,8 +390,8 @@ func (i2c *I2C) configurePins(config I2CConfig) {
|
|||||||
stm32.AFIO.MAPR.SetBits(stm32.AFIO_MAPR_I2C1_REMAP)
|
stm32.AFIO.MAPR.SetBits(stm32.AFIO_MAPR_I2C1_REMAP)
|
||||||
}
|
}
|
||||||
|
|
||||||
config.SDA.Configure(PinConfig{Mode: PinOutput50MHz + pinOutputModeAltOpenDrain})
|
config.SDA.Configure(PinConfig{Mode: PinOutput50MHz + PinOutputModeAltOpenDrain})
|
||||||
config.SCL.Configure(PinConfig{Mode: PinOutput50MHz + pinOutputModeAltOpenDrain})
|
config.SCL.Configure(PinConfig{Mode: PinOutput50MHz + PinOutputModeAltOpenDrain})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i2c *I2C) getFreqRange(config I2CConfig) uint32 {
|
func (i2c *I2C) getFreqRange(config I2CConfig) uint32 {
|
||||||
@@ -717,7 +717,7 @@ func (t *TIM) configurePin(channel uint8, pf PinFunction) {
|
|||||||
stm32.AFIO.MAPR.ReplaceBits(remap<<stm32.AFIO_MAPR2_TIM14_REMAP_Pos, stm32.AFIO_MAPR2_TIM14_REMAP_Msk, 0)
|
stm32.AFIO.MAPR.ReplaceBits(remap<<stm32.AFIO_MAPR2_TIM14_REMAP_Pos, stm32.AFIO_MAPR2_TIM14_REMAP_Msk, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pf.Pin.Configure(PinConfig{Mode: PinOutput + pinOutputModeAltPushPull})
|
pf.Pin.Configure(PinConfig{Mode: PinOutput + PinOutputModeAltPushPull})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TIM) enableMainOutput() {
|
func (t *TIM) enableMainOutput() {
|
||||||
|
|||||||
@@ -640,8 +640,8 @@ const (
|
|||||||
|
|
||||||
func (uart *UART) configurePins(config UARTConfig) {
|
func (uart *UART) configurePins(config UARTConfig) {
|
||||||
// enable the alternate functions on the TX and RX pins
|
// enable the alternate functions on the TX and RX pins
|
||||||
config.TX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTTX}, uart.TxAltFuncSelector)
|
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||||
config.RX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTRX}, uart.RxAltFuncSelector)
|
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 {
|
func (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 {
|
||||||
@@ -674,9 +674,9 @@ func (spi SPI) config8Bits() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) configurePins(config SPIConfig) {
|
func (spi SPI) configurePins(config SPIConfig) {
|
||||||
config.SCK.ConfigureAltFunc(PinConfig{Mode: pinModeSPICLK}, spi.AltFuncSelector)
|
config.SCK.ConfigureAltFunc(PinConfig{Mode: PinModeSPICLK}, spi.AltFuncSelector)
|
||||||
config.SDO.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDO}, spi.AltFuncSelector)
|
config.SDO.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDO}, spi.AltFuncSelector)
|
||||||
config.SDI.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDI}, spi.AltFuncSelector)
|
config.SDI.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDI}, spi.AltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
||||||
@@ -723,8 +723,8 @@ type I2C struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i2c *I2C) configurePins(config I2CConfig) {
|
func (i2c *I2C) configurePins(config I2CConfig) {
|
||||||
config.SCL.ConfigureAltFunc(PinConfig{Mode: pinModeI2CSCL}, i2c.AltFuncSelector)
|
config.SCL.ConfigureAltFunc(PinConfig{Mode: PinModeI2CSCL}, i2c.AltFuncSelector)
|
||||||
config.SDA.ConfigureAltFunc(PinConfig{Mode: pinModeI2CSDA}, i2c.AltFuncSelector)
|
config.SDA.ConfigureAltFunc(PinConfig{Mode: PinModeI2CSDA}, i2c.AltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i2c *I2C) getFreqRange(config I2CConfig) uint32 {
|
func (i2c *I2C) getFreqRange(config I2CConfig) uint32 {
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ const APB2_TIM_FREQ = 216e6 // 216MHz
|
|||||||
// Configure the UART.
|
// Configure the UART.
|
||||||
func (uart *UART) configurePins(config UARTConfig) {
|
func (uart *UART) configurePins(config UARTConfig) {
|
||||||
// enable the alternate functions on the TX and RX pins
|
// enable the alternate functions on the TX and RX pins
|
||||||
config.TX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTTX}, uart.TxAltFuncSelector)
|
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||||
config.RX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTRX}, uart.RxAltFuncSelector)
|
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UART baudrate calc based on the bus and clockspeed
|
// UART baudrate calc based on the bus and clockspeed
|
||||||
|
|||||||
@@ -195,8 +195,8 @@ func (p Pin) registerInterrupt() interrupt.Interrupt {
|
|||||||
// Configure the UART.
|
// Configure the UART.
|
||||||
func (uart *UART) configurePins(config UARTConfig) {
|
func (uart *UART) configurePins(config UARTConfig) {
|
||||||
// enable the alternate functions on the TX and RX pins
|
// enable the alternate functions on the TX and RX pins
|
||||||
config.TX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTTX}, uart.TxAltFuncSelector)
|
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||||
config.RX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTRX}, uart.RxAltFuncSelector)
|
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UART baudrate calc based on the bus and clockspeed
|
// UART baudrate calc based on the bus and clockspeed
|
||||||
@@ -289,9 +289,9 @@ func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
|||||||
|
|
||||||
// Configure SPI pins for input output and clock
|
// Configure SPI pins for input output and clock
|
||||||
func (spi SPI) configurePins(config SPIConfig) {
|
func (spi SPI) configurePins(config SPIConfig) {
|
||||||
config.SCK.ConfigureAltFunc(PinConfig{Mode: pinModeSPICLK}, spi.AltFuncSelector)
|
config.SCK.ConfigureAltFunc(PinConfig{Mode: PinModeSPICLK}, spi.AltFuncSelector)
|
||||||
config.SDO.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDO}, spi.AltFuncSelector)
|
config.SDO.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDO}, spi.AltFuncSelector)
|
||||||
config.SDI.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDI}, spi.AltFuncSelector)
|
config.SDI.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDI}, spi.AltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------- I2C related types and code
|
//---------- I2C related types and code
|
||||||
|
|||||||
@@ -280,8 +280,8 @@ func (p Pin) registerInterrupt() interrupt.Interrupt {
|
|||||||
// Configure the UART.
|
// Configure the UART.
|
||||||
func (uart *UART) configurePins(config UARTConfig) {
|
func (uart *UART) configurePins(config UARTConfig) {
|
||||||
// enable the alternate functions on the TX and RX pins
|
// enable the alternate functions on the TX and RX pins
|
||||||
config.TX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTTX}, uart.TxAltFuncSelector)
|
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||||
config.RX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTRX}, uart.RxAltFuncSelector)
|
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UART baudrate calc based on the bus and clockspeed
|
// UART baudrate calc based on the bus and clockspeed
|
||||||
@@ -357,9 +357,9 @@ func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
|||||||
|
|
||||||
// Configure SPI pins for input output and clock
|
// Configure SPI pins for input output and clock
|
||||||
func (spi SPI) configurePins(config SPIConfig) {
|
func (spi SPI) configurePins(config SPIConfig) {
|
||||||
config.SCK.ConfigureAltFunc(PinConfig{Mode: pinModeSPICLK}, spi.AltFuncSelector)
|
config.SCK.ConfigureAltFunc(PinConfig{Mode: PinModeSPICLK}, spi.AltFuncSelector)
|
||||||
config.SDO.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDO}, spi.AltFuncSelector)
|
config.SDO.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDO}, spi.AltFuncSelector)
|
||||||
config.SDI.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDI}, spi.AltFuncSelector)
|
config.SDI.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDI}, spi.AltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------- Timer related code
|
//---------- Timer related code
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ func (uart *UART) configurePins(config UARTConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// enable the alternate functions on the TX and RX pins
|
// enable the alternate functions on the TX and RX pins
|
||||||
config.TX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTTX}, uart.TxAltFuncSelector)
|
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||||
config.RX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTRX}, uart.RxAltFuncSelector)
|
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UART baudrate calc based on the bus and clockspeed
|
// UART baudrate calc based on the bus and clockspeed
|
||||||
|
|||||||
@@ -239,9 +239,9 @@ func (spi SPI) config8Bits() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) configurePins(config SPIConfig) {
|
func (spi SPI) configurePins(config SPIConfig) {
|
||||||
config.SCK.ConfigureAltFunc(PinConfig{Mode: pinModeSPICLK}, spi.AltFuncSelector)
|
config.SCK.ConfigureAltFunc(PinConfig{Mode: PinModeSPICLK}, spi.AltFuncSelector)
|
||||||
config.SDO.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDO}, spi.AltFuncSelector)
|
config.SDO.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDO}, spi.AltFuncSelector)
|
||||||
config.SDI.ConfigureAltFunc(PinConfig{Mode: pinModeSPISDI}, spi.AltFuncSelector)
|
config.SDI.ConfigureAltFunc(PinConfig{Mode: PinModeSPISDI}, spi.AltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
func (spi SPI) getBaudRate(config SPIConfig) uint32 {
|
||||||
@@ -298,8 +298,8 @@ func (i2c *I2C) getFreqRange() uint32 {
|
|||||||
// Configure the UART.
|
// Configure the UART.
|
||||||
func (uart UART) configurePins(config UARTConfig) {
|
func (uart UART) configurePins(config UARTConfig) {
|
||||||
// enable the alternate functions on the TX and RX pins
|
// enable the alternate functions on the TX and RX pins
|
||||||
config.TX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTTX}, uart.TxAltFuncSelector)
|
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||||
config.RX.ConfigureAltFunc(PinConfig{Mode: pinModeUARTRX}, uart.RxAltFuncSelector)
|
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UART baudrate calc based on the bus and clockspeed
|
// UART baudrate calc based on the bus and clockspeed
|
||||||
|
|||||||
Vendored
+25
-25
@@ -4,51 +4,51 @@ import "time"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Test ticker.
|
// Test ticker.
|
||||||
ticker := time.NewTicker(time.Millisecond * 250)
|
ticker := time.NewTicker(time.Millisecond * 500)
|
||||||
println("waiting on ticker")
|
println("waiting on ticker")
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Millisecond * 125)
|
time.Sleep(time.Millisecond * 150)
|
||||||
println(" - after 125ms")
|
println(" - after 150ms")
|
||||||
time.Sleep(time.Millisecond * 250)
|
time.Sleep(time.Millisecond * 200)
|
||||||
println(" - after 375ms")
|
println(" - after 200ms")
|
||||||
time.Sleep(time.Millisecond * 250)
|
time.Sleep(time.Millisecond * 300)
|
||||||
println(" - after 625ms")
|
println(" - after 300ms")
|
||||||
}()
|
}()
|
||||||
<-ticker.C
|
<-ticker.C
|
||||||
println("waited on ticker at 250ms")
|
|
||||||
<-ticker.C
|
|
||||||
println("waited on ticker at 500ms")
|
println("waited on ticker at 500ms")
|
||||||
|
<-ticker.C
|
||||||
|
println("waited on ticker at 1000ms")
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
time.Sleep(time.Millisecond * 500)
|
time.Sleep(time.Millisecond * 750)
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
println("fail: ticker should have stopped!")
|
println("fail: ticker should have stopped!")
|
||||||
default:
|
default:
|
||||||
println("ticker was stopped (didn't send anything after 500ms)")
|
println("ticker was stopped (didn't send anything after 750ms)")
|
||||||
}
|
}
|
||||||
|
|
||||||
timer := time.NewTimer(time.Millisecond * 250)
|
timer := time.NewTimer(time.Millisecond * 500)
|
||||||
println("waiting on timer")
|
println("waiting on timer")
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Millisecond * 125)
|
time.Sleep(time.Millisecond * 200)
|
||||||
println(" - after 125ms")
|
println(" - after 200ms")
|
||||||
time.Sleep(time.Millisecond * 250)
|
time.Sleep(time.Millisecond * 400)
|
||||||
println(" - after 250ms")
|
println(" - after 400ms")
|
||||||
}()
|
}()
|
||||||
<-timer.C
|
<-timer.C
|
||||||
println("waited on timer at 250ms")
|
println("waited on timer at 500ms")
|
||||||
time.Sleep(time.Millisecond * 250)
|
time.Sleep(time.Millisecond * 500)
|
||||||
|
|
||||||
reset := timer.Reset(time.Millisecond * 250)
|
reset := timer.Reset(time.Millisecond * 500)
|
||||||
println("timer reset:", reset)
|
println("timer reset:", reset)
|
||||||
println("waiting on timer")
|
println("waiting on timer")
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Millisecond * 125)
|
time.Sleep(time.Millisecond * 200)
|
||||||
println(" - after 125ms")
|
println(" - after 200ms")
|
||||||
time.Sleep(time.Millisecond * 250)
|
time.Sleep(time.Millisecond * 400)
|
||||||
println(" - after 250ms")
|
println(" - after 400ms")
|
||||||
}()
|
}()
|
||||||
<-timer.C
|
<-timer.C
|
||||||
println("waited on timer at 250ms")
|
println("waited on timer at 500ms")
|
||||||
time.Sleep(time.Millisecond * 250)
|
time.Sleep(time.Millisecond * 500)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+11
-11
@@ -1,16 +1,16 @@
|
|||||||
waiting on ticker
|
waiting on ticker
|
||||||
- after 125ms
|
- after 150ms
|
||||||
waited on ticker at 250ms
|
- after 200ms
|
||||||
- after 375ms
|
|
||||||
waited on ticker at 500ms
|
waited on ticker at 500ms
|
||||||
- after 625ms
|
- after 300ms
|
||||||
ticker was stopped (didn't send anything after 500ms)
|
waited on ticker at 1000ms
|
||||||
|
ticker was stopped (didn't send anything after 750ms)
|
||||||
waiting on timer
|
waiting on timer
|
||||||
- after 125ms
|
- after 200ms
|
||||||
waited on timer at 250ms
|
waited on timer at 500ms
|
||||||
- after 250ms
|
- after 400ms
|
||||||
timer reset: false
|
timer reset: false
|
||||||
waiting on timer
|
waiting on timer
|
||||||
- after 125ms
|
- after 200ms
|
||||||
waited on timer at 250ms
|
waited on timer at 500ms
|
||||||
- after 250ms
|
- after 400ms
|
||||||
|
|||||||
Reference in New Issue
Block a user