Arduino.h
1 /*
2  * EEZ PSU Firmware
3  * Copyright (C) 2015-present, Envox d.o.o.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14 
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <stdint.h>
22 #include <queue>
23 
24 typedef uint8_t byte;
25 
26 namespace eez {
27 namespace psu {
28 namespace simulator {
30 namespace arduino {
31 
32 #define LSBFIRST 0
33 #define MSBFIRST 1
34 
35 #define INPUT 0x0
36 #define OUTPUT 0x1
37 #define INPUT_PULLUP 0x2
38 
39 #define HIGH 0x1
40 #define LOW 0x0
41 
42 #define CHANGE 1
43 #define FALLING 2
44 #define RISING 3
45 
46 #define digitalPinToInterrupt(p) (p)
47 
48 static const uint8_t SS = 53;
49 static const uint8_t MOSI = 51;
50 static const uint8_t MISO = 50;
51 static const uint8_t SCK = 52;
52 
53 void pinMode(uint8_t pin, uint8_t mode);
54 int digitalRead(uint8_t pin);
55 void digitalWrite(uint8_t pin, uint8_t state);
56 int analogRead(uint8_t pin);
57 void analogWrite(uint8_t pin, int state);
58 
59 typedef void(*InterruptCallback)(void);
60 
61 void attachInterrupt(uint8_t, InterruptCallback, int mode);
62 void detachInterrupt(uint8_t);
63 
64 void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
65 
66 uint32_t millis();
67 uint32_t micros();
68 void delay(uint32_t millis);
69 void delayMicroseconds(uint32_t microseconds);
70 
72 class IPAddress {
73  friend class SimulatorSerial;
74 
75 private:
76  union {
77  uint8_t bytes[4]; // IPv4 address
78  uint32_t dword;
79  } _address;
80 
81 public:
82  operator uint32_t() const { return _address.dword; };
83 };
84 
87 public:
88  void begin(unsigned long baud);
89  int write(const char *buffer, int size);
90  int print(const char *data);
91  int println(int value);
92  int println(const char *data);
93  int println(IPAddress ipAddress);
94  operator bool() { return true; }
95  int available(void);
96  int read(void);
97  void flush(void);
98 
99  void put(int ch);
100 
101 private:
102  std::queue<int> input;
103 };
104 
105 extern SimulatorSerial Serial;
106 
107 #define PROGMEM
108 #define pgm_read_byte_near(address_short) (*(address_short))
109 
110 }
111 }
112 }
113 } // namespace eez::psu::simulator::arduino;
114 
115 using namespace eez::psu::simulator::arduino;
Arduino API simulation.
Definition: Arduino.h:30
Bare minimum implementation of the Arduino Serial object.
Definition: Arduino.h:86
Namespace for the everything from the EEZ.
Definition: actions.cpp:41
Bare minimum implementation of the Arduino IPAddress class.
Definition: Arduino.h:72