diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index 19c25e899..6b9aedcfb 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -186,4 +186,48 @@ long map(long, long, long, long, long); #include "pins_arduino.h" +/** + * User-defined Literals + * usage: + * + * uint32_t = test = 10_MHz; // --> 10000000 + */ +#ifdef __cplusplus +unsigned long long operator"" _kHz(unsigned long long x) { + return x * 1000; +} + +unsigned long long operator"" _MHz(unsigned long long x) { + return x * 1000 * 1000; +} + +unsigned long long operator"" _GHz(unsigned long long x) { + return x * 1000 * 1000 * 1000; +} + +unsigned long long operator"" _kBit(unsigned long long x) { + return x * 1024; +} + +unsigned long long operator"" _MBit(unsigned long long x) { + return x * 1024 * 1024; +} + +unsigned long long operator"" _GBit(unsigned long long x) { + return x * 1024 * 1024 * 1024; +} + +unsigned long long operator"" _kB(unsigned long long x) { + return x * 1024; +} + +unsigned long long operator"" _MB(unsigned long long x) { + return x * 1024 * 1024; +} + +unsigned long long operator"" _GB(unsigned long long x) { + return x * 1024 * 1024 * 1024; +} +#endif + #endif diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 190ff3009..5dafde53e 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -24,18 +24,6 @@ extern "C" { #include "user_interface.h" } -#define kHz (1000L) -#define MHz (1000L*kHz) -#define GHz (1000L*MHz) - -#define kBit (1024L) -#define MBit (1024L*kBit) -#define GBit (1024L*MBit) - -#define kB (1024L) -#define MB (1024L*kB) -#define GB (1024L*MB) - //extern "C" void ets_wdt_init(uint32_t val); extern "C" void ets_wdt_enable(void); extern "C" void ets_wdt_disable(void); @@ -134,15 +122,15 @@ uint32_t EspClass::getFlashChipSize(void) if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { switch((bytes[3] & 0xf0) >> 4) { case 0x0: // 4 Mbit (512KB) - return (512 * kB); + return (512_kB); case 0x1: // 2 MBit (256KB) - return (256 * kB); + return (256_kB); case 0x2: // 8 MBit (1MB) - return (1 * MB); + return (1_MB); case 0x3: // 16 MBit (2MB) - return (2 * MB); + return (2_MB); case 0x4: // 32 MBit (4MB) - return (4 * MB); + return (4_MB); default: // fail? return 0; } @@ -158,13 +146,13 @@ uint32_t EspClass::getFlashChipSpeed(void) if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { switch(bytes[3] & 0x0F) { case 0x0: // 40 MHz - return (40 * MHz); + return (40_MHz); case 0x1: // 26 MHz - return (26 * MHz); + return (26_MHz); case 0x2: // 20 MHz - return (20 * MHz); + return (20_MHz); case 0xf: // 80 MHz - return (80 * MHz); + return (80_MHz); default: // fail? return 0; }