|
|
@ -473,6 +473,13 @@ var ( |
|
|
|
Buffer: NewRingBuffer(), |
|
|
|
Mode: PinSERCOMAlt, |
|
|
|
} |
|
|
|
|
|
|
|
// The second hardware serial port on the SAMD51. Uses the SERCOM0 interface.
|
|
|
|
UART2 = UART{ |
|
|
|
Buffer: NewRingBuffer(), |
|
|
|
Bus: sam.SERCOM0_USART_INT, |
|
|
|
Mode: PinSERCOMAlt, |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
const ( |
|
|
@ -522,6 +529,8 @@ func (uart UART) Configure(config UARTConfig) { |
|
|
|
} |
|
|
|
|
|
|
|
switch config.RX { |
|
|
|
case PA06: |
|
|
|
rxpad = sercomRXPad2 |
|
|
|
case PA07: |
|
|
|
rxpad = sercomRXPad3 |
|
|
|
case PA11: |
|
|
@ -591,11 +600,20 @@ func (uart UART) Configure(config UARTConfig) { |
|
|
|
// setup interrupt on receive
|
|
|
|
uart.Bus.INTENSET.Set(sam.SERCOM_USART_INT_INTENSET_RXC) |
|
|
|
|
|
|
|
// Enable RX IRQ. Currently assumes SERCOM3.
|
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_0) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_1) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_2) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_OTHER) |
|
|
|
// Enable RX IRQ.
|
|
|
|
switch uart.Bus { |
|
|
|
case sam.SERCOM0_USART_INT: |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM0_0) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM0_1) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM0_2) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM0_OTHER) |
|
|
|
default: |
|
|
|
// Currently assumes SERCOM3
|
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_0) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_1) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_2) |
|
|
|
arm.EnableIRQ(sam.IRQ_SERCOM3_OTHER) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// SetBaudRate sets the communication speed for the UART.
|
|
|
@ -647,6 +665,32 @@ func handleUART1() { |
|
|
|
UART1.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC) |
|
|
|
} |
|
|
|
|
|
|
|
//go:export SERCOM0_0_IRQHandler
|
|
|
|
func handleSERCOM0_0() { |
|
|
|
handleUART2() |
|
|
|
} |
|
|
|
|
|
|
|
//go:export SERCOM0_1_IRQHandler
|
|
|
|
func handleSERCOM0_1() { |
|
|
|
handleUART2() |
|
|
|
} |
|
|
|
|
|
|
|
//go:export SERCOM0_2_IRQHandler
|
|
|
|
func handleSERCOM0_2() { |
|
|
|
handleUART2() |
|
|
|
} |
|
|
|
|
|
|
|
//go:export SERCOM0_OTHER_IRQHandler
|
|
|
|
func handleSERCOM0_OTHER() { |
|
|
|
handleUART2() |
|
|
|
} |
|
|
|
|
|
|
|
func handleUART2() { |
|
|
|
// should reset IRQ
|
|
|
|
UART2.Receive(byte((UART2.Bus.DATA.Get() & 0xFF))) |
|
|
|
UART2.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC) |
|
|
|
} |
|
|
|
|
|
|
|
// I2C on the SAMD51.
|
|
|
|
type I2C struct { |
|
|
|
Bus *sam.SERCOM_I2CM_Type |
|
|
|