AceTime  1.3
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 
58  // Teensyduino defines strcmp_P(a, b) as strcmp(a,b), which cannot be
59  // passed as a function pointer, so we have to use strcmp() directly.
60  #define acetime_strcmp_P strcmp
61 
62 #elif defined(ESP8266)
63  #include <pgmspace.h>
64  #include <AceCommon.h>
65 
66  // ESP8266 2.5.2 defines strcmp_P() as a macro function, but we need a real
67  // function.
68  inline int acetime_strcmp_P(const char* str1, const char* str2P) {
69  return strcmp_P((str1), (str2P));
70  }
71 
72  // ESP8266 2.5.2 doesn't have these so use versions from AceCommon
73  using ace_common::strchr_P;
74  using ace_common::strrchr_P;
75 
76 #elif defined(ESP32)
77  #include <pgmspace.h>
78  #include <AceCommon.h>
79 
80  #define acetime_strcmp_P strcmp_P
81 
82  // ESP32 1.0.4 doesn't have these so use versions from AceCommon
83  using ace_common::strchr_P;
84  using ace_common::strrchr_P;
85 
86  // ESP32 does not define SERIAL_PORT_MONITOR. Define it unless another
87  // library has already defined it.
88  #if ! defined(SERIAL_PORT_MONITOR)
89  #define SERIAL_PORT_MONITOR Serial
90  #endif
91 
92 #elif defined(UNIX_HOST_DUINO)
93  #include <pgmspace.h>
94  #define acetime_strcmp_P strcmp_P
95 
96 #else
97  #error Unsupported platform
98 #endif
99 
100 #endif