29 #ifndef _SSD1306_LINUX_IO_H_ 30 #define _SSD1306_LINUX_IO_H_ 32 #if (defined(__linux__) || defined(__MINGW32__)) && !defined(ARDUINO) 34 #define SSD1306_LINUX_SUPPORTED 36 #if defined(SDL_EMULATION) // SDL Emulation mode includes 40 #if defined(__KERNEL__) // KERNEL includes 41 #include <linux/types.h> 43 #elif defined(__MINGW32__) // MINGW32 includes 51 #else // LINUX includes 70 static inline int digitalRead(
int pin) {
return LOW; };
71 #if defined(__KERNEL__) // ============== KERNEL 72 static inline void delay(
unsigned long ms) { };
73 static inline void delayMicroseconds(
unsigned long us) { };
74 static inline int analogRead(
int pin) {
return 0; };
75 static inline void digitalWrite(
int pin,
int level) { };
76 static inline uint32_t millis(
void) {
return 0; };
77 static inline uint32_t micros(
void) {
return 0; };
78 static inline void pinMode(
int pin,
int mode) {};
80 #elif defined(__MINGW32__) // ============== MINGW32 81 static inline void delay(
unsigned long ms) { Sleep(ms); };
82 static inline void delayMicroseconds(
unsigned long us) { Sleep((us+500)/1000); };
83 static inline uint32_t millis(
void)
85 return GetTickCount();
88 static inline uint32_t micros(
void)
90 return GetTickCount()*1000;
93 #else // ============== LINUX 94 static inline void delay(
unsigned long ms) { usleep(ms*1000); };
95 static inline void delayMicroseconds(
unsigned long us) { usleep(us); };
96 static inline uint32_t millis(
void)
99 clock_gettime(CLOCK_MONOTONIC, &ts);
100 return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
103 static inline uint32_t micros(
void)
106 clock_gettime(CLOCK_MONOTONIC, &ts);
107 return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
114 static inline int min(
int a,
int b) {
return a<b?a:b; };
115 static inline int max(
int a,
int b) {
return a>b?a:b; };
116 #if !defined(SDL_EMULATION) 117 void pinMode(
int pin,
int mode);
122 #if defined(__MINGW32__) || defined(SDL_EMULATION) 123 static inline int analogRead(
int pin) {
return sdl_read_analog(pin); };
124 static inline void digitalWrite(
int pin,
int level) { sdl_write_digital(pin, level); };
125 static inline void pinMode(
int pin,
int mode) { };
126 #elif !defined(__KERNEL__) 127 static inline int analogRead(
int pin) {
return 0; };
128 void digitalWrite(
int pin,
int level);
131 static inline void randomSeed(
int seed) { };
132 static inline void attachInterrupt(
int pin,
void (*interrupt)(
void),
int level) { };
133 static inline uint8_t pgm_read_byte(
const void *ptr) {
return *((
const uint8_t *)ptr); };
134 static inline uint16_t eeprom_read_word(
const void *ptr) {
return 0; };
135 static inline void eeprom_write_word(
const void *ptr, uint16_t val) { };
137 static inline char *utoa(
unsigned int num,
char *str,
int radix)
148 digit = (
unsigned int)num % radix;
150 temp[temp_loc++] = digit +
'0';
152 temp[temp_loc++] = digit - 10 +
'A';
153 num = ((
unsigned int)num) / radix;
154 }
while ((
unsigned int)num > 0);
160 while ( temp_loc >=0 ) {
161 str[str_loc++] = temp[temp_loc--];
174 static inline long random(
long v)
179 static inline long random(
long min,
long max)
181 return rand() % (max - min + 1) + min;