summaryrefslogtreecommitdiff
path: root/src/arch/lora32u4ii/driver/stdout.cc
blob: e7ddd5f9d967efe5194af892fd22696354e3a69d (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
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright 2021 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "driver/stdout.h"
#include <avr/io.h>

#ifndef BAUD
#define BAUD 9600UL
#endif

#include <util/setbaud.h>

void StandardOutput::setup()
{
	UBRR1H = UBRRH_VALUE;
	UBRR1L = UBRRL_VALUE;

#if USE_2X
	UCSR1A |= _BV(U2X1);
#else
	UCSR1A &= ~_BV(U2X1);
#endif

	UCSR1B |= _BV(RXEN1) | _BV(TXEN1);
	UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); // async UART, 8N1
	//UCSR1D = 0;
}

OutputStream & StandardOutput::pprint(const char *text)
{
	PGM_P p = reinterpret_cast<PGM_P>(text);
	char c;
	while ((c = pgm_read_byte(p++))) {
		put(c);
	}
	return *this;
}


void StandardOutput::put(char c)
{
	while (!(UCSR1A & _BV(UDRE1)));
	UDR1 = c;
	if (c == '\n') {
		put('\r');
	}
}

StandardOutput kout;