-
Notifications
You must be signed in to change notification settings - Fork 4
/
conf.go
80 lines (67 loc) · 2.17 KB
/
conf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2019 Michal Derkacz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gpio
// Mode specifies operation mode.
type Mode byte
const (
In Mode = 0 // Logical input.
Out Mode = out // Logical output.
Alt Mode = alt // Alternate function output or bidirectional i/o.
AltIn Mode = altIn // Alternate function input.
Ana Mode = ana // Analog mode.
)
// Driver specifies output driver mode.
type Driver byte
const (
PushPull Driver = 0
OpenDrain Driver = openDrain
)
// Speed specifies speed of output driver. Concrete STM32 series implements 3
// or 4 speed levels. Slow, Medium and Fast levels are always implemented. Actual
// speed at given level depends on supply voltage and load capacity. See the
// datasheet for more info.
type Speed int8
const (
VeryLow Speed = veryLow // Typically < 1 MHz.
Low Speed = low // Typically < 2 MHz.
Medium Speed = 0 // Typically < 25 MHz.
High Speed = high // Typically < 50 MHz.
VeryHigh Speed = veryHigh // Typically < 100 MHz.
)
// Pull specifies pull-up/pull-down configuration.
type Pull byte
const (
NoPull Pull = 0 // No pull-up/pull-down
PullUp Pull = pullUp // Activate internal pull-up resistor.
PullDown Pull = pullDown // Activate internal pull-down resistor.
)
// Config contains parameters used to setup GPIO pin.
type Config struct {
Mode Mode // Mode: input, output, analog, alternate function.
Driver Driver // Output driver type: push-pull or open-drain.
Speed Speed // Output speed.
Pull Pull // Pull-up/pull-down resistors.
}
// SetupPin configures one pin.
func (p *Port) SetupPin(index int, cfg *Config) {
setup(p, index, cfg)
}
// Setup configures pins.
func (p *Port) Setup(pins Pins, cfg *Config) {
for n := 0; n < 16; n++ {
if pins&(1<<uint(n)) != 0 {
setup(p, n, cfg)
}
}
}
// Lock locks configuration of specified pins. Locked configuration can not be
// modified until reset.
func (p *Port) Lock(pins Pins) {
pins1 := uint32(pins) | 0x10000
p.lckr.Store(pins1)
p.lckr.Store(uint32(pins))
p.lckr.Store(pins1)
p.lckr.Load()
p.lckr.Load()
}