mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-18 03:24:00 +00:00
machine/atsamd21: add GPIO_INPUT_PULLUP and GPIO_INPUT_PULLDOWN GPIO pin config options
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
@@ -34,6 +34,7 @@ const (
|
|||||||
GPIO_OUTPUT = 11
|
GPIO_OUTPUT = 11
|
||||||
GPIO_PWM = GPIO_TIMER
|
GPIO_PWM = GPIO_TIMER
|
||||||
GPIO_PWM_ALT = GPIO_TIMER_ALT
|
GPIO_PWM_ALT = GPIO_TIMER_ALT
|
||||||
|
GPIO_INPUT_PULLDOWN = 12
|
||||||
)
|
)
|
||||||
|
|
||||||
// Hardware pins
|
// Hardware pins
|
||||||
@@ -127,6 +128,28 @@ func (p GPIO) Configure(config GPIOConfig) {
|
|||||||
p.setPinCfg(sam.PORT_PINCFG0_INEN)
|
p.setPinCfg(sam.PORT_PINCFG0_INEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case GPIO_INPUT_PULLDOWN:
|
||||||
|
if p.Pin < 32 {
|
||||||
|
sam.PORT.DIRCLR0 = (1 << p.Pin)
|
||||||
|
sam.PORT.OUTCLR0 = (1 << p.Pin)
|
||||||
|
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
||||||
|
} else {
|
||||||
|
sam.PORT.DIRCLR1 = (1<<p.Pin - 32)
|
||||||
|
sam.PORT.OUTCLR1 = (1<<p.Pin - 32)
|
||||||
|
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
||||||
|
}
|
||||||
|
|
||||||
|
case GPIO_INPUT_PULLUP:
|
||||||
|
if p.Pin < 32 {
|
||||||
|
sam.PORT.DIRCLR0 = (1 << p.Pin)
|
||||||
|
sam.PORT.OUTSET0 = (1 << p.Pin)
|
||||||
|
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
||||||
|
} else {
|
||||||
|
sam.PORT.DIRCLR1 = (1<<p.Pin - 32)
|
||||||
|
sam.PORT.OUTSET1 = (1<<p.Pin - 32)
|
||||||
|
p.setPinCfg(sam.PORT_PINCFG0_INEN | sam.PORT_PINCFG0_PULLEN)
|
||||||
|
}
|
||||||
|
|
||||||
case GPIO_SERCOM:
|
case GPIO_SERCOM:
|
||||||
if p.Pin&1 > 0 {
|
if p.Pin&1 > 0 {
|
||||||
// odd pin, so save the even pins
|
// odd pin, so save the even pins
|
||||||
|
|||||||
Reference in New Issue
Block a user