|
| 1 | +#include "Arduino.h" |
| 2 | + |
| 3 | +#include <stdio.h> |
| 4 | + |
| 5 | +#include <chrono> |
1 | 6 | #include <cstring> |
2 | | -#include <chrono> |
3 | 7 | #include <ctime> |
4 | | -#include <stdio.h> |
5 | 8 | #include <thread> |
6 | | -#include <chrono> |
7 | | -#include "Arduino.h" |
| 9 | + |
| 10 | +#include "GPIOWrapper.h" |
| 11 | +#include "HardwareGPIO.h" |
| 12 | +#include "RemoteSerial.h" |
8 | 13 | #include "api/Common.h" |
9 | | -#include "api/Stream.h" |
10 | 14 | #include "api/PluggableUSB.h" |
11 | | -#include "RemoteSerial.h" |
12 | | -#include "Hardware.h" |
| 15 | +#include "api/Stream.h" |
13 | 16 | #if !defined(SKIP_HARDWARE_SETUP) |
14 | | -# include "HardwareSetupRemote.h" |
| 17 | +#include "HardwareSetupRemote.h" |
15 | 18 | #endif |
16 | 19 | #if !defined(SKIP_HARDWARE_WIFI) |
17 | | -# include "WiFi.h" |
18 | | -# include "WiFiClient.h" |
| 20 | +#include "WiFi.h" |
| 21 | +#include "WiFiClient.h" |
19 | 22 | #endif |
20 | 23 | #if defined(USE_RPI) |
21 | | -# include "HardwareGPIO_RPI.h" |
22 | | -# include "HardwareI2C_RPI.h" |
| 24 | +#include "HardwareGPIO_RPI.h" |
| 25 | +#include "HardwareI2C_RPI.h" |
23 | 26 | #endif |
24 | | -#include "api/PluggableUSB.h" |
25 | | -#include "api/deprecated-avr-comp/avr/dtostrf.h" |
26 | 27 | #include "ArduinoLogger.h" |
27 | | -#include "StdioDevice.h" |
28 | 28 | #include "Serial.h" |
| 29 | +#include "StdioDevice.h" |
| 30 | +#include "api/PluggableUSB.h" |
| 31 | +#include "api/deprecated-avr-comp/avr/dtostrf.h" |
29 | 32 |
|
30 | 33 | namespace arduino { |
31 | 34 |
|
32 | 35 | #if !defined(SKIP_HARDWARE_WIFI) |
33 | | -WifiMock WiFi; // So that we can use the WiFi |
| 36 | +WifiMock WiFi; // So that we can use the WiFi |
34 | 37 | #endif |
35 | 38 |
|
| 39 | +// static PluggableUSB_ obj; |
| 40 | +PluggableUSB_::PluggableUSB_() {} |
36 | 41 |
|
37 | | -//static PluggableUSB_ obj; |
38 | | -PluggableUSB_::PluggableUSB_(){} |
| 42 | +} // namespace arduino |
39 | 43 |
|
40 | | -} |
41 | | - |
42 | | - |
43 | 44 | // sleep ms milliseconds |
44 | | -void delay(unsigned long ms){ |
45 | | - std::this_thread::sleep_for(std::chrono::milliseconds(ms)); |
| 45 | +void delay(unsigned long ms) { |
| 46 | + std::this_thread::sleep_for(std::chrono::milliseconds(ms)); |
46 | 47 | } |
47 | 48 |
|
48 | 49 | // sleep us milliseconds |
49 | | -void delayMicroseconds(unsigned int us){ |
50 | | - std::this_thread::sleep_for(std::chrono::microseconds(us)); |
| 50 | +void delayMicroseconds(unsigned int us) { |
| 51 | + std::this_thread::sleep_for(std::chrono::microseconds(us)); |
51 | 52 | } |
52 | 53 |
|
53 | 54 | // double to string conversion -> we can use sprintf which is complete in linux |
54 | | -char *dtostrf(double val, signed char width, unsigned char prec, char *sout){ |
55 | | - sprintf(sout,"%*.*lf",width,prec, val); |
56 | | - return sout; |
| 55 | +char* dtostrf(double val, signed char width, unsigned char prec, char* sout) { |
| 56 | + sprintf(sout, "%*.*lf", width, prec, val); |
| 57 | + return sout; |
57 | 58 | } |
58 | 59 |
|
59 | 60 | // Returns the number of milliseconds passed since epich |
60 | 61 | unsigned long millis() { |
61 | | - static uint64_t start = 0; |
62 | | - using namespace std::chrono; |
63 | | - // Get current time with precision of milliseconds |
64 | | - auto now = time_point_cast<milliseconds>(system_clock::now()); |
65 | | - // sys_milliseconds is type time_point<system_clock, milliseconds> |
66 | | - using sys_milliseconds = decltype(now); |
67 | | - // Convert time_point to signed integral type |
68 | | - auto result = now.time_since_epoch().count(); |
69 | | - if (start == 0) { |
70 | | - start = result; |
71 | | - } |
72 | | - return result - start; |
73 | | - |
| 62 | + static uint64_t start = 0; |
| 63 | + using namespace std::chrono; |
| 64 | + // Get current time with precision of milliseconds |
| 65 | + auto now = time_point_cast<milliseconds>(system_clock::now()); |
| 66 | + // sys_milliseconds is type time_point<system_clock, milliseconds> |
| 67 | + using sys_milliseconds = decltype(now); |
| 68 | + // Convert time_point to signed integral type |
| 69 | + auto result = now.time_since_epoch().count(); |
| 70 | + if (start == 0) { |
| 71 | + start = result; |
| 72 | + } |
| 73 | + return result - start; |
74 | 74 | } |
75 | 75 |
|
76 | 76 | // Returns the micros of milliseconds passed since epich |
77 | | -unsigned long micros(void){ |
78 | | - using namespace std::chrono; |
79 | | - // Get current time with precision of milliseconds |
80 | | - auto now = time_point_cast<microseconds>(system_clock::now()); |
81 | | - // sys_milliseconds is type time_point<system_clock, milliseconds> |
82 | | - using sys_milliseconds = decltype(now); |
83 | | - // Convert time_point to signed integral type |
84 | | - return now.time_since_epoch().count(); |
| 77 | +unsigned long micros(void) { |
| 78 | + using namespace std::chrono; |
| 79 | + // Get current time with precision of milliseconds |
| 80 | + auto now = time_point_cast<microseconds>(system_clock::now()); |
| 81 | + // sys_milliseconds is type time_point<system_clock, milliseconds> |
| 82 | + using sys_milliseconds = decltype(now); |
| 83 | + // Convert time_point to signed integral type |
| 84 | + return now.time_since_epoch().count(); |
85 | 85 | } |
86 | 86 |
|
87 | | -void pinMode(pin_size_t pinNumber, PinMode pinMode){ |
88 | | - if (Hardware.gpio != nullptr) { |
89 | | - Hardware.gpio->pinMode(pinNumber,pinMode); |
90 | | - } |
| 87 | +void pinMode(pin_size_t pinNumber, PinMode pinMode) { |
| 88 | + GPIO.pinMode(pinNumber, pinMode); |
91 | 89 | } |
92 | 90 | void digitalWrite(pin_size_t pinNumber, PinStatus status) { |
93 | | - if (Hardware.gpio != nullptr) { |
94 | | - Hardware.gpio->digitalWrite(pinNumber,status); |
95 | | - } |
| 91 | + GPIO.digitalWrite(pinNumber, status); |
96 | 92 | } |
97 | 93 | PinStatus digitalRead(pin_size_t pinNumber) { |
98 | | - if (Hardware.gpio != nullptr) { |
99 | | - return Hardware.gpio->digitalRead(pinNumber); |
100 | | - } else { |
101 | | - return HIGH; //sumulate input pullup |
102 | | - } |
103 | | -} |
104 | | -int analogRead(pin_size_t pinNumber){ |
105 | | - if (Hardware.gpio != nullptr) { |
106 | | - return Hardware.gpio->analogRead(pinNumber); |
107 | | - } else { |
108 | | - return 0; |
109 | | - } |
110 | | - |
111 | | -} |
112 | | -void analogReference(uint8_t mode){ |
113 | | - if (Hardware.gpio != nullptr) { |
114 | | - Hardware.gpio->analogReference(mode); |
115 | | - } |
| 94 | + return GPIO.digitalRead(pinNumber); |
116 | 95 | } |
| 96 | +int analogRead(pin_size_t pinNumber) { return GPIO.analogRead(pinNumber); } |
| 97 | +void analogReference(uint8_t mode) { GPIO.analogReference(mode); } |
117 | 98 | void analogWrite(pin_size_t pinNumber, int value) { |
118 | | - if (Hardware.gpio != nullptr) { |
119 | | - Hardware.gpio->analogWrite(pinNumber,value); |
120 | | - } |
| 99 | + GPIO.analogWrite(pinNumber, value); |
121 | 100 | } |
122 | 101 | void tone(uint8_t pinNumber, unsigned int frequency, unsigned long duration) { |
123 | | - if (Hardware.gpio != nullptr) { |
124 | | - Hardware.gpio->tone(pinNumber,frequency,duration); |
125 | | - } |
126 | | -} |
127 | | -void noTone(uint8_t pinNumber) { |
128 | | - if (Hardware.gpio != nullptr) { |
129 | | - Hardware.gpio->noTone(pinNumber); |
130 | | - } |
| 102 | + GPIO.tone(pinNumber, frequency, duration); |
131 | 103 | } |
132 | | -unsigned long pulseIn(uint8_t pinNumber, uint8_t state, unsigned long timeout){ |
133 | | - if (Hardware.gpio != nullptr) { |
134 | | - return Hardware.gpio->pulseIn(pinNumber, state, timeout); |
135 | | - } else { |
136 | | - return 0; |
137 | | - } |
| 104 | +void noTone(uint8_t pinNumber) { GPIO.noTone(pinNumber); } |
| 105 | +unsigned long pulseIn(uint8_t pinNumber, uint8_t state, unsigned long timeout) { |
| 106 | + return GPIO.pulseIn(pinNumber, state, timeout); |
138 | 107 | } |
139 | | -unsigned long pulseInLong(uint8_t pinNumber, uint8_t state, unsigned long timeout){ |
140 | | - if (Hardware.gpio != nullptr) { |
141 | | - return Hardware.gpio->pulseInLong(pinNumber, state, timeout); |
142 | | - } else { |
143 | | - return 0; |
144 | | - } |
| 108 | +unsigned long pulseInLong(uint8_t pinNumber, uint8_t state, |
| 109 | + unsigned long timeout) { |
| 110 | + return GPIO.pulseInLong(pinNumber, state, timeout); |
145 | 111 | } |
146 | 112 |
|
147 | | -void yield(){ |
148 | | -} |
149 | | - |
150 | | - |
| 113 | +void yield() {} |
0 commit comments