AceTime  0.5.1
Date and time classes for Arduino that support timezones from the TZ Database, and a system clock that can synchronize from an NTP server or an RTC chip.
compat.h
Go to the documentation of this file.
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 #ifndef ACE_TIME_COMMON_COMPAT_H
7 #define ACE_TIME_COMMON_COMPAT_H
8 
18 #include <stdint.h>
19 #include <string.h>
20 
22 #define ACE_TIME_USE_PROGMEM 1
23 #if ACE_TIME_USE_PROGMEM
24  #define ACE_TIME_PROGMEM PROGMEM
25 #else
26  #define ACE_TIME_PROGMEM
27 #endif
28 
29 // Include the correct pgmspace.h depending on architecture. Define a
30 // consistent acetime_strcmp_P() which can be passed as a function pointer
31 // into the ZoneManager template class.
32 #if defined(ARDUINO_ARCH_AVR)
33  #include <avr/pgmspace.h>
34  #define FPSTR(p) (reinterpret_cast<const __FlashStringHelper *>(p))
35  #define acetime_strcmp_P strcmp_P
36 
37 #elif defined(ARDUINO_ARCH_SAMD)
38  #include <avr/pgmspace.h>
39  #define FPSTR(p) (reinterpret_cast<const __FlashStringHelper *>(p))
40 
41  // strcmp_P(a,b) is defined to be strcmp(a,b), but we need a function
42  // pointer, so map it directly to strcmp()
43  #define acetime_strcmp_P strcmp
44 
45  // Set this to 1 to clobber SERIAL_PORT_MONITOR to SerialUSB on
46  // an original Arduino Zero when using the Native port. See USER_GUIDE.md for
47  // more info.
48  #define ACE_TIME_CLOBBER_SERIAL_PORT_MONITOR 0
49  #if ACE_TIME_CLOBBER_SERIAL_PORT_MONITOR && defined(ARDUINO_SAMD_ZERO)
50  #undef SERIAL_PORT_MONITOR
51  #define SERIAL_PORT_MONITOR SerialUSB
52  #endif
53 
54 #elif defined(TEENSYDUINO)
55  #include <avr/pgmspace.h>
56  #define FPSTR(p) (reinterpret_cast<const __FlashStringHelper *>(p))
57  // Teensyduino defines strcmp_P(a, b) as strcmp(a,b), which cannot be
58  // passed as a function pointer, so we have to use strcmp() directly.
59  #define acetime_strcmp_P strcmp
60 
61 #elif defined(ESP8266)
62  #include <pgmspace.h>
63 
64  // ESP8266 2.5.2 defines strcmp_P() as a macro function, but we need a real
65  // function.
66  inline int acetime_strcmp_P(const char* str1, const char* str2P) {
67  return strcmp_P((str1), (str2P));
68  }
69 
70  // ESP8266 2.5.2 doesn't have these so provide our own implementation.
71  extern "C" {
72  const char* strchr_P(const char* s, int c);
73  const char* strrchr_P(const char* s, int c);
74  }
75 
76 #elif defined(ESP32)
77  #include <pgmspace.h>
78  // Fix incorrect definition of FPSTR in ESP32 1.0.2. See
79  // https://github.com/espressif/arduino-esp32/issues/1371
80  #undef FPSTR
81  #define FPSTR(p) (reinterpret_cast<const __FlashStringHelper *>(p))
82  #define acetime_strcmp_P strcmp_P
83 
84  // ESP32 1.0.2 doesn't have these so provide our own implementation.
85  extern "C" {
86  const char* strchr_P(const char* s, int c);
87  const char* strrchr_P(const char* s, int c);
88  }
89 
90  // ESP32 does not define SERIAL_PORT_MONITOR
91  #define SERIAL_PORT_MONITOR Serial
92 
93 #elif defined(__linux__) or defined(__APPLE__)
94  #include <pgmspace.h>
95  #define FPSTR(p) (reinterpret_cast<const __FlashStringHelper *>(p))
96  #define acetime_strcmp_P strcmp_P
97  #define SERIAL_PORT_MONITOR Serial
98 
99 #else
100  #error Unsupported platform
101 #endif
102 
107 int acetime_strcmp_PP(const char* a, const char* b);
108 
109 #endif
int acetime_strcmp_PP(const char *a, const char *b)
Compare 2 strings in flash memory.
Definition: compat.cpp:36