summaryrefslogtreecommitdiff
path: root/src/arch/blinkenrocket/driver/stdout.cc
blob: a7c0a3f9a5c20c8b18a75addd804f26355481185 (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
/*
 * Copyright 2020 Daniel Friesel
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */
#include "driver/stdout.h"
#include <avr/io.h>
#include <avr/interrupt.h>

void StandardOutput::setup()
{
#ifndef KOUT_NOP
	PORTC |= _BV(PC1);
	DDRC |= _BV(DDC1);
#endif
}

void StandardOutput::put(char c)
{
#ifndef KOUT_NOP
	unsigned char i = 1;
	PORTC &= ~_BV(PC1);
	__builtin_avr_delay_cycles(59);
	while (i < 0x80) {
		if (c & i) {
			PORTC |= _BV(PC1);
		} else {
			PORTC &= ~_BV(PC1);
		}
		i <<= 1;
		__builtin_avr_delay_cycles(54);
	}
	__builtin_avr_delay_cycles(6);
	PORTC &= ~_BV(PC1);
	__builtin_avr_delay_cycles(67);
	PORTC |= _BV(PC1);
	__builtin_avr_delay_cycles(150);
	if (c == '\n') {
		put('\r');
	}
#endif
}

StandardOutput kout;