forked from eembc/coremark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_arduino.cpp
71 lines (67 loc) · 1.98 KB
/
core_arduino.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
#include <Arduino.h>
#include <stdarg.h>
#include "core_arduino.h"
extern "C" CORETIMETYPE barebones_clock()
{
return millis();
}
extern "C" int ee_printf(const char *format, ...)
{
va_list args;
va_start(args, format);
for (; *format; format++) {
if (*format == '%') {
bool islong = false;
format++;
if (*format == '%') {
Serial.print(*format);
continue;
}
if (*format == '-') {
format++; // ignore size
}
while (*format >= '0' && *format <= '9') {
format++; // ignore size
}
if (*format == 'l') {
islong = true;
format++;
}
if (*format == '\0') {
break;
}
if (*format == 's') {
Serial.print((char *) va_arg(args, int));
} else if (*format == 'f') {
Serial.print(va_arg(args, double));
} else if (*format == 'd') {
if (islong) {
Serial.print(va_arg(args, long));
} else {
Serial.print(va_arg(args, int));
}
} else if (*format == 'u') {
if (islong) {
Serial.print(va_arg(args, unsigned long));
} else {
Serial.print(va_arg(args, unsigned int));
}
} else if (*format == 'x') {
if (islong) {
Serial.print(va_arg(args, unsigned long), HEX);
} else {
Serial.print(va_arg(args, unsigned int), HEX);
}
} else if (*format == 'c') {
Serial.print(va_arg(args, int));
}
} else {
if (*format == '\n') {
Serial.print('\r');
}
Serial.print(*format);
}
}
va_end(args);
return 1;
}