mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
b67351babe
Previously, the machine.UART0 object had two meanings:
- it was the first UART on the chip
- it was the default output for println
These two meanings conflict, and resulted in workarounds like:
- Defining UART0 to refer to the USB-CDC interface (atsamd21,
atsamd51, nrf52840), even though that clearly isn't an UART.
- Defining NRF_UART0 to avoid a conflict with UART0 (which was
redefined as a USB-CDC interface).
- Defining aliases like UART0 = UART1, which refer to the same
hardware peripheral (stm32).
This commit changes this to use a new machine.Serial object for the
default serial port. It might refer to the first or second UART
depending on the board, or even to the USB-CDC interface. Also, UART0
now really refers to the first UART on the chip, no longer to a USB-CDC
interface.
The changes in the runtime package are all just search+replace. The
changes in the machine package are a mixture of search+replace and
manual modifications.
This commit does not affect binary size, in fact it doesn't affect the
resulting binary at all.
108 lines
1.4 KiB
Go
108 lines
1.4 KiB
Go
// +build sam,atsamd21,trinket_m0
|
|
|
|
package machine
|
|
|
|
import (
|
|
"device/sam"
|
|
"runtime/interrupt"
|
|
)
|
|
|
|
// used to reset into bootloader
|
|
const RESET_MAGIC_VALUE = 0xf01669ef
|
|
|
|
// GPIO Pins
|
|
const (
|
|
D0 = PA08 // PWM available
|
|
D1 = PA02
|
|
D2 = PA09 // PWM available
|
|
D3 = PA07 // PWM available / UART0 RX
|
|
D4 = PA06 // PWM available / UART0 TX
|
|
D13 = PA10 // LED
|
|
)
|
|
|
|
// Analog pins
|
|
const (
|
|
A0 = D1
|
|
A1 = D2
|
|
A2 = D0
|
|
A3 = D3
|
|
A4 = D4
|
|
)
|
|
|
|
const (
|
|
LED = D13
|
|
)
|
|
|
|
// USBCDC pins
|
|
const (
|
|
USBCDC_DM_PIN = PA24
|
|
USBCDC_DP_PIN = PA25
|
|
)
|
|
|
|
// UART1 pins
|
|
const (
|
|
UART_TX_PIN = D4
|
|
UART_RX_PIN = D3
|
|
)
|
|
|
|
// UART1 on the Trinket M0.
|
|
var (
|
|
UART1 = &_UART1
|
|
_UART1 = UART{
|
|
Buffer: NewRingBuffer(),
|
|
Bus: sam.SERCOM0_USART,
|
|
SERCOM: 0,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0, _UART1.handleInterrupt)
|
|
}
|
|
|
|
// SPI pins
|
|
const (
|
|
SPI0_SCK_PIN = D3
|
|
SPI0_SDO_PIN = D4
|
|
SPI0_SDI_PIN = D2
|
|
)
|
|
|
|
// SPI on the Trinket M0.
|
|
var (
|
|
SPI0 = SPI{
|
|
Bus: sam.SERCOM0_SPI,
|
|
SERCOM: 0,
|
|
}
|
|
)
|
|
|
|
// I2C pins
|
|
const (
|
|
SDA_PIN = D0 // SDA
|
|
SCL_PIN = D2 // SCL
|
|
)
|
|
|
|
// I2C on the Trinket M0.
|
|
var (
|
|
I2C0 = &I2C{
|
|
Bus: sam.SERCOM2_I2CM,
|
|
SERCOM: 2,
|
|
}
|
|
)
|
|
|
|
// I2S pins
|
|
const (
|
|
I2S_SCK_PIN = PA10
|
|
I2S_SD_PIN = PA08
|
|
I2S_WS_PIN = NoPin // TODO: figure out what this is on Trinket M0.
|
|
)
|
|
|
|
// USB CDC identifiers
|
|
const (
|
|
usb_STRING_PRODUCT = "Adafruit Trinket M0"
|
|
usb_STRING_MANUFACTURER = "Adafruit"
|
|
)
|
|
|
|
var (
|
|
usb_VID uint16 = 0x239A
|
|
usb_PID uint16 = 0x801E
|
|
)
|