summaryrefslogtreecommitdiff
path: root/src/arch/blinkenrocket/driver/stdout.cc
blob: 195ba96e0e217dce8cf5bf34985b6fb67acaf326 (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
#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;