mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-07 20:43:40 +00:00
sam: add support for Atmel SAMD21 based ItsyBitsy M0
Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
committed by
Ayke van Laethem
parent
1f511786d3
commit
e2be7ccf76
@@ -0,0 +1,31 @@
|
||||
// +build sam,atsamd21g18a,itsybitsy_m0
|
||||
|
||||
package machine
|
||||
|
||||
// GPIO Pins
|
||||
const (
|
||||
D0 = 11 // RX: SERCOM0/PAD[3]
|
||||
D1 = 10 // TX: SERCOM0/PAD[2]
|
||||
D2 = 14
|
||||
D3 = 9
|
||||
D4 = 8
|
||||
D5 = 15
|
||||
D6 = 20
|
||||
D7 = 21
|
||||
D8 = 6
|
||||
D9 = 7
|
||||
D10 = 18
|
||||
D11 = 16
|
||||
D12 = 19
|
||||
D13 = 17
|
||||
)
|
||||
|
||||
const (
|
||||
LED = D13
|
||||
)
|
||||
|
||||
// UART pins
|
||||
const (
|
||||
UART_TX_PIN = 0
|
||||
UART_RX_PIN = 0
|
||||
)
|
||||
@@ -0,0 +1,45 @@
|
||||
// +build sam,atsamd21g18a
|
||||
|
||||
// Peripheral abstraction layer for the atsamd21g18.
|
||||
//
|
||||
// Datasheet:
|
||||
// http://ww1.microchip.com/downloads/en/DeviceDoc/SAMD21-Family-DataSheet-DS40001882D.pdf
|
||||
//
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/sam"
|
||||
)
|
||||
|
||||
const CPU_FREQUENCY = 48000000
|
||||
|
||||
type GPIOMode uint8
|
||||
|
||||
const (
|
||||
GPIO_INPUT = 0
|
||||
GPIO_OUTPUT = 1
|
||||
)
|
||||
|
||||
// Configure this pin with the given configuration.
|
||||
func (p GPIO) Configure(config GPIOConfig) {
|
||||
if config.Mode == GPIO_OUTPUT { // set output bit
|
||||
sam.PORT.DIRSET0 = (1 << p.Pin)
|
||||
} else {
|
||||
sam.PORT.DIRCLR0 = (1 << p.Pin)
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the current value of a GPIO pin.
|
||||
func (p GPIO) Get() bool {
|
||||
return (sam.PORT.IN0>>p.Pin)&1 > 0
|
||||
}
|
||||
|
||||
// Set the pin to high or low.
|
||||
// Warning: only use this on an output pin!
|
||||
func (p GPIO) Set(high bool) {
|
||||
if high {
|
||||
sam.PORT.OUTSET0 = (1 << p.Pin)
|
||||
} else {
|
||||
sam.PORT.OUTCLR0 = (1 << p.Pin)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// +build !avr,!nrf,!stm32
|
||||
// +build !avr,!nrf,!sam,!stm32
|
||||
|
||||
package machine
|
||||
|
||||
|
||||
Reference in New Issue
Block a user