forked from dhansel/Altair8800
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch_serial.cpp
104 lines (75 loc) · 2.14 KB
/
switch_serial.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// -----------------------------------------------------------------------------
// Altair 8800 Simulator
// Copyright (C) 2017 David Hansel
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
// -----------------------------------------------------------------------------
#if !defined(__AVR_ATmega2560__)
#include <Arduino.h>
#include "host.h"
#include "switch_serial.h"
SwitchSerialClass SwitchSerial;
SwitchSerialClass::SwitchSerialClass() : Stream()
{
m_selected = 0;
}
void SwitchSerialClass::begin(unsigned long baud)
{
host_serial_setup(m_selected, baud, SERIAL_8N1, false);
}
void SwitchSerialClass::end()
{
host_serial_end(m_selected);
}
int SwitchSerialClass::available(void)
{
return host_serial_available(m_selected);
}
int SwitchSerialClass::availableForWrite(void)
{
return host_serial_available_for_write(m_selected);
}
int SwitchSerialClass::peek(void)
{
return host_serial_peek(m_selected);
}
int SwitchSerialClass::read(void)
{
return host_serial_read(m_selected);
}
void SwitchSerialClass::flush(void)
{
return host_serial_flush(m_selected);
}
size_t SwitchSerialClass::write(uint8_t b)
{
return host_serial_write(m_selected, b);
}
size_t SwitchSerialClass::write(const uint8_t *buffer, size_t size)
{
size_t sz = size;
while( sz>0 )
{
size_t n = host_serial_write(m_selected, (const char *) buffer, sz);
buffer += n;
sz -= n;
}
return size;
}
SwitchSerialClass::operator bool()
{
return host_serial_ok(m_selected);
}
#endif