Skip to content

Commit 34939ab

Browse files
committed
machine/atsamd21: add GPIO_INPUT_PULLUP and GPIO_INPUT_PULLDOWN GPIO pin config options
Signed-off-by: Ron Evans <[email protected]>
1 parent c56b2a4 commit 34939ab

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

src/machine/machine_atsamd21.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ const CPU_FREQUENCY = 48000000
2121
type GPIOMode uint8
2222

2323
const (
24-
GPIO_ANALOG = 1
25-
GPIO_SERCOM = 2
26-
GPIO_SERCOM_ALT = 3
27-
GPIO_TIMER = 4
28-
GPIO_TIMER_ALT = 5
29-
GPIO_COM = 6
30-
GPIO_AC_CLK = 7
31-
GPIO_DIGITAL = 8
32-
GPIO_INPUT = 9
33-
GPIO_INPUT_PULLUP = 10
34-
GPIO_OUTPUT = 11
35-
GPIO_PWM = GPIO_TIMER
36-
GPIO_PWM_ALT = GPIO_TIMER_ALT
24+
GPIO_ANALOG = 1
25+
GPIO_SERCOM = 2
26+
GPIO_SERCOM_ALT = 3
27+
GPIO_TIMER = 4
28+
GPIO_TIMER_ALT = 5
29+
GPIO_COM = 6
30+
GPIO_AC_CLK = 7
31+
GPIO_DIGITAL = 8
32+
GPIO_INPUT = 9
33+
GPIO_INPUT_PULLUP = 10
34+
GPIO_OUTPUT = 11
35+
GPIO_PWM = GPIO_TIMER
36+
GPIO_PWM_ALT = GPIO_TIMER_ALT
37+
GPIO_INPUT_PULLDOWN = 12
3738
)
3839

3940
// Hardware pins
@@ -127,6 +128,28 @@ func (p GPIO) Configure(config GPIOConfig) {
127128
p.setPinCfg(sam.PORT_PINCFG0_INEN)
128129
}
129130

131+
case GPIO_INPUT_PULLDOWN:
132+
if p.Pin < 32 {
133+
sam.PORT.DIRCLR0 = (1 << p.Pin)
134+
sam.PORT.OUTCLR0 = (1 << p.Pin)
135+
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
136+
} else {
137+
sam.PORT.DIRCLR1 = (1<<p.Pin - 32)
138+
sam.PORT.OUTCLR1 = (1<<p.Pin - 32)
139+
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
140+
}
141+
142+
case GPIO_INPUT_PULLUP:
143+
if p.Pin < 32 {
144+
sam.PORT.DIRCLR0 = (1 << p.Pin)
145+
sam.PORT.OUTSET0 = (1 << p.Pin)
146+
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
147+
} else {
148+
sam.PORT.DIRCLR1 = (1<<p.Pin - 32)
149+
sam.PORT.OUTSET1 = (1<<p.Pin - 32)
150+
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
151+
}
152+
130153
case GPIO_SERCOM:
131154
if p.Pin&1 > 0 {
132155
// odd pin, so save the even pins

0 commit comments

Comments
 (0)