avr: use machine.UART0 as stdout

Этот коммит содержится в:
Ayke van Laethem 2018-10-04 13:36:38 +02:00
родитель f37d409855
коммит 3e98fbcdc8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: E97FF5335DFDFDED
2 изменённых файлов: 8 добавлений и 12 удалений

Просмотреть файл

@ -291,8 +291,11 @@ func (uart UART) Configure(config UARTConfig) {
*avr.UBRR0H = avr.RegValue(ps >> 8) *avr.UBRR0H = avr.RegValue(ps >> 8)
*avr.UBRR0L = avr.RegValue(ps & 0xff) *avr.UBRR0L = avr.RegValue(ps & 0xff)
// enable RX interrupt // enable RX, TX and RX interrupt
*avr.UCSR0B |= avr.UCSR0B_RXCIE0 *avr.UCSR0B = avr.UCSR0B_RXEN0 | avr.UCSR0B_TXEN0 | avr.UCSR0B_RXCIE0
// 8-bits data
*avr.UCSR0C = avr.UCSR0C_UCSZ01 | avr.UCSR0C_UCSZ00
} }
// WriteByte writes a byte of data to the UART. // WriteByte writes a byte of data to the UART.

Просмотреть файл

@ -4,6 +4,7 @@ package runtime
import ( import (
"device/avr" "device/avr"
"machine"
"unsafe" "unsafe"
) )
@ -54,19 +55,11 @@ func init() {
} }
func initUART() { func initUART() {
// Initialize UART at 9600 baud when running at 16MHz. machine.UART0.Configure(machine.UARTConfig{})
*avr.UBRR0H = 0
*avr.UBRR0L = 0x67
*avr.UCSR0B = avr.UCSR0B_RXEN0 | avr.UCSR0B_TXEN0 // enable RX and TX
*avr.UCSR0C = avr.UCSR0C_UCSZ01 | avr.UCSR0C_UCSZ00 // 8-bits data
} }
func putchar(c byte) { func putchar(c byte) {
for (*avr.UCSR0A & avr.UCSR0A_UDRE0) == 0 { machine.UART0.WriteByte(c)
// Wait until previous char has been sent.
}
*avr.UDR0 = avr.RegValue(c) // send char
} }
// Sleep this number of ticks of 16ms. // Sleep this number of ticks of 16ms.