Fix STM32 flashing options (#2997)
[ExpressLRS.git] / src / include / native.h
blobee23fadd02368320ee12fed520eb158e22ce1d48
1 #pragma once
3 #include <stdint.h>
4 #include <cstdlib>
5 #include <cstdint>
6 #include <cstring>
7 #include <cctype>
8 #include <algorithm>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <math.h>
13 #include <sys/time.h>
15 #define DEVICE_NAME "testing"
16 #define RADIO_SX128X 1
18 typedef uint8_t byte;
20 #define HEX 16
21 #define DEC 10
23 class Stream
25 public:
26 Stream() {}
27 virtual ~Stream() {}
29 // Stream methods
30 virtual int available() = 0;
31 virtual int read() = 0;
32 virtual int peek() = 0;
33 virtual void flush() = 0;
35 // Print methods
36 virtual size_t write(uint8_t c) = 0;
37 virtual size_t write(const uint8_t *s, size_t l) = 0;
39 int print(const char *s) {return 0;}
40 int print(uint8_t s) {return 0;}
41 int print(uint8_t s, int radix) {return 0;}
42 int println() {return 0;}
43 int println(const char *s) {return 0;}
44 int println(uint8_t s) {return 0;}
45 int println(uint8_t s, int radix) {return 0;}
48 class HardwareSerial: public Stream {
49 public:
50 // Stream methods
51 int available() {return 0;}
52 int read() {return -1;}
53 int peek() {return 0;}
54 void flush() {}
55 void end() {}
56 void begin(int baud) {}
57 void enableHalfDuplexRx() {}
58 int availableForWrite() {return 256;}
60 // Print methods
61 size_t write(uint8_t c) {return 1;}
62 size_t write(const uint8_t *s, size_t l) {return l;}
64 int print(const char *s) {return 0;}
65 int print(uint8_t s) {return 0;}
66 int print(uint8_t s, int radix) {return 0;}
67 int println() {return 0;}
68 int println(const char *s) {return 0;}
69 int println(uint8_t s) {return 0;}
70 int println(uint8_t s, int radix) {return 0;}
73 static HardwareSerial Serial;
74 static Stream *SerialLogger = &Serial;
76 inline void interrupts() {}
77 inline void noInterrupts() {}
79 inline unsigned long micros() {
80 struct timeval tv;
81 gettimeofday(&tv,NULL);
82 return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
85 inline void delay(int32_t time) {
86 usleep(time);
89 inline unsigned long millis() { return 0; }
90 inline void delayMicroseconds(int delay) { }
91 inline char *itoa(int32_t value, char *str, int base) { sprintf(str, "%d", value); return str; }
92 inline char *utoa(uint32_t value, char *str, int base) { sprintf(str, "%u", value); return str; }
93 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
95 #ifdef _WIN32
96 #define random rand
97 #define srandom srand
98 #endif