-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathnative_core.cpp
155 lines (124 loc) · 2.46 KB
/
native_core.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <string>
#include <iostream>
#include <iomanip>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <stdarg.h>
#include <Logger.h>
#include <Pins.h>
#include <Clock.h>
#include <WProgram.h>
using namespace std;
extern Logger theLogger;
extern Pins thePins;
extern Clock theClock;
extern "C" {
void __cxa_pure_virtual()
{
theLogger.sketch("CORE","SYSTEM HALT -- cxa_pure_virtual");
while (1) {}
}
//
// Clock
//
void delay(unsigned long ms)
{
theLogger.sketch("CLOK","delay %lu",ms);
theClock.delay(ms);
}
unsigned long millis(void)
{
return theClock.millis();
}
void delayMicroseconds(unsigned int us)
{
theLogger.sketch("CLOK","delay %u us",us);
theClock.delayMicroseconds(us);
}
//
// Pins
//
void digitalWrite(uint8_t pin,uint8_t level)
{
thePins.digitalWrite(pin,level);
}
int digitalRead(uint8_t pin)
{
return thePins.digitalRead(pin);
}
int analogRead(uint8_t pin)
{
if ( pin >= A0 )
pin -= A0;
return thePins.analogRead(pin);
}
void pinMode(uint8_t pin,uint8_t mode)
{
thePins.pinMode(pin,mode);
}
void pinSymbol(uint8_t pin,const char* label)
{
thePins.pinSymbol(pin,label);
}
void attachInterrupt(uint8_t num, void (*fn)(void), int)
{
thePins.attachInterrupt(num,fn);
}
void detachInterrupt(uint8_t num)
{
thePins.detachInterrupt(num);
}
//
// Specialized functions
//
void printf_P(const char* format,...)
{
std::string formatstr(format);
// replace '%S' with '%s'
size_t at = formatstr.find("%S");
while ( at != string::npos )
{
formatstr.replace(at,2,"%s");
at = formatstr.find("%S",at);
}
// Remove trailing \n and \r
size_t s = formatstr.size();
char c = formatstr.at(s-1);
while ( s && ( c == '\n' || c == '\r' ) )
{
formatstr.resize(--s);
c = formatstr.at(s-1);
}
va_list args;
va_start (args, format);
//vprintf (formatstr.c_str(), args);
theLogger.sketch_v("PRTF",formatstr.c_str(),args);
va_end (args);
}
//
// No-ops
//
unsigned long pulseIn(uint8_t pin, uint8_t /*state*/, unsigned long /*timeout*/ )
{
theLogger.sketch("CORE","%i: pulseIn 1000",pin);
return 1000LU;
}
void analogWrite(uint8_t pin,int level)
{
theLogger.sketch("PINS","%i: %i",pin,level);
}
void fdevopen(int (*)(char, FILE*),int)
{
}
}
void tone(uint8_t pin, unsigned int what, unsigned long wait)
{
theLogger.sketch("PINS","%i: tone %u",pin,what);
delay(wait);
}
void noTone(uint8_t pin)
{
theLogger.sketch("PINS","%i: noTone",pin);
}
// vim:cin:ai:sts=2 sw=2 ft=cpp