Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.4 KiB

  1. /*
  2. COMPATIBILITY BETWEEN 2.3.0 and latest versions
  3. */
  4. #pragma once
  5. // -----------------------------------------------------------------------------
  6. // Core version 2.4.2 and higher changed the cont_t structure to a pointer:
  7. // https://github.com/esp8266/Arduino/commit/5d5ea92a4d004ab009d5f642629946a0cb8893dd#diff-3fa12668b289ccb95b7ab334833a4ba8L35
  8. // Core version 2.5.0 introduced EspClass helper method:
  9. // https://github.com/esp8266/Arduino/commit/0e0e34c614fe8a47544c9998201b1d9b3c24eb18
  10. // -----------------------------------------------------------------------------
  11. extern "C" {
  12. #include <cont.h>
  13. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) \
  14. || defined(ARDUINO_ESP8266_RELEASE_2_4_0) \
  15. || defined(ARDUINO_ESP8266_RELEASE_2_4_1)
  16. extern cont_t g_cont;
  17. #define getFreeStack() cont_get_free_stack(&g_cont)
  18. #elif defined(ARDUINO_ESP8266_RELEASE_2_4_2)
  19. extern cont_t* g_pcont;
  20. #define getFreeStack() cont_get_free_stack(g_pcont)
  21. #else
  22. #define getFreeStack() ESP.getFreeContStack()
  23. #endif
  24. }
  25. #include <pgmspace.h>
  26. // -----------------------------------------------------------------------------
  27. // ref: https://github.com/esp8266/Arduino/blob/master/tools/sdk/libc/xtensa-lx106-elf/include/sys/pgmspace.h
  28. // __STRINGIZE && __STRINGIZE_NX && PROGMEM definitions port
  29. // -----------------------------------------------------------------------------
  30. // Do not replace macros unless running version older than 2.5.0
  31. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0) \
  32. || defined(ARDUINO_ESP8266_RELEASE_2_4_0) \
  33. || defined(ARDUINO_ESP8266_RELEASE_2_4_1) \
  34. || defined(ARDUINO_ESP8266_RELEASE_2_4_2)
  35. // Quoting esp8266/Arduino comments:
  36. // "Since __section__ is supposed to be only use for global variables,
  37. // there could be conflicts when a static/inlined function has them in the
  38. // same file as a non-static PROGMEM object.
  39. // Ref: https://gcc.gnu.org/onlinedocs/gcc-3.2/gcc/Variable-Attributes.html
  40. // Place each progmem object into its own named section, avoiding conflicts"
  41. #define __TO_STR_(A) #A
  42. #define __TO_STR(A) __TO_STR_(A)
  43. #undef PROGMEM
  44. #define PROGMEM __attribute__((section( "\".irom.text." __FILE__ "." __TO_STR(__LINE__) "." __TO_STR(__COUNTER__) "\"")))
  45. // "PSTR() macro modified to start on a 32-bit boundary. This adds on average
  46. // 1.5 bytes/string, but in return memcpy_P and strcpy_P will work 4~8x faster"
  47. #undef PSTR
  48. #define PSTR(s) (__extension__({static const char __c[] __attribute__((__aligned__(4))) PROGMEM = (s); &__c[0];}))
  49. #endif
  50. // -----------------------------------------------------------------------------
  51. // Division by zero bug
  52. // https://github.com/esp8266/Arduino/pull/2397
  53. // https://github.com/esp8266/Arduino/pull/2408
  54. // -----------------------------------------------------------------------------
  55. #if defined(ARDUINO_ESP8266_RELEASE_2_3_0)
  56. long __attribute__((deprecated("Please avoid using map() with Core 2.3.0"))) map(long x, long in_min, long in_max, long out_min, long out_max);
  57. #endif
  58. // -----------------------------------------------------------------------------
  59. // std::make_unique backport for C++11, since we still use it
  60. // -----------------------------------------------------------------------------
  61. #if 201103L >= __cplusplus
  62. namespace std {
  63. template<typename T, typename... Args>
  64. std::unique_ptr<T> make_unique(Args&&... args) {
  65. return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
  66. }
  67. }
  68. #endif
  69. #define UNUSED(x) (void)(x)