machine: make UART objects pointer receivers
This means that machine.UART0, machine.UART1, etc are of type *machine.UART, not machine.UART. This makes them easier to pass around and avoids surprises when they are passed around by value while they should be passed around by reference. There is a small code size impact in some cases, but it is relatively minor.
Этот коммит содержится в:
родитель
7c949ad386
коммит
aa5b8d0df7
46 изменённых файлов: 246 добавлений и 179 удалений
|
@ -9,7 +9,8 @@ import (
|
|||
|
||||
// UART1 on the Arduino Nano 33 connects to the onboard NINA-W102 WiFi chip.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM3_USART,
|
||||
SERCOM: 3,
|
||||
|
@ -18,7 +19,8 @@ var (
|
|||
|
||||
// UART2 on the Arduino Nano 33 connects to the normal TX/RX pins.
|
||||
var (
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM5_USART,
|
||||
SERCOM: 5,
|
||||
|
@ -26,8 +28,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM5, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM5, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the Arduino Nano 33.
|
||||
|
|
|
@ -240,28 +240,32 @@ var (
|
|||
// UART on the SAM E54 Xplained Pro
|
||||
var (
|
||||
// Extension Header EXT1
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
}
|
||||
|
||||
// Extension Header EXT2
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM5_USART_INT,
|
||||
SERCOM: 5,
|
||||
}
|
||||
|
||||
// Extension Header EXT3
|
||||
UART3 = UART{
|
||||
UART3 = &_UART3
|
||||
_UART3 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM1_USART_INT,
|
||||
SERCOM: 1,
|
||||
}
|
||||
|
||||
// EDBG Virtual COM Port
|
||||
UART4 = UART{
|
||||
UART4 = &_UART4
|
||||
_UART4 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM2_USART_INT,
|
||||
SERCOM: 2,
|
||||
|
@ -269,10 +273,10 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, UART3.handleInterrupt)
|
||||
UART4.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, UART4.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, _UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, _UART3.handleInterrupt)
|
||||
UART4.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, _UART4.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the SAM E54 Xplained Pro
|
||||
|
|
|
@ -61,19 +61,21 @@ const (
|
|||
var (
|
||||
// USART1 is the first hardware serial port on the STM32.
|
||||
// Both UART0 and UART1 refer to USART1.
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART1,
|
||||
}
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART2,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART1, UART0.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, UART1.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART0.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
|
||||
// UART1 on the Circuit Playground Express.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM4_USART,
|
||||
SERCOM: 4,
|
||||
|
@ -17,7 +18,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the Circuit Playground Express.
|
||||
|
|
|
@ -56,7 +56,8 @@ const (
|
|||
|
||||
// UART1 on the Feather M0.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM1_USART,
|
||||
SERCOM: 1,
|
||||
|
@ -64,7 +65,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C pins
|
||||
|
|
|
@ -103,13 +103,15 @@ var (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM5_USART_INT,
|
||||
SERCOM: 5,
|
||||
}
|
||||
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
|
@ -117,8 +119,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART2.handleInterrupt)
|
||||
|
||||
// turn on neopixel
|
||||
D7.Configure(PinConfig{Mode: PinOutput})
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM5_USART_INT,
|
||||
SERCOM: 5,
|
||||
}
|
||||
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
|
@ -22,8 +24,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the Feather M4.
|
||||
|
|
|
@ -119,19 +119,22 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART3,
|
||||
TxAltFuncSelector: AF7_USART1_2_3,
|
||||
RxAltFuncSelector: AF7_USART1_2_3,
|
||||
}
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART6,
|
||||
TxAltFuncSelector: AF8_USART4_5_6,
|
||||
RxAltFuncSelector: AF8_USART4_5_6,
|
||||
}
|
||||
UART3 = UART{
|
||||
UART3 = &_UART3
|
||||
_UART3 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART1,
|
||||
TxAltFuncSelector: AF7_USART1_2_3,
|
||||
|
@ -141,9 +144,9 @@ var (
|
|||
)
|
||||
|
||||
func initUART() {
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART3, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(stm32.IRQ_USART6, UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(stm32.IRQ_USART1, UART3.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(stm32.IRQ_USART6, _UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART3.handleInterrupt)
|
||||
}
|
||||
|
||||
// -- SPI ----------------------------------------------------------------------
|
||||
|
|
|
@ -8,30 +8,34 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM4_2, UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, UART3.handleInterrupt)
|
||||
UART4.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART4.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM4_2, _UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, _UART3.handleInterrupt)
|
||||
UART4.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, _UART4.handleInterrupt)
|
||||
}
|
||||
|
||||
// UART on the Grand Central M4
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
}
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM4_USART_INT,
|
||||
SERCOM: 4,
|
||||
}
|
||||
UART3 = UART{
|
||||
UART3 = &_UART3
|
||||
_UART3 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM1_USART_INT,
|
||||
SERCOM: 1,
|
||||
}
|
||||
UART4 = UART{
|
||||
UART4 = &_UART4
|
||||
_UART4 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM5_USART_INT,
|
||||
SERCOM: 5,
|
||||
|
|
|
@ -56,7 +56,8 @@ const (
|
|||
|
||||
// UART1 on the ItsyBitsy M0.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM1_USART,
|
||||
SERCOM: 1,
|
||||
|
@ -64,7 +65,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C pins
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM3_USART_INT,
|
||||
SERCOM: 3,
|
||||
}
|
||||
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
|
@ -22,8 +24,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the ItsyBitsy M4.
|
||||
|
|
|
@ -57,7 +57,8 @@ const (
|
|||
var (
|
||||
|
||||
// Console UART (LPUSART1)
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.LPUART1,
|
||||
TxAltFuncSelector: 6,
|
||||
|
@ -65,7 +66,8 @@ var (
|
|||
}
|
||||
|
||||
// Gps UART
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART1,
|
||||
TxAltFuncSelector: 0,
|
||||
|
@ -88,6 +90,6 @@ var (
|
|||
|
||||
func init() {
|
||||
// Enable UARTs Interrupts
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_AES_RNG_LPUART1, UART0.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART1, UART1.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_AES_RNG_LPUART1, _UART0.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(stm32.IRQ_USART1, _UART1.handleInterrupt)
|
||||
}
|
||||
|
|
|
@ -9,13 +9,15 @@ import (
|
|||
|
||||
// UART on the MatrixPortal M4
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM1_USART_INT,
|
||||
SERCOM: 1,
|
||||
}
|
||||
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM4_USART_INT,
|
||||
SERCOM: 4,
|
||||
|
@ -23,8 +25,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1_1, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM4_1, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM1_1, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM4_1, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the MatrixPortal M4
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM3_USART_INT,
|
||||
SERCOM: 3,
|
||||
}
|
||||
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
|
@ -22,8 +24,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the Metro M4.
|
||||
|
|
|
@ -100,15 +100,16 @@ var (
|
|||
// USART2 is the hardware serial port connected to the onboard ST-LINK
|
||||
// debugger to be exposed as virtual COM port over USB on Nucleo boards.
|
||||
// Both UART0 and UART1 refer to USART2.
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART2,
|
||||
}
|
||||
UART2 = &UART0
|
||||
UART2 = UART0
|
||||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, UART0.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
|
|
|
@ -32,17 +32,18 @@ var (
|
|||
// USART3 is the hardware serial port connected to the onboard ST-LINK
|
||||
// debugger to be exposed as virtual COM port over USB on Nucleo boards.
|
||||
// Both UART0 and UART1 refer to USART2.
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART3,
|
||||
TxAltFuncSelector: UART_ALT_FN,
|
||||
RxAltFuncSelector: UART_ALT_FN,
|
||||
}
|
||||
UART1 = &UART0
|
||||
UART1 = UART0
|
||||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART3, UART0.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART3, _UART0.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
|
|
|
@ -64,13 +64,14 @@ var (
|
|||
// USART2 is the hardware serial port connected to the onboard ST-LINK
|
||||
// debugger to be exposed as virtual COM port over USB on Nucleo boards.
|
||||
// Both UART0 and UART1 refer to USART2.
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART2,
|
||||
TxAltFuncSelector: 4,
|
||||
RxAltFuncSelector: 4,
|
||||
}
|
||||
UART1 = &UART0
|
||||
UART1 = UART0
|
||||
|
||||
// I2C1 is documented, alias to I2C0 as well
|
||||
I2C1 = &I2C{
|
||||
|
@ -88,5 +89,5 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, UART0.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt)
|
||||
}
|
||||
|
|
|
@ -66,13 +66,14 @@ var (
|
|||
// USART2 is the hardware serial port connected to the onboard ST-LINK
|
||||
// debugger to be exposed as virtual COM port over USB on Nucleo boards.
|
||||
// Both UART0 and UART1 refer to USART2.
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART2,
|
||||
TxAltFuncSelector: 7,
|
||||
RxAltFuncSelector: 3,
|
||||
}
|
||||
UART1 = &UART0
|
||||
UART1 = UART0
|
||||
|
||||
// I2C1 is documented, alias to I2C0 as well
|
||||
I2C1 = &I2C{
|
||||
|
@ -90,5 +91,5 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, UART0.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt)
|
||||
}
|
||||
|
|
|
@ -32,13 +32,14 @@ var (
|
|||
// LPUART1 is the hardware serial port connected to the onboard ST-LINK
|
||||
// debugger to be exposed as virtual COM port over USB on Nucleo boards.
|
||||
// Both UART0 and UART1 refer to LPUART1.
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.LPUART1,
|
||||
TxAltFuncSelector: UART_ALT_FN,
|
||||
RxAltFuncSelector: UART_ALT_FN,
|
||||
}
|
||||
UART1 = &UART0
|
||||
UART1 = UART0
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -56,5 +57,5 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_LPUART1, UART0.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_LPUART1, _UART0.handleInterrupt)
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
|
||||
// UART1 on the P1AM-100 connects to the normal TX/RX pins.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM3_USART,
|
||||
SERCOM: 5,
|
||||
|
@ -17,7 +18,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the P1AM-100.
|
||||
|
|
|
@ -8,13 +8,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM5_USART_INT,
|
||||
SERCOM: 5,
|
||||
}
|
||||
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART_INT,
|
||||
SERCOM: 0,
|
||||
|
@ -22,8 +24,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM5_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the ItsyBitsy M4.
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM4_USART_INT,
|
||||
SERCOM: 4,
|
||||
|
@ -16,7 +17,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4_2, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4_2, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the PyPortal.
|
||||
|
|
|
@ -59,7 +59,8 @@ const (
|
|||
|
||||
// UART1 on the QT Py M0.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART,
|
||||
SERCOM: 0,
|
||||
|
@ -67,7 +68,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
|
|
|
@ -27,18 +27,19 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
UART0 = UART{
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: stm32.USART2,
|
||||
TxAltFuncSelector: AF7_USART1_2_3,
|
||||
RxAltFuncSelector: AF7_USART1_2_3,
|
||||
}
|
||||
UART1 = &UART0
|
||||
UART1 = UART0
|
||||
)
|
||||
|
||||
// set up RX IRQ handler. Follow similar pattern for other UARTx instances
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, UART0.handleInterrupt)
|
||||
UART0.Interrupt = interrupt.New(stm32.IRQ_USART2, _UART0.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
|
|
|
@ -80,11 +80,11 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
TeensyUART1 = &UART0
|
||||
TeensyUART2 = &UART1
|
||||
TeensyUART3 = &UART2
|
||||
TeensyUART4 = &UART3
|
||||
TeensyUART5 = &UART4
|
||||
TeensyUART1 = UART0
|
||||
TeensyUART2 = UART1
|
||||
TeensyUART3 = UART2
|
||||
TeensyUART4 = UART3
|
||||
TeensyUART5 = UART4
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -90,13 +90,13 @@ const (
|
|||
|
||||
func init() {
|
||||
// register any interrupt handlers for this board's peripherals
|
||||
UART1.Interrupt = interrupt.New(nxp.IRQ_LPUART6, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(nxp.IRQ_LPUART4, UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(nxp.IRQ_LPUART2, UART3.handleInterrupt)
|
||||
UART4.Interrupt = interrupt.New(nxp.IRQ_LPUART3, UART4.handleInterrupt)
|
||||
UART5.Interrupt = interrupt.New(nxp.IRQ_LPUART8, UART5.handleInterrupt)
|
||||
UART6.Interrupt = interrupt.New(nxp.IRQ_LPUART1, UART6.handleInterrupt)
|
||||
UART7.Interrupt = interrupt.New(nxp.IRQ_LPUART7, UART7.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(nxp.IRQ_LPUART6, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(nxp.IRQ_LPUART4, _UART2.handleInterrupt)
|
||||
UART3.Interrupt = interrupt.New(nxp.IRQ_LPUART2, _UART3.handleInterrupt)
|
||||
UART4.Interrupt = interrupt.New(nxp.IRQ_LPUART3, _UART4.handleInterrupt)
|
||||
UART5.Interrupt = interrupt.New(nxp.IRQ_LPUART8, _UART5.handleInterrupt)
|
||||
UART6.Interrupt = interrupt.New(nxp.IRQ_LPUART1, _UART6.handleInterrupt)
|
||||
UART7.Interrupt = interrupt.New(nxp.IRQ_LPUART7, _UART7.handleInterrupt)
|
||||
}
|
||||
|
||||
// #=====================================================#
|
||||
|
@ -136,8 +136,9 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
UART0 = &UART1 // alias UART0 to UART1
|
||||
UART1 = UART{
|
||||
UART0 = UART1 // alias UART0 to UART1
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Bus: nxp.LPUART6,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
@ -150,7 +151,8 @@ var (
|
|||
sel: &nxp.IOMUXC.LPUART6_TX_SELECT_INPUT,
|
||||
},
|
||||
}
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Bus: nxp.LPUART4,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
@ -163,7 +165,8 @@ var (
|
|||
sel: &nxp.IOMUXC.LPUART4_TX_SELECT_INPUT,
|
||||
},
|
||||
}
|
||||
UART3 = UART{
|
||||
UART3 = &_UART3
|
||||
_UART3 = UART{
|
||||
Bus: nxp.LPUART2,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
@ -176,7 +179,8 @@ var (
|
|||
sel: &nxp.IOMUXC.LPUART2_TX_SELECT_INPUT,
|
||||
},
|
||||
}
|
||||
UART4 = UART{
|
||||
UART4 = &_UART4
|
||||
_UART4 = UART{
|
||||
Bus: nxp.LPUART3,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
@ -189,7 +193,8 @@ var (
|
|||
sel: &nxp.IOMUXC.LPUART3_TX_SELECT_INPUT,
|
||||
},
|
||||
}
|
||||
UART5 = UART{
|
||||
UART5 = &_UART5
|
||||
_UART5 = UART{
|
||||
Bus: nxp.LPUART8,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
@ -202,7 +207,8 @@ var (
|
|||
sel: &nxp.IOMUXC.LPUART8_TX_SELECT_INPUT,
|
||||
},
|
||||
}
|
||||
UART6 = UART{
|
||||
UART6 = &_UART6
|
||||
_UART6 = UART{
|
||||
Bus: nxp.LPUART1,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
@ -210,7 +216,8 @@ var (
|
|||
// RX: D24 (PA12 [AD_B0_12])
|
||||
// TX: D25 (PA13 [AD_B0_13])
|
||||
}
|
||||
UART7 = UART{
|
||||
UART7 = &_UART7
|
||||
_UART7 = UART{
|
||||
Bus: nxp.LPUART7,
|
||||
Buffer: NewRingBuffer(),
|
||||
txBuffer: NewRingBuffer(),
|
||||
|
|
|
@ -47,7 +47,8 @@ const (
|
|||
|
||||
// UART1 on the Trinket M0.
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM0_USART,
|
||||
SERCOM: 0,
|
||||
|
@ -55,7 +56,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM0, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// SPI pins
|
||||
|
|
|
@ -8,14 +8,16 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM2_USART_INT,
|
||||
SERCOM: 2,
|
||||
}
|
||||
|
||||
// RTL8720D
|
||||
UART2 = UART{
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM1_USART_INT,
|
||||
SERCOM: 1,
|
||||
|
@ -23,8 +25,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, UART2.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, _UART1.handleInterrupt)
|
||||
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM1_2, _UART2.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C on the Wio Terminal
|
||||
|
|
|
@ -62,7 +62,8 @@ const (
|
|||
|
||||
// UART1 on the Xiao
|
||||
var (
|
||||
UART1 = UART{
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{
|
||||
Buffer: NewRingBuffer(),
|
||||
Bus: sam.SERCOM4_USART,
|
||||
SERCOM: 4,
|
||||
|
@ -70,7 +71,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4, UART1.handleInterrupt)
|
||||
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM4, _UART1.handleInterrupt)
|
||||
}
|
||||
|
||||
// I2C pins
|
||||
|
|
|
@ -124,7 +124,8 @@ func (i2c *I2C) readByte() byte {
|
|||
// UART
|
||||
var (
|
||||
// UART0 is the hardware serial port on the AVR.
|
||||
UART0 = UART{Buffer: NewRingBuffer()}
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{Buffer: NewRingBuffer()}
|
||||
)
|
||||
|
||||
// UART on the AVR.
|
||||
|
@ -133,7 +134,7 @@ type UART struct {
|
|||
}
|
||||
|
||||
// Configure the UART on the AVR. Defaults to 9600 baud on Arduino.
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
if config.BaudRate == 0 {
|
||||
config.BaudRate = 9600
|
||||
}
|
||||
|
@ -165,7 +166,7 @@ func (uart UART) Configure(config UARTConfig) {
|
|||
}
|
||||
|
||||
// WriteByte writes a byte of data to the UART.
|
||||
func (uart UART) WriteByte(c byte) error {
|
||||
func (uart *UART) WriteByte(c byte) error {
|
||||
// Wait until UART buffer is not busy.
|
||||
for !avr.UCSR0A.HasBits(avr.UCSR0A_UDRE0) {
|
||||
}
|
||||
|
|
|
@ -515,7 +515,7 @@ const (
|
|||
)
|
||||
|
||||
// Configure the UART.
|
||||
func (uart UART) Configure(config UARTConfig) error {
|
||||
func (uart *UART) Configure(config UARTConfig) error {
|
||||
// Default baud rate to 115200.
|
||||
if config.BaudRate == 0 {
|
||||
config.BaudRate = 115200
|
||||
|
@ -614,7 +614,7 @@ func (uart UART) Configure(config UARTConfig) error {
|
|||
}
|
||||
|
||||
// SetBaudRate sets the communication speed for the UART.
|
||||
func (uart UART) SetBaudRate(br uint32) {
|
||||
func (uart *UART) SetBaudRate(br uint32) {
|
||||
// Asynchronous fractional mode (Table 24-2 in datasheet)
|
||||
// BAUD = fref / (sampleRateValue * fbaud)
|
||||
// (multiply by 8, to calculate fractional piece)
|
||||
|
@ -628,7 +628,7 @@ func (uart UART) SetBaudRate(br uint32) {
|
|||
}
|
||||
|
||||
// WriteByte writes a byte of data to the UART.
|
||||
func (uart UART) WriteByte(c byte) error {
|
||||
func (uart *UART) WriteByte(c byte) error {
|
||||
// wait until ready to receive
|
||||
for !uart.Bus.INTFLAG.HasBits(sam.SERCOM_USART_INTFLAG_DRE) {
|
||||
}
|
||||
|
|
|
@ -961,7 +961,7 @@ const (
|
|||
)
|
||||
|
||||
// Configure the UART.
|
||||
func (uart UART) Configure(config UARTConfig) error {
|
||||
func (uart *UART) Configure(config UARTConfig) error {
|
||||
// Default baud rate to 115200.
|
||||
if config.BaudRate == 0 {
|
||||
config.BaudRate = 115200
|
||||
|
@ -1064,7 +1064,7 @@ func (uart UART) Configure(config UARTConfig) error {
|
|||
}
|
||||
|
||||
// SetBaudRate sets the communication speed for the UART.
|
||||
func (uart UART) SetBaudRate(br uint32) {
|
||||
func (uart *UART) SetBaudRate(br uint32) {
|
||||
// Asynchronous fractional mode (Table 24-2 in datasheet)
|
||||
// BAUD = fref / (sampleRateValue * fbaud)
|
||||
// (multiply by 8, to calculate fractional piece)
|
||||
|
@ -1078,7 +1078,7 @@ func (uart UART) SetBaudRate(br uint32) {
|
|||
}
|
||||
|
||||
// WriteByte writes a byte of data to the UART.
|
||||
func (uart UART) WriteByte(c byte) error {
|
||||
func (uart *UART) WriteByte(c byte) error {
|
||||
// wait until ready to receive
|
||||
for !uart.Bus.INTFLAG.HasBits(sam.SERCOM_USART_INT_INTFLAG_DRE) {
|
||||
}
|
||||
|
|
|
@ -252,9 +252,12 @@ func (p Pin) mux() *volatile.Register32 {
|
|||
}
|
||||
|
||||
var (
|
||||
UART0 = UART{Bus: esp.UART0, Buffer: NewRingBuffer()}
|
||||
UART1 = UART{Bus: esp.UART1, Buffer: NewRingBuffer()}
|
||||
UART2 = UART{Bus: esp.UART2, Buffer: NewRingBuffer()}
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{Bus: esp.UART0, Buffer: NewRingBuffer()}
|
||||
UART1 = &_UART1
|
||||
_UART1 = UART{Bus: esp.UART1, Buffer: NewRingBuffer()}
|
||||
UART2 = &_UART2
|
||||
_UART2 = UART{Bus: esp.UART2, Buffer: NewRingBuffer()}
|
||||
)
|
||||
|
||||
type UART struct {
|
||||
|
@ -262,14 +265,14 @@ type UART struct {
|
|||
Buffer *RingBuffer
|
||||
}
|
||||
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
if config.BaudRate == 0 {
|
||||
config.BaudRate = 115200
|
||||
}
|
||||
uart.Bus.CLKDIV.Set(peripheralClock / config.BaudRate)
|
||||
}
|
||||
|
||||
func (uart UART) WriteByte(b byte) error {
|
||||
func (uart *UART) WriteByte(b byte) error {
|
||||
for (uart.Bus.STATUS.Get()>>16)&0xff >= 128 {
|
||||
// Read UART_TXFIFO_CNT from the status register, which indicates how
|
||||
// many bytes there are in the transmit buffer. Wait until there are
|
||||
|
|
|
@ -140,7 +140,8 @@ func (p Pin) PortMaskClear() (*uint32, uint32) {
|
|||
}
|
||||
|
||||
// UART0 is a hardware UART that supports both TX and RX.
|
||||
var UART0 = UART{Buffer: NewRingBuffer()}
|
||||
var UART0 = &_UART0
|
||||
var _UART0 = UART{Buffer: NewRingBuffer()}
|
||||
|
||||
type UART struct {
|
||||
Buffer *RingBuffer
|
||||
|
@ -148,7 +149,7 @@ type UART struct {
|
|||
|
||||
// Configure the UART baud rate. TX and RX pins are fixed by the hardware so
|
||||
// cannot be modified and will be ignored.
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
if config.BaudRate == 0 {
|
||||
config.BaudRate = 115200
|
||||
}
|
||||
|
@ -157,7 +158,7 @@ func (uart UART) Configure(config UARTConfig) {
|
|||
|
||||
// WriteByte writes a single byte to the output buffer. Note that the hardware
|
||||
// includes a buffer of 128 bytes which will be used first.
|
||||
func (uart UART) WriteByte(c byte) error {
|
||||
func (uart *UART) WriteByte(c byte) error {
|
||||
for (esp.UART0.UART_STATUS.Get()>>16)&0xff >= 128 {
|
||||
// Wait until the TX buffer has room.
|
||||
}
|
||||
|
|
|
@ -56,17 +56,18 @@ type UART struct {
|
|||
}
|
||||
|
||||
var (
|
||||
UART0 = UART{Bus: sifive.UART0, Buffer: NewRingBuffer()}
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{Bus: sifive.UART0, Buffer: NewRingBuffer()}
|
||||
)
|
||||
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
// Assuming a 16Mhz Crystal (which is Y1 on the HiFive1), the divisor for a
|
||||
// 115200 baud rate is 138.
|
||||
sifive.UART0.DIV.Set(138)
|
||||
sifive.UART0.TXCTRL.Set(sifive.UART_TXCTRL_ENABLE)
|
||||
sifive.UART0.RXCTRL.Set(sifive.UART_RXCTRL_ENABLE)
|
||||
sifive.UART0.IE.Set(sifive.UART_IE_RXWM) // enable the receive interrupt (only)
|
||||
intr := interrupt.New(sifive.IRQ_UART0, UART0.handleInterrupt)
|
||||
intr := interrupt.New(sifive.IRQ_UART0, _UART0.handleInterrupt)
|
||||
intr.SetPriority(5)
|
||||
intr.Enable()
|
||||
}
|
||||
|
@ -83,7 +84,7 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
|
|||
uart.Receive(c)
|
||||
}
|
||||
|
||||
func (uart UART) WriteByte(c byte) {
|
||||
func (uart *UART) WriteByte(c byte) {
|
||||
for sifive.UART0.TXDATA.Get()&sifive.UART_TXDATA_FULL != 0 {
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ package machine
|
|||
var (
|
||||
SPI0 = SPI{0}
|
||||
I2C0 = &I2C{0}
|
||||
UART0 = UART{0}
|
||||
UART0 = &UART{0}
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -124,34 +124,34 @@ type UARTConfig struct {
|
|||
}
|
||||
|
||||
// Configure the UART.
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
uartConfigure(uart.Bus, config.TX, config.RX)
|
||||
}
|
||||
|
||||
// Read from the UART.
|
||||
func (uart UART) Read(data []byte) (n int, err error) {
|
||||
func (uart *UART) Read(data []byte) (n int, err error) {
|
||||
return uartRead(uart.Bus, &data[0], len(data)), nil
|
||||
}
|
||||
|
||||
// Write to the UART.
|
||||
func (uart UART) Write(data []byte) (n int, err error) {
|
||||
func (uart *UART) Write(data []byte) (n int, err error) {
|
||||
return uartWrite(uart.Bus, &data[0], len(data)), nil
|
||||
}
|
||||
|
||||
// Buffered returns the number of bytes currently stored in the RX buffer.
|
||||
func (uart UART) Buffered() int {
|
||||
func (uart *UART) Buffered() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// ReadByte reads a single byte from the UART.
|
||||
func (uart UART) ReadByte() (byte, error) {
|
||||
func (uart *UART) ReadByte() (byte, error) {
|
||||
var b byte
|
||||
uartRead(uart.Bus, &b, 1)
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// WriteByte writes a single byte to the UART.
|
||||
func (uart UART) WriteByte(b byte) error {
|
||||
func (uart *UART) WriteByte(b byte) error {
|
||||
uartWrite(uart.Bus, &b, 1)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -338,10 +338,11 @@ type UART struct {
|
|||
}
|
||||
|
||||
var (
|
||||
UART0 = UART{Bus: kendryte.UARTHS, Buffer: NewRingBuffer()}
|
||||
UART0 = &_UART0
|
||||
_UART0 = UART{Bus: kendryte.UARTHS, Buffer: NewRingBuffer()}
|
||||
)
|
||||
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
|
||||
// Use default baudrate if not set.
|
||||
if config.BaudRate == 0 {
|
||||
|
@ -366,7 +367,7 @@ func (uart UART) Configure(config UARTConfig) {
|
|||
// Enable interrupts on receive.
|
||||
uart.Bus.IE.Set(kendryte.UARTHS_IE_RXWM)
|
||||
|
||||
intr := interrupt.New(kendryte.IRQ_UARTHS, UART0.handleInterrupt)
|
||||
intr := interrupt.New(kendryte.IRQ_UARTHS, _UART0.handleInterrupt)
|
||||
intr.SetPriority(5)
|
||||
intr.Enable()
|
||||
}
|
||||
|
@ -383,7 +384,7 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
|
|||
uart.Receive(c)
|
||||
}
|
||||
|
||||
func (uart UART) WriteByte(c byte) {
|
||||
func (uart *UART) WriteByte(c byte) {
|
||||
for uart.Bus.TXDATA.Get()&kendryte.UARTHS_TXDATA_FULL != 0 {
|
||||
}
|
||||
|
||||
|
|
|
@ -137,12 +137,13 @@ type UART struct {
|
|||
|
||||
// UART
|
||||
var (
|
||||
// NRF_UART0 is the hardware UART on the NRF SoC.
|
||||
NRF_UART0 = UART{Buffer: NewRingBuffer()}
|
||||
// UART0 is the hardware UART on the NRF SoC.
|
||||
_NRF_UART0 = UART{Buffer: NewRingBuffer()}
|
||||
NRF_UART0 = &_NRF_UART0
|
||||
)
|
||||
|
||||
// Configure the UART.
|
||||
func (uart UART) Configure(config UARTConfig) {
|
||||
func (uart *UART) Configure(config UARTConfig) {
|
||||
// Default baud rate to 115200.
|
||||
if config.BaudRate == 0 {
|
||||
config.BaudRate = 115200
|
||||
|
@ -164,13 +165,13 @@ func (uart UART) Configure(config UARTConfig) {
|
|||
nrf.UART0.INTENSET.Set(nrf.UART_INTENSET_RXDRDY_Msk)
|
||||
|
||||
// Enable RX IRQ.
|
||||
intr := interrupt.New(nrf.IRQ_UART0, NRF_UART0.handleInterrupt)
|
||||
intr := interrupt.New(nrf.IRQ_UART0, _NRF_UART0.handleInterrupt)
|
||||
intr.SetPriority(0xc0) // low priority
|
||||
intr.Enable()
|
||||
}
|
||||
|
||||
// SetBaudRate sets the communication speed for the UART.
|
||||
func (uart UART) SetBaudRate(br uint32) {
|
||||
func (uart *UART) SetBaudRate(br uint32) {
|
||||
// Magic: calculate 'baudrate' register from the input number.
|
||||
// Every value listed in the datasheet will be converted to the
|
||||
// correct register value, except for 192600. I suspect the value
|
||||
|
@ -185,7 +186,7 @@ func (uart UART) SetBaudRate(br uint32) {
|
|||
}
|
||||
|
||||
// WriteByte writes a byte of data to the UART.
|
||||
func (uart UART) WriteByte(c byte) error {
|
||||
func (uart *UART) WriteByte(c byte) error {
|
||||
nrf.UART0.EVENTS_TXDRDY.Set(0)
|
||||
nrf.UART0.TXD.Set(uint32(c))
|
||||
for nrf.UART0.EVENTS_TXDRDY.Get() == 0 {
|
||||
|
|
|
@ -19,7 +19,7 @@ func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
|
|||
return nrf.GPIO, uint32(p)
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx Pin) {
|
||||
func (uart *UART) setPins(tx, rx Pin) {
|
||||
nrf.UART0.PSELTXD.Set(uint32(tx))
|
||||
nrf.UART0.PSELRXD.Set(uint32(rx))
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
|
|||
return nrf.P0, uint32(p)
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx Pin) {
|
||||
func (uart *UART) setPins(tx, rx Pin) {
|
||||
nrf.UART0.PSELTXD.Set(uint32(tx))
|
||||
nrf.UART0.PSELRXD.Set(uint32(rx))
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
|
|||
}
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx Pin) {
|
||||
func (uart *UART) setPins(tx, rx Pin) {
|
||||
nrf.UART0.PSEL.TXD.Set(uint32(tx))
|
||||
nrf.UART0.PSEL.RXD.Set(uint32(rx))
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func (p Pin) getPortPin() (*nrf.GPIO_Type, uint32) {
|
|||
}
|
||||
}
|
||||
|
||||
func (uart UART) setPins(tx, rx Pin) {
|
||||
func (uart *UART) setPins(tx, rx Pin) {
|
||||
nrf.UART0.PSEL.TXD.Set(uint32(tx))
|
||||
nrf.UART0.PSEL.RXD.Set(uint32(rx))
|
||||
}
|
||||
|
|
|
@ -101,18 +101,25 @@ type UART struct {
|
|||
Interrupt interrupt.Interrupt
|
||||
}
|
||||
|
||||
var UART0 = UART{UART_Type: nxp.UART0, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART0, DefaultRX: defaultUART0RX, DefaultTX: defaultUART0TX}
|
||||
var UART1 = UART{UART_Type: nxp.UART1, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART1, DefaultRX: defaultUART1RX, DefaultTX: defaultUART1TX}
|
||||
var UART2 = UART{UART_Type: nxp.UART2, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART2, DefaultRX: defaultUART2RX, DefaultTX: defaultUART2TX}
|
||||
var UART3 = UART{UART_Type: nxp.UART3, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART3, DefaultRX: defaultUART3RX, DefaultTX: defaultUART3TX}
|
||||
var UART4 = UART{UART_Type: nxp.UART4, SCGC: &nxp.SIM.SCGC1, SCGCMask: nxp.SIM_SCGC1_UART4, DefaultRX: defaultUART4RX, DefaultTX: defaultUART4TX}
|
||||
var (
|
||||
UART0 = &_UART0
|
||||
UART1 = &_UART1
|
||||
UART2 = &_UART2
|
||||
UART3 = &_UART3
|
||||
UART4 = &_UART4
|
||||
_UART0 = UART{UART_Type: nxp.UART0, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART0, DefaultRX: defaultUART0RX, DefaultTX: defaultUART0TX}
|
||||
_UART1 = UART{UART_Type: nxp.UART1, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART1, DefaultRX: defaultUART1RX, DefaultTX: defaultUART1TX}
|
||||
_UART2 = UART{UART_Type: nxp.UART2, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART2, DefaultRX: defaultUART2RX, DefaultTX: defaultUART2TX}
|
||||
_UART3 = UART{UART_Type: nxp.UART3, SCGC: &nxp.SIM.SCGC4, SCGCMask: nxp.SIM_SCGC4_UART3, DefaultRX: defaultUART3RX, DefaultTX: defaultUART3TX}
|
||||
_UART4 = UART{UART_Type: nxp.UART4, SCGC: &nxp.SIM.SCGC1, SCGCMask: nxp.SIM_SCGC1_UART4, DefaultRX: defaultUART4RX, DefaultTX: defaultUART4TX}
|
||||
)
|
||||
|
||||
func init() {
|
||||
UART0.Interrupt = interrupt.New(nxp.IRQ_UART0_RX_TX, UART0.handleStatusInterrupt)
|
||||
UART1.Interrupt = interrupt.New(nxp.IRQ_UART1_RX_TX, UART1.handleStatusInterrupt)
|
||||
UART2.Interrupt = interrupt.New(nxp.IRQ_UART2_RX_TX, UART2.handleStatusInterrupt)
|
||||
UART3.Interrupt = interrupt.New(nxp.IRQ_UART3_RX_TX, UART3.handleStatusInterrupt)
|
||||
UART4.Interrupt = interrupt.New(nxp.IRQ_UART4_RX_TX, UART4.handleStatusInterrupt)
|
||||
UART0.Interrupt = interrupt.New(nxp.IRQ_UART0_RX_TX, _UART0.handleStatusInterrupt)
|
||||
UART1.Interrupt = interrupt.New(nxp.IRQ_UART1_RX_TX, _UART1.handleStatusInterrupt)
|
||||
UART2.Interrupt = interrupt.New(nxp.IRQ_UART2_RX_TX, _UART2.handleStatusInterrupt)
|
||||
UART3.Interrupt = interrupt.New(nxp.IRQ_UART3_RX_TX, _UART3.handleStatusInterrupt)
|
||||
UART4.Interrupt = interrupt.New(nxp.IRQ_UART4_RX_TX, _UART4.handleStatusInterrupt)
|
||||
}
|
||||
|
||||
// Configure the UART.
|
||||
|
|
|
@ -144,14 +144,14 @@ func (p Pin) enableClock() {
|
|||
//---------- UART related types and code
|
||||
|
||||
// Configure the UART.
|
||||
func (uart UART) configurePins(config UARTConfig) {
|
||||
func (uart *UART) configurePins(config UARTConfig) {
|
||||
// enable the alternate functions on the TX and RX pins
|
||||
config.TX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTTX}, uart.TxAltFuncSelector)
|
||||
config.RX.ConfigureAltFunc(PinConfig{Mode: PinModeUARTRX}, uart.RxAltFuncSelector)
|
||||
}
|
||||
|
||||
// UART baudrate calc based on the bus and clockspeed
|
||||
func (uart UART) getBaudRateDivisor(baudRate uint32) uint32 {
|
||||
func (uart *UART) getBaudRateDivisor(baudRate uint32) uint32 {
|
||||
var clock, rate uint32
|
||||
switch uart.Bus {
|
||||
case stm32.LPUART1:
|
||||
|
|
|
@ -27,7 +27,7 @@ type UARTConfig struct {
|
|||
//
|
||||
|
||||
// Read from the RX buffer.
|
||||
func (uart UART) Read(data []byte) (n int, err error) {
|
||||
func (uart *UART) Read(data []byte) (n int, err error) {
|
||||
// check if RX buffer is empty
|
||||
size := uart.Buffered()
|
||||
if size == 0 {
|
||||
|
@ -49,7 +49,7 @@ func (uart UART) Read(data []byte) (n int, err error) {
|
|||
}
|
||||
|
||||
// Write data to the UART.
|
||||
func (uart UART) Write(data []byte) (n int, err error) {
|
||||
func (uart *UART) Write(data []byte) (n int, err error) {
|
||||
for _, v := range data {
|
||||
uart.WriteByte(v)
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ func (uart UART) Write(data []byte) (n int, err error) {
|
|||
|
||||
// ReadByte reads a single byte from the RX buffer.
|
||||
// If there is no data in the buffer, returns an error.
|
||||
func (uart UART) ReadByte() (byte, error) {
|
||||
func (uart *UART) ReadByte() (byte, error) {
|
||||
// check if RX buffer is empty
|
||||
buf, ok := uart.Buffer.Get()
|
||||
if !ok {
|
||||
|
@ -68,12 +68,12 @@ func (uart UART) ReadByte() (byte, error) {
|
|||
}
|
||||
|
||||
// Buffered returns the number of bytes currently stored in the RX buffer.
|
||||
func (uart UART) Buffered() int {
|
||||
func (uart *UART) Buffered() int {
|
||||
return int(uart.Buffer.Used())
|
||||
}
|
||||
|
||||
// Receive handles adding data to the UART's data buffer.
|
||||
// Usually called by the IRQ handler for a machine.
|
||||
func (uart UART) Receive(data byte) {
|
||||
func (uart *UART) Receive(data byte) {
|
||||
uart.Buffer.Put(data)
|
||||
}
|
||||
|
|
|
@ -229,7 +229,7 @@ func initInternal() {
|
|||
func postinit() {}
|
||||
|
||||
func putchar(c byte) {
|
||||
machine.PutcharUART(&machine.UART0, c)
|
||||
machine.PutcharUART(machine.UART0, c)
|
||||
}
|
||||
|
||||
func abort() {
|
||||
|
@ -256,9 +256,9 @@ func abort() {
|
|||
// keep polling some communication while in fault
|
||||
// mode, so we don't completely die.
|
||||
// machine.PollUSB(&machine.USB0)
|
||||
machine.PollUART(&machine.UART0)
|
||||
machine.PollUART(&machine.UART1)
|
||||
machine.PollUART(&machine.UART2)
|
||||
machine.PollUART(machine.UART0)
|
||||
machine.PollUART(machine.UART1)
|
||||
machine.PollUART(machine.UART2)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче