diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 190ff3009..b2126b627 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -24,23 +24,55 @@ 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); extern "C" void wdt_feed(void); +/** + * User-defined Literals + * usage: + * + * uint32_t = test = 10_MHz; // --> 10000000 + */ + +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; +} + + EspClass ESP; EspClass::EspClass() @@ -134,15 +166,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 +190,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; } @@ -186,3 +218,32 @@ FlashMode_t EspClass::getFlashChipMode(void) } return mode; } + +/** + * Infos from + * http://www.wlxmall.com/images/stock_item/att/A1010004.pdf + * http://www.gigadevice.com/product-series/5.html?locale=en_US + */ +uint32_t EspClass::getFlashChipSizeByChipId(void) { + uint32_t chipId = getFlashChipId(); + switch(chipId) { + case 0x1740C8: // GD25Q64B + return (8_MB); + case 0x1640C8: // GD25Q32B + return (4_MB); + case 0x1540C8: // GD25Q16B + return (2_MB); + case 0x1440C8: // GD25Q80 + return (1_MB); + case 0x1340C8: // GD25Q40 + return (512_kB); + case 0x1240C8: // GD25Q20 + return (256_kB); + case 0x1140C8: // GD25Q10 + return (128_kB); + case 0x1040C8: // GD25Q12 + return (64_kB); + default: + return 0; + } +} diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index 34fa3e13b..78b468163 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -90,6 +90,7 @@ class EspClass { uint32_t getFlashChipSize(void); uint32_t getFlashChipSpeed(void); FlashMode_t getFlashChipMode(void); + uint32_t getFlashChipSizeByChipId(void); }; diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index ad8766444..9bd3e35a8 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -510,6 +510,9 @@ void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) { } void ICACHE_FLASH_ATTR HardwareSerial::end() { + if(uart_get_debug() == _uart_nr) { + uart_set_debug(UART_NO); + } uart_uninit(_uart); delete _rx_buffer; delete _tx_buffer; diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 326d3264b..d45165443 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -48,7 +48,7 @@ extern void setup(); void preloop_update_frequency() __attribute__((weak)); void preloop_update_frequency() { -#if defined(F_CPU) && (F_CPU == 16000000L) +#if defined(F_CPU) && (F_CPU == 160000000L) REG_SET_BIT(0x3ff00014, BIT(0)); ets_update_cpu_frequency(160); #endif diff --git a/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 5ac670e63..e9fe9ce58 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/cores/esp8266/core_esp8266_wiring_digital.c @@ -59,13 +59,17 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO GPC(pin) = (GPC(pin) & (0xF << GPCI)); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED) GPES = (1 << pin); //Enable - } else if(mode == INPUT || mode == INPUT_PULLUP){ + } else if(mode == INPUT || mode == INPUT_PULLUP || mode == INPUT_PULLDOWN){ GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED) GPEC = (1 << pin); //Disable - if(mode == INPUT_PULLUP){ - GPF(pin) |= (1 << GPFPU);//Enable Pullup - } + if(mode == INPUT_PULLUP) { + GPF(pin) &= ~(1 << GPFPD); // Disable Pulldown + GPF(pin) |= (1 << GPFPU); // Enable Pullup + } else if(mode == INPUT_PULLDOWN) { + GPF(pin) &= ~(1 << GPFPU); // Disable Pullup + GPF(pin) |= (1 << GPFPD); // Enable Pulldown + } } } else if(pin == 16){ GPF16 = GP16FFS(GPFFS_GPIO(pin));//Set mode to GPIO @@ -81,7 +85,7 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { } } -extern void __digitalWrite(uint8_t pin, uint8_t val) { +extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) { val &= 0x01; if(pin < 16){ if(val) GPOS = (1 << pin); @@ -92,12 +96,13 @@ extern void __digitalWrite(uint8_t pin, uint8_t val) { } } -extern int __digitalRead(uint8_t pin) { +extern int ICACHE_RAM_ATTR __digitalRead(uint8_t pin) { if(pin < 16){ return GPIP(pin); } else if(pin == 16){ return GP16I & 0x01; } + return 0; } /* @@ -154,6 +159,11 @@ extern void __detachInterrupt(uint8_t pin) { } void initPins() { + //Disable UART interrupts + system_set_os_print(0); + U0IE = 0; + U1IE = 0; + for (int i = 0; i <= 5; ++i) { pinMode(i, INPUT); } diff --git a/cores/esp8266/esp8266_peri.h b/cores/esp8266/esp8266_peri.h index f905d34b3..8b92a07f5 100644 --- a/cores/esp8266/esp8266_peri.h +++ b/cores/esp8266/esp8266_peri.h @@ -93,9 +93,11 @@ static uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C, //GPIO (0-15) PIN Function Bits #define GPFSOE 0 //Sleep OE #define GPFSS 1 //Sleep Sel +#define GPFSPD 2 //Sleep Pulldown #define GPFSPU 3 //Sleep Pullup #define GPFFS0 4 //Function Select bit 0 #define GPFFS1 5 //Function Select bit 1 +#define GPFPD 6 //Pulldown #define GPFPU 7 //Pullup #define GPFFS2 8 //Function Select bit 2 #define GPFFS(f) (((((f) & 4) != 0) << GPFFS2) | ((((f) & 2) != 0) << GPFFS1) | ((((f) & 1) != 0) << GPFFS0)) diff --git a/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino b/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino index 10da0e9b3..09b5038f9 100644 --- a/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino +++ b/libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino @@ -9,16 +9,21 @@ MDNSResponder mdns; ESP8266WebServer server(80); +const int led = 13; + void handleRoot() { + digitalWrite(led, 1); server.send(200, "text/plain", "hello from esp8266!"); + digitalWrite(led, 0); } void handleNotFound(){ - String message = "URI: "; + digitalWrite(led, 1); + String message += "File Not Found\n\n"; + message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; - message += "\nNot Found!\n\n"; message += "\nArguments: "; message += server.args(); message += "\n"; @@ -26,9 +31,12 @@ void handleNotFound(){ message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; } server.send(404, "text/plain", message); + digitalWrite(led, 0); } void setup(void){ + pinMode(led, OUTPUT); + digitalWrite(led, 0); Serial.begin(115200); WiFi.begin(ssid, password); Serial.println(""); diff --git a/platform.txt b/platform.txt index b3aa18f36..72915c027 100644 --- a/platform.txt +++ b/platform.txt @@ -23,7 +23,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD compiler.c.elf.ldscript=eagle.app.v6.ld compiler.c.elf.flags=-nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{compiler.c.elf.ldscript}" compiler.c.elf.cmd=xtensa-lx106-elf-gcc -compiler.c.elf.libs=-lc -lm -lg -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig +compiler.c.elf.libs=-lm -lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig compiler.cpp.cmd=xtensa-lx106-elf-g++ compiler.cpp.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD