diff --git a/src/machine/board_arduino_nano33_baremetal.go b/src/machine/board_arduino_nano33_baremetal.go index 584f65ee..79e62d24 100644 --- a/src/machine/board_arduino_nano33_baremetal.go +++ b/src/machine/board_arduino_nano33_baremetal.go @@ -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. diff --git a/src/machine/board_atsame54-xpro.go b/src/machine/board_atsame54-xpro.go index d5d1f681..a70ab7b0 100644 --- a/src/machine/board_atsame54-xpro.go +++ b/src/machine/board_atsame54-xpro.go @@ -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 diff --git a/src/machine/board_bluepill.go b/src/machine/board_bluepill.go index 51e38934..4aece086 100644 --- a/src/machine/board_bluepill.go +++ b/src/machine/board_bluepill.go @@ -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 diff --git a/src/machine/board_circuitplay_express_baremetal.go b/src/machine/board_circuitplay_express_baremetal.go index 78709baa..f99043e1 100644 --- a/src/machine/board_circuitplay_express_baremetal.go +++ b/src/machine/board_circuitplay_express_baremetal.go @@ -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. diff --git a/src/machine/board_feather-m0.go b/src/machine/board_feather-m0.go index 4c7f664e..f0f72ea7 100644 --- a/src/machine/board_feather-m0.go +++ b/src/machine/board_feather-m0.go @@ -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 diff --git a/src/machine/board_feather-m4-can.go b/src/machine/board_feather-m4-can.go index 795a6a3e..5ad3cd15 100644 --- a/src/machine/board_feather-m4-can.go +++ b/src/machine/board_feather-m4-can.go @@ -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}) diff --git a/src/machine/board_feather-m4_baremetal.go b/src/machine/board_feather-m4_baremetal.go index bfe47ecf..d0d9d6dd 100644 --- a/src/machine/board_feather-m4_baremetal.go +++ b/src/machine/board_feather-m4_baremetal.go @@ -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. diff --git a/src/machine/board_feather-stm32f405.go b/src/machine/board_feather-stm32f405.go index 17d8b93f..f55572ff 100644 --- a/src/machine/board_feather-stm32f405.go +++ b/src/machine/board_feather-stm32f405.go @@ -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 ---------------------------------------------------------------------- diff --git a/src/machine/board_grandcentral-m4_baremetal.go b/src/machine/board_grandcentral-m4_baremetal.go index 74f0a39d..a59bd95b 100644 --- a/src/machine/board_grandcentral-m4_baremetal.go +++ b/src/machine/board_grandcentral-m4_baremetal.go @@ -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, diff --git a/src/machine/board_itsybitsy-m0.go b/src/machine/board_itsybitsy-m0.go index 189557ae..a4161429 100644 --- a/src/machine/board_itsybitsy-m0.go +++ b/src/machine/board_itsybitsy-m0.go @@ -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 diff --git a/src/machine/board_itsybitsy-m4_baremetal.go b/src/machine/board_itsybitsy-m4_baremetal.go index 133bd462..b38655fd 100644 --- a/src/machine/board_itsybitsy-m4_baremetal.go +++ b/src/machine/board_itsybitsy-m4_baremetal.go @@ -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. diff --git a/src/machine/board_lgt92.go b/src/machine/board_lgt92.go index c95de360..81fe2220 100644 --- a/src/machine/board_lgt92.go +++ b/src/machine/board_lgt92.go @@ -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) } diff --git a/src/machine/board_matrixportal-m4_baremetal.go b/src/machine/board_matrixportal-m4_baremetal.go index 4199cbb9..8e0cd854 100644 --- a/src/machine/board_matrixportal-m4_baremetal.go +++ b/src/machine/board_matrixportal-m4_baremetal.go @@ -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 diff --git a/src/machine/board_metro-m4-airlift_baremetal.go b/src/machine/board_metro-m4-airlift_baremetal.go index e5b37539..1564b240 100644 --- a/src/machine/board_metro-m4-airlift_baremetal.go +++ b/src/machine/board_metro-m4-airlift_baremetal.go @@ -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. diff --git a/src/machine/board_nucleof103rb.go b/src/machine/board_nucleof103rb.go index 8908864d..0efdd5d8 100644 --- a/src/machine/board_nucleof103rb.go +++ b/src/machine/board_nucleof103rb.go @@ -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 diff --git a/src/machine/board_nucleof722ze.go b/src/machine/board_nucleof722ze.go index 32a6e256..4c1a2cd2 100644 --- a/src/machine/board_nucleof722ze.go +++ b/src/machine/board_nucleof722ze.go @@ -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 diff --git a/src/machine/board_nucleol031k6.go b/src/machine/board_nucleol031k6.go index d5fddebf..dc80b50d 100644 --- a/src/machine/board_nucleol031k6.go +++ b/src/machine/board_nucleol031k6.go @@ -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) } diff --git a/src/machine/board_nucleol432kc.go b/src/machine/board_nucleol432kc.go index cb92a961..bb5133d2 100644 --- a/src/machine/board_nucleol432kc.go +++ b/src/machine/board_nucleol432kc.go @@ -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) } diff --git a/src/machine/board_nucleol552ze.go b/src/machine/board_nucleol552ze.go index d7fc67e9..a20285c4 100644 --- a/src/machine/board_nucleol552ze.go +++ b/src/machine/board_nucleol552ze.go @@ -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) } diff --git a/src/machine/board_p1am-100_baremetal.go b/src/machine/board_p1am-100_baremetal.go index 2bbf33aa..e50dd446 100644 --- a/src/machine/board_p1am-100_baremetal.go +++ b/src/machine/board_p1am-100_baremetal.go @@ -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. diff --git a/src/machine/board_pybadge_baremetal.go b/src/machine/board_pybadge_baremetal.go index b11ab157..2e4e89bc 100644 --- a/src/machine/board_pybadge_baremetal.go +++ b/src/machine/board_pybadge_baremetal.go @@ -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. diff --git a/src/machine/board_pyportal_baremetal.go b/src/machine/board_pyportal_baremetal.go index ef554022..82a4e334 100644 --- a/src/machine/board_pyportal_baremetal.go +++ b/src/machine/board_pyportal_baremetal.go @@ -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. diff --git a/src/machine/board_qtpy.go b/src/machine/board_qtpy.go index e21e288a..883a32ba 100644 --- a/src/machine/board_qtpy.go +++ b/src/machine/board_qtpy.go @@ -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 diff --git a/src/machine/board_stm32f4disco.go b/src/machine/board_stm32f4disco.go index 5b292e1a..8c3976ab 100644 --- a/src/machine/board_stm32f4disco.go +++ b/src/machine/board_stm32f4disco.go @@ -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 diff --git a/src/machine/board_teensy36.go b/src/machine/board_teensy36.go index f0eccecd..0808b4b3 100644 --- a/src/machine/board_teensy36.go +++ b/src/machine/board_teensy36.go @@ -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 ( diff --git a/src/machine/board_teensy40.go b/src/machine/board_teensy40.go index 792c0d3d..7f0781f0 100644 --- a/src/machine/board_teensy40.go +++ b/src/machine/board_teensy40.go @@ -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(), diff --git a/src/machine/board_trinket.go b/src/machine/board_trinket.go index 8535fdfe..6305cb70 100644 --- a/src/machine/board_trinket.go +++ b/src/machine/board_trinket.go @@ -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 diff --git a/src/machine/board_wioterminal_baremetal.go b/src/machine/board_wioterminal_baremetal.go index bd909f03..a8657f91 100644 --- a/src/machine/board_wioterminal_baremetal.go +++ b/src/machine/board_wioterminal_baremetal.go @@ -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 diff --git a/src/machine/board_xiao.go b/src/machine/board_xiao.go index 05316ed4..b18a44e3 100644 --- a/src/machine/board_xiao.go +++ b/src/machine/board_xiao.go @@ -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 diff --git a/src/machine/machine_atmega.go b/src/machine/machine_atmega.go index e3f2e769..6d9a5eda 100644 --- a/src/machine/machine_atmega.go +++ b/src/machine/machine_atmega.go @@ -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) { } diff --git a/src/machine/machine_atsamd21.go b/src/machine/machine_atsamd21.go index 058099cd..a9a02437 100644 --- a/src/machine/machine_atsamd21.go +++ b/src/machine/machine_atsamd21.go @@ -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) { } diff --git a/src/machine/machine_atsamd51.go b/src/machine/machine_atsamd51.go index f21d0173..4b633389 100644 --- a/src/machine/machine_atsamd51.go +++ b/src/machine/machine_atsamd51.go @@ -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) { } diff --git a/src/machine/machine_esp32.go b/src/machine/machine_esp32.go index fd4fa062..ee3f61de 100644 --- a/src/machine/machine_esp32.go +++ b/src/machine/machine_esp32.go @@ -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 diff --git a/src/machine/machine_esp8266.go b/src/machine/machine_esp8266.go index 19c5dd0a..e8a9ecf6 100644 --- a/src/machine/machine_esp8266.go +++ b/src/machine/machine_esp8266.go @@ -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. } diff --git a/src/machine/machine_fe310.go b/src/machine/machine_fe310.go index 3af8acc4..ebd85971 100644 --- a/src/machine/machine_fe310.go +++ b/src/machine/machine_fe310.go @@ -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 { } diff --git a/src/machine/machine_generic.go b/src/machine/machine_generic.go index 16948a49..697af241 100644 --- a/src/machine/machine_generic.go +++ b/src/machine/machine_generic.go @@ -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 } diff --git a/src/machine/machine_k210.go b/src/machine/machine_k210.go index f009e152..232c942b 100644 --- a/src/machine/machine_k210.go +++ b/src/machine/machine_k210.go @@ -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 { } diff --git a/src/machine/machine_nrf.go b/src/machine/machine_nrf.go index c49096e8..ee883ccc 100644 --- a/src/machine/machine_nrf.go +++ b/src/machine/machine_nrf.go @@ -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 { diff --git a/src/machine/machine_nrf51.go b/src/machine/machine_nrf51.go index fe89da4d..4615a549 100644 --- a/src/machine/machine_nrf51.go +++ b/src/machine/machine_nrf51.go @@ -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)) } diff --git a/src/machine/machine_nrf52.go b/src/machine/machine_nrf52.go index 50ccde36..44120028 100644 --- a/src/machine/machine_nrf52.go +++ b/src/machine/machine_nrf52.go @@ -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)) } diff --git a/src/machine/machine_nrf52833.go b/src/machine/machine_nrf52833.go index a7b8ecf0..1920b4e6 100644 --- a/src/machine/machine_nrf52833.go +++ b/src/machine/machine_nrf52833.go @@ -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)) } diff --git a/src/machine/machine_nrf52840.go b/src/machine/machine_nrf52840.go index 1767802d..d7d6ae2b 100644 --- a/src/machine/machine_nrf52840.go +++ b/src/machine/machine_nrf52840.go @@ -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)) } diff --git a/src/machine/machine_nxpmk66f18_uart.go b/src/machine/machine_nxpmk66f18_uart.go index 690e2841..2d8eae01 100644 --- a/src/machine/machine_nxpmk66f18_uart.go +++ b/src/machine/machine_nxpmk66f18_uart.go @@ -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. diff --git a/src/machine/machine_stm32l0.go b/src/machine/machine_stm32l0.go index f4df17ab..8dab461b 100644 --- a/src/machine/machine_stm32l0.go +++ b/src/machine/machine_stm32l0.go @@ -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: diff --git a/src/machine/uart.go b/src/machine/uart.go index 971ff23e..38046fba 100644 --- a/src/machine/uart.go +++ b/src/machine/uart.go @@ -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) } diff --git a/src/runtime/runtime_nxpmk66f18.go b/src/runtime/runtime_nxpmk66f18.go index 1cb52334..d31ff0d0 100644 --- a/src/runtime/runtime_nxpmk66f18.go +++ b/src/runtime/runtime_nxpmk66f18.go @@ -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) } }