File tree Expand file tree Collapse file tree 1 file changed +36
-13
lines changed Expand file tree Collapse file tree 1 file changed +36
-13
lines changed Original file line number Diff line number Diff line change @@ -21,19 +21,20 @@ const CPU_FREQUENCY = 48000000
2121type GPIOMode uint8
2222
2323const (
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
You can’t perform that action at this time.
0 commit comments