summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-12-08 15:24:37 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-12-08 15:24:37 +0100
commit540974f8f109aa8874f032eddf59819c76eb018e (patch)
tree00166d053f03dad76149c62fc57347fc2859a773 /src
parentdcf84169ae75b11c1656d45dbc6c626d93da6a10 (diff)
"Fix" esp8266 UART output by removing virtual functions
Diffstat (limited to 'src')
-rw-r--r--src/arch/esp8266/driver/stdout.cc190
-rw-r--r--src/os/main.cc1
2 files changed, 191 insertions, 0 deletions
diff --git a/src/arch/esp8266/driver/stdout.cc b/src/arch/esp8266/driver/stdout.cc
index b35275b..9638a81 100644
--- a/src/arch/esp8266/driver/stdout.cc
+++ b/src/arch/esp8266/driver/stdout.cc
@@ -7,6 +7,196 @@ void uart_div_modify(uint8_t uart_no, uint32 DivLatchValue);
void os_printf_plus(const char *s, ...);
}
+StandardOutput & StandardOutput::operator<<(unsigned char c)
+{
+ put(c);
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(char c)
+{
+ put(c);
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(unsigned short number)
+{
+ *this << (unsigned long long)number;
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(short number)
+{
+ *this << (long long)number;
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(unsigned int number)
+{
+ *this << (unsigned long long)number;
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(int number)
+{
+ *this << (long long)number;
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(unsigned long number)
+{
+ *this << (unsigned long long)number;
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(long number)
+{
+ *this << (long long)number;
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(unsigned long long number)
+{
+ switch (base) {
+ case 2:
+ put('0');
+ put('b');
+ break;
+ case 8:
+ put('0');
+ break;
+ case 16:
+ put('0');
+ put('x');
+ break;
+ }
+
+ if (number == 0) {
+ put('0');
+ return *this;
+ }
+
+ signed int i = 0;
+ while (number > 0) {
+ if (base == 16 && number % base > 9) {
+ digit_buffer[i] = 'a' + (number % base) - 10;
+ } else {
+ digit_buffer[i] = '0' + (number % base);
+ }
+ number /= base;
+ i++;
+ }
+ i--;
+ for (; i >= 0; i--) {
+ put(digit_buffer[i]);
+ }
+ return *this;
+
+}
+
+StandardOutput & StandardOutput::operator<<(long long number)
+{
+ if (number < 0) {
+ put('-');
+ number *= -1;
+ }
+ *this << (unsigned long long)number;
+
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(void *pointer)
+{
+ unsigned short temp_base = base;
+ *this << hex << (long)pointer;
+ switch (temp_base) {
+ case 2:
+ *this << bin; break;
+ case 8:
+ *this << oct; break;
+ case 10:
+ *this << dec; break;
+ }
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(const char *text)
+{
+ int i = 0;
+ while (text[i] != '\0') {
+ put(text[i++]);
+ }
+ return *this;
+}
+
+StandardOutput & StandardOutput::operator<<(StandardOutput & (*fkt) (StandardOutput &))
+{
+ return fkt(*this);
+}
+
+void StandardOutput::setBase(uint8_t b)
+{
+ if (b == 2 || b == 8 || b == 10 || b == 16) {
+ base = b;
+ }
+}
+
+// FLUSH
+StandardOutput & flush(StandardOutput & os)
+{
+ os.flush();
+ return os;
+}
+
+// ENDL: fuegt einen Zeilenumbruch in die Ausgabe ein.
+StandardOutput & endl(StandardOutput & os)
+{
+ os.put('\n');
+ os.flush();
+ return os;
+}
+
+// BIN: print numbers in binary form
+StandardOutput & bin(StandardOutput & os)
+{
+ os.setBase(2);
+ return os;
+}
+
+// OCT: print numbers in octal form.
+StandardOutput & oct(StandardOutput & os)
+{
+ os.setBase(8);
+ return os;
+}
+
+// DEC: print numbers in decimal form.
+StandardOutput & dec(StandardOutput & os)
+{
+ os.setBase(10);
+ return os;
+}
+
+// HEX: print numbers in hexadecimal form.
+StandardOutput & hex(StandardOutput & os)
+{
+ os.setBase(16);
+ return os;
+}
+
+// TERM: null-termination
+StandardOutput & term(StandardOutput & os)
+{
+ os.put('\0');
+ os.flush();
+ return os;
+}
+
+StandardOutput::StandardOutput()
+{
+ base = 10;
+}
+
void StandardOutput::setup()
{
uart_div_modify(0, UART_CLK_FREQ / 115200);
diff --git a/src/os/main.cc b/src/os/main.cc
index 3e48053..4509301 100644
--- a/src/os/main.cc
+++ b/src/os/main.cc
@@ -98,6 +98,7 @@ int main(void)
gpio.led_on(0);
kout << "Hello, World!" << endl;
+ kout << "Test, World!" << endl;
arch.idle_loop();