aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/machine_atsamd51.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-10-15 21:20:45 +0200
committerRon Evans <[email protected]>2021-10-25 14:49:02 +0200
commite50885a6f2ac2752e1f8c64d20acc7776d355779 (patch)
tree59ab7d71c6d9c7453a9aefbebfd8f064fca16785 /src/machine/machine_atsamd51.go
parent478dd3a28db34d81a8397fa1d6ad3c52371eddb1 (diff)
downloadtinygo-e50885a6f2ac2752e1f8c64d20acc7776d355779.tar.gz
tinygo-e50885a6f2ac2752e1f8c64d20acc7776d355779.zip
sam: simplify definition of SERCOM UART peripherals
Instead of defining them separately for each board, define them once in the chip definition and later simply use &sercomUART1 etc. to refer to them. This is simpler and less error-prone. I found two bugs while working on this: - The P1AM-100 board mixed SERCOM 5 and SERCOM 3. It looks like SERCOM 5 was intended, based on the used pins. - The Adafruit Matrix Portal appears to have configured the wrong interrupt. Unfortunately, I can't test these fixes. However, they make it clear that such a change is important to avoid bugs. I tested this commit on the PyBadge and the Circuit Playground Express.
Diffstat (limited to 'src/machine/machine_atsamd51.go')
-rw-r--r--src/machine/machine_atsamd51.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go
index 4fc5bc62a..b7c96339f 100644
--- a/src/machine/machine_atsamd51.go
+++ b/src/machine/machine_atsamd51.go
@@ -951,10 +951,23 @@ type UART struct {
}
var (
- // USB is a USB CDC interface.
- USB = &USBCDC{Buffer: NewRingBuffer()}
+ sercomUSART0 = UART{Buffer: NewRingBuffer(), Bus: sam.SERCOM0_USART_INT, SERCOM: 0}
+ sercomUSART1 = UART{Buffer: NewRingBuffer(), Bus: sam.SERCOM1_USART_INT, SERCOM: 1}
+ sercomUSART2 = UART{Buffer: NewRingBuffer(), Bus: sam.SERCOM2_USART_INT, SERCOM: 2}
+ sercomUSART3 = UART{Buffer: NewRingBuffer(), Bus: sam.SERCOM3_USART_INT, SERCOM: 3}
+ sercomUSART4 = UART{Buffer: NewRingBuffer(), Bus: sam.SERCOM4_USART_INT, SERCOM: 4}
+ sercomUSART5 = UART{Buffer: NewRingBuffer(), Bus: sam.SERCOM5_USART_INT, SERCOM: 5}
)
+func init() {
+ sercomUSART0.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, sercomUSART0.handleInterrupt)
+ sercomUSART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, sercomUSART1.handleInterrupt)
+ sercomUSART2.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, sercomUSART2.handleInterrupt)
+ sercomUSART3.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, sercomUSART3.handleInterrupt)
+ sercomUSART4.Interrupt = interrupt.New(sam.IRQ_SERCOM4_2, sercomUSART4.handleInterrupt)
+ sercomUSART5.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, sercomUSART5.handleInterrupt)
+}
+
const (
sampleRate16X = 16
lsbFirst = 1
@@ -1950,6 +1963,11 @@ type USBCDC struct {
sent bool
}
+var (
+ // USB is a USB CDC interface.
+ USB = &USBCDC{Buffer: NewRingBuffer()}
+)
+
const (
usbcdcTxSizeMask uint8 = 0x3F
usbcdcTxBankMask uint8 = ^usbcdcTxSizeMask