summaryrefslogtreecommitdiff
path: root/src/arch/blinkenrocket/driver/stdout.cc
blob: 961cf46fa3bc49e3d5d0f7df0f87244c69f37f99 (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
#include "driver/stdout.h"
#include <avr/io.h>
#include <avr/interrupt.h>

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

void StandardOutput::put(char c)
{
	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');
	}
}

StandardOutput kout;