summaryrefslogtreecommitdiff
path: root/src/arch/atmega2560/driver/stdout3.cc
blob: 451a043dc7ad8d66930d6bec774f92d84d507a98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
 * Copyright 2024 Birte Kristina Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "driver/stdout3.h"
#include <avr/io.h>
#include <avr/interrupt.h>

#undef BAUD
#define BAUD CONFIG_arch_atmega2560_uart3_baud

#include <util/setbaud.h>

void StandardOutput3::setup()
{
	UBRR3H = UBRRH_VALUE;
	UBRR3L = UBRRL_VALUE;

#if USE_2X
	UCSR3A |= _BV(U2X3);
#else
	UCSR3A &= ~_BV(U2X3);
#endif

	UCSR3B |= _BV(RXEN3) | _BV(TXEN3);
	UCSR3C = _BV(UCSZ31) | _BV(UCSZ30);
}

void StandardOutput3::put(char c)
{
	while (!(UCSR3A & _BV(UDRE3)));
	UDR3 = c;
	if (c == '\n') {
		put('\r');
	}
}

StandardOutput3 kout3;