From c9e1acd72050eacd9115de42434e576bc53c0674 Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Wed, 8 Jul 2015 19:02:43 -0700 Subject: [PATCH 01/13] Doc update to mention support in Adafruit's NeoPixel library. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3a43e519b3..64ab428924 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)). - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [DHT11](https://github.com/adafruit/DHT-sensor-library) - Download latest v1.1.0 library and no changes are necessary. Older versions should initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);``` +- [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel libray, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager). - [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266. - [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266. From c77f11906cf3220989019df70cee66ce4ad65f37 Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 21:14:40 +0800 Subject: [PATCH 02/13] digitalWrite cleanup and more compliant with behavior on AVR I rewrote digitalWrite because the existing version was breaking functionality as compared to how it behaves on the AVR,. specifically, I could not use digitalWrite for a library that works fine on the AVR. Instead I had to resort to fiddling with GPOC and GPOS and bit masks, but this rewrite made all of that unnecessary, for whatever reason, it just works better. This version borrows a little from the AVR library in the sense that the same logic is applied to determine whether a pin should be high or low as the AVR version, and yes, it does appear to make a difference. --- cores/esp8266/core_esp8266_wiring_digital.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 5654e5f123..7ed1dcb26d 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/cores/esp8266/core_esp8266_wiring_digital.c @@ -77,13 +77,16 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { } extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) { - val &= 0x01; - if(pin < 16){ - if(val) GPOS = (1 << pin); - else GPOC = (1 << pin); - } else if(pin == 16){ - if(val) GP16O |= 1; - else GP16O &= ~1; + if(val == LOW) { + GP16O &= ~1; + } else { + GP16O |= 1; + } + if(val == LOW) { + GPOC = digitalPinToBitMask(pin); + } else { + GPOS = digitalPinToBitMask(pin); + } } } From d0137574d006c475b6b423db35417ecca39422e0 Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 22:04:58 +0800 Subject: [PATCH 03/13] Update core_esp8266_wiring_digital.c Ugh, I don't know how that happened. --- cores/esp8266/core_esp8266_wiring_digital.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 7ed1dcb26d..2df6952c6b 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/cores/esp8266/core_esp8266_wiring_digital.c @@ -77,11 +77,13 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { } extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) { + if (pin == 16) { if(val == LOW) { GP16O &= ~1; } else { GP16O |= 1; } + } else if ((pin >= 0) && (pin <= 15)) { if(val == LOW) { GPOC = digitalPinToBitMask(pin); } else { From 8e699b426ba10fdc694bbc6706970e7b30f6b24c Mon Sep 17 00:00:00 2001 From: h4rm0n1c Date: Fri, 10 Jul 2015 22:24:49 +0800 Subject: [PATCH 04/13] Update core_esp8266_wiring_digital.c --- cores/esp8266/core_esp8266_wiring_digital.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_digital.c b/cores/esp8266/core_esp8266_wiring_digital.c index 2df6952c6b..5be065af51 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.c +++ b/cores/esp8266/core_esp8266_wiring_digital.c @@ -77,18 +77,12 @@ extern void __pinMode(uint8_t pin, uint8_t mode) { } extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) { - if (pin == 16) { - if(val == LOW) { - GP16O &= ~1; - } else { - GP16O |= 1; - } - } else if ((pin >= 0) && (pin <= 15)) { - if(val == LOW) { - GPOC = digitalPinToBitMask(pin); - } else { - GPOS = digitalPinToBitMask(pin); - } + if(pin < 16){ + if(val) GPOS = (1 << pin); + else GPOC = (1 << pin); + } else if(pin == 16){ + if(val) GP16O |= 1; + else GP16O &= ~1; } } From 954499bc120b129d69de104a321085cd27b34a07 Mon Sep 17 00:00:00 2001 From: Kiril Zyapkov Date: Sat, 11 Jul 2015 12:35:02 +0300 Subject: [PATCH 05/13] httpUpdate: fix case sensitivity issues On Linux (presumably Mac too), the header of the library could not be included, caps changed to match the filename. The line 'architectures=ESP8266' in library.properties caused: WARNING: library ESP8266httpUpdate claims to run on [ESP8266] architecture(s) and may be incompatible with your current board which runs on [esp8266] architecture(s). --- libraries/ESP8266httpUpdate/library.properties | 4 ++-- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266httpUpdate/library.properties b/libraries/ESP8266httpUpdate/library.properties index 9be2f7d6dc..fa53da0511 100644 --- a/libraries/ESP8266httpUpdate/library.properties +++ b/libraries/ESP8266httpUpdate/library.properties @@ -1,8 +1,8 @@ name=ESP8266httpUpdate version=1.0 author=Markus Sattler -maintainer=Markus Sattler +maintainer=Markus Sattler sentence=Http Update for ESP8266 paragraph= url=https://github.com/Links2004/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/ESP8266httpUpdate -architectures=ESP8266 +architectures=esp8266 diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp index d6d3bececf..8c42afffc3 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp @@ -23,7 +23,7 @@ * */ -#include "ESP8266HTTPUpdate.h" +#include "ESP8266httpUpdate.h" ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) { From 2f34d6d74aace39888ac141525db4c98afcb866f Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 13 Jul 2015 04:20:25 +0300 Subject: [PATCH 06/13] Upload doc folder along with a package --- changes.md => doc/changes.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changes.md => doc/changes.md (100%) diff --git a/changes.md b/doc/changes.md similarity index 100% rename from changes.md rename to doc/changes.md From dece2408302713dfbef59ae5d688c24fcf23187b Mon Sep 17 00:00:00 2001 From: Makuna Date: Fri, 10 Jul 2015 18:28:04 -0700 Subject: [PATCH 07/13] Issue fixes https://github.com/esp8266/Arduino/issues/475 https://github.com/esp8266/Arduino/issues/484 --- README.md | 4 +-- cores/esp8266/core_esp8266_noniso.c | 39 ++++++++++++++++++----------- cores/esp8266/pgmspace.cpp | 11 ++++++++ cores/esp8266/pgmspace.h | 3 ++- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 64ab428924..201d0f250e 100644 --- a/README.md +++ b/README.md @@ -213,8 +213,8 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)). - [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git) - [DHT11](https://github.com/adafruit/DHT-sensor-library) - Download latest v1.1.0 library and no changes are necessary. Older versions should initialize DHT as follows: ```DHT dht(DHTPIN, DHTTYPE, 15);``` -- [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel libray, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager). -- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266. +- [NeoPixel](https://github.com/adafruit/Adafruit_NeoPixel) - Adafruit's NeoPixel library, now with support for the ESP8266 (use version 1.0.2 or higher from Arduino's library manager). +- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266. Use the "NeoPixelAnimator" branch for esp8266 to get HSL color support and more. - [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266. - [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB. diff --git a/cores/esp8266/core_esp8266_noniso.c b/cores/esp8266/core_esp8266_noniso.c index eddac25a5c..40fe5e6dd4 100644 --- a/cores/esp8266/core_esp8266_noniso.c +++ b/cores/esp8266/core_esp8266_noniso.c @@ -149,49 +149,58 @@ char* ultoa(unsigned long value, char* result, int base) { char * dtostrf(double number, signed char width, unsigned char prec, char *s) { - if(isnan(number)) { + if (isnan(number)) { strcpy(s, "nan"); return s; } - if(isinf(number)) { + if (isinf(number)) { strcpy(s, "inf"); return s; } - if(number > 4294967040.0 || number < -4294967040.0) { + if (number > 4294967040.0 || number < -4294967040.0) { strcpy(s, "ovf"); return s; } + char* out = s; + int signInt_Part = 1; + // Handle negative numbers - if(number < 0.0) { - *out = '-'; - ++out; + if (number < 0.0) { + signInt_Part = -1; number = -number; } + // calc left over digits + if (prec > 0) + { + width -= (prec + 1); + } + // Round correctly so that print(1.999, 2) prints as "2.00" double rounding = 0.5; - for(uint8_t i = 0; i < prec; ++i) + for (uint8_t i = 0; i < prec; ++i) rounding /= 10.0; number += rounding; // Extract the integer part of the number and print it - unsigned long int_part = (unsigned long) number; - double remainder = number - (double) int_part; - out += sprintf(out, "%ld", int_part); + unsigned long int_part = (unsigned long)number; + double remainder = number - (double)int_part; + out += sprintf(out, "%*ld", width, int_part * signInt_Part); // Print the decimal point, but only if there are digits beyond - if(prec > 0) { + if (prec > 0) { *out = '.'; ++out; - } - for (unsigned char decShift = prec; decShift > 0; decShift--) { - remainder *= 10.0; + + for (unsigned char decShift = prec; decShift > 0; decShift--) { + remainder *= 10.0; + } + sprintf(out, "%0*d", prec, (int)remainder); } - sprintf(out, "%0*d", prec, (int)remainder); return s; } diff --git a/cores/esp8266/pgmspace.cpp b/cores/esp8266/pgmspace.cpp index c2b5781f1f..b91dd59128 100644 --- a/cores/esp8266/pgmspace.cpp +++ b/cores/esp8266/pgmspace.cpp @@ -135,6 +135,17 @@ int printf_P(const char* formatP, ...) { return ret; } +int sprintf_P(char* str, const char* formatP, ...) { + int ret; + va_list arglist; + va_start(arglist, formatP); + + ret = vsnprintf_P(str, SIZE_IRRELEVANT, formatP, arglist); + + va_end(arglist); + return ret; +} + int snprintf_P(char* str, size_t strSize, const char* formatP, ...) { int ret; va_list arglist; diff --git a/cores/esp8266/pgmspace.h b/cores/esp8266/pgmspace.h index e6db10fbda..7669058be3 100644 --- a/cores/esp8266/pgmspace.h +++ b/cores/esp8266/pgmspace.h @@ -50,7 +50,8 @@ size_t strnlen_P(const char *s, size_t size); #define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT) int printf_P(const char *formatP, ...) __attribute__ ((format (printf, 1, 2))); -int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__ ((format (printf, 3, 4))); +int sprintf_P(char *str, const char *formatP, ...) __attribute__((format(printf, 2, 3))); +int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__((format(printf, 3, 4))); int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap) __attribute__ ((format (printf, 3, 0))); // flash memory must be read using 32 bit aligned addresses else a processor From d815c36753600a8e8f7f9610740dbd659a09818d Mon Sep 17 00:00:00 2001 From: Makuna Date: Mon, 13 Jul 2015 13:47:13 -0700 Subject: [PATCH 08/13] optimistic_yield() this introduces optimistic_yield() used for when standard library methods are normally used in tight loops waiting for something to happen, like available(). --- README.md | 1 + cores/esp8266/HardwareSerial.cpp | 18 ++++++++++++------ cores/esp8266/core_esp8266_main.cpp | 17 ++++++++++++----- libraries/ESP8266WiFi/src/WiFiClient.cpp | 17 ++++++++--------- libraries/ESP8266WiFi/src/WiFiServer.cpp | 10 +++------- libraries/ESP8266WiFi/src/WiFiUdp.cpp | 16 +++++++++++++--- libraries/Wire/Wire.cpp | 10 +++++++++- 7 files changed, 58 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 201d0f250e..db43813bb3 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ Libraries that don't rely on low-level access to AVR registers should work well. - [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy. - [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266. - [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB. +- [ST7735](https://github.com/nzmichaelh/Adafruit-ST7735-Library) - Adafruit's ST7735 library modified to be compatible with esp8266. Just make sure to modify the pins in the examples as they are still AVR specific. #### Upload via serial port #### Pick the correct serial port. diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index e77fe3ef43..7f1f2cc92b 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -551,14 +551,20 @@ bool HardwareSerial::isRxEnabled(void) { return _uart->rxEnabled; } +extern "C" void optimistic_yield(); + int HardwareSerial::available(void) { - if(_uart == 0) - return 0; - if(_uart->rxEnabled) { - return static_cast(_rx_buffer->getSize()); - } else { - return 0; + int result = 0; + + if (_uart != NULL && _uart->rxEnabled) { + result = static_cast(_rx_buffer->getSize()); } + + if (!result) { + optimistic_yield(); + } + + return result; } int HardwareSerial::peek(void) { diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index dcf5631eab..04ab9f116f 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -34,6 +34,8 @@ extern "C" { #define LOOP_TASK_PRIORITY 0 #define LOOP_QUEUE_SIZE 1 +#define OPTIMISTIC_YIELD_TIME_US 16000 + struct rst_info resetInfo; int atexit(void (*func)()) { @@ -62,11 +64,8 @@ extern void (*__init_array_end)(void); cont_t g_cont __attribute__ ((aligned (16))); static os_event_t g_loop_queue[LOOP_QUEUE_SIZE]; -static uint32_t g_micros_at_task_start; +static uint32_t g_micros_at_last_task_yield; -extern "C" uint32_t esp_micros_at_task_start() { - return g_micros_at_task_start; -} extern "C" void abort() { while(1) { @@ -74,6 +73,7 @@ extern "C" void abort() { } extern "C" void esp_yield() { + g_micros_at_last_task_yield = system_get_time(); cont_yield(&g_cont); } @@ -87,6 +87,13 @@ extern "C" void __yield() { } extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); +extern "C" void optimistic_yield() { + if (system_get_time() - g_micros_at_last_task_yield > OPTIMISTIC_YIELD_TIME_US) + { + __yield(); + } +} + static void loop_wrapper() { static bool setup_done = false; if(!setup_done) { @@ -99,7 +106,7 @@ static void loop_wrapper() { } static void loop_task(os_event_t *events) { - g_micros_at_task_start = system_get_time(); + g_micros_at_last_task_yield = system_get_time(); cont_run(&g_cont, &loop_wrapper); if(cont_check(&g_cont) != 0) { ets_printf("\r\nheap collided with sketch stack\r\n"); diff --git a/libraries/ESP8266WiFi/src/WiFiClient.cpp b/libraries/ESP8266WiFi/src/WiFiClient.cpp index 3b4a9b6f08..4327b90416 100644 --- a/libraries/ESP8266WiFi/src/WiFiClient.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClient.cpp @@ -177,20 +177,19 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size) return _client->write(reinterpret_cast(buf), size); } -extern "C" uint32_t esp_micros_at_task_start(); +extern "C" void optimistic_yield(); int WiFiClient::available() { - static uint32_t lastPollTime = 0; - if (!_client) - return 0; - - if (lastPollTime > esp_micros_at_task_start()) - yield(); + int result = 0; - lastPollTime = micros(); + if (_client) { + result = _client->getSize(); + } - int result = _client->getSize(); + if (!result) { + optimistic_yield(); + } return result; } diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index 69ad4ff81a..8c5378cd51 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -84,17 +84,15 @@ bool WiFiServer::getNoDelay(){ return tcp_nagle_disabled(_pcb); } -extern "C" uint32_t esp_micros_at_task_start(); - bool WiFiServer::hasClient(){ if (_unclaimed) return true; return false; } +extern "C" void optimistic_yield(); + WiFiClient WiFiServer::available(byte* status) { - static uint32_t lastPollTime = 0; - if (_unclaimed) { WiFiClient result(_unclaimed); @@ -103,9 +101,7 @@ WiFiClient WiFiServer::available(byte* status) return result; } - if (lastPollTime > esp_micros_at_task_start()) - yield(); - lastPollTime = micros(); + optimistic_yield(); return WiFiClient(); } diff --git a/libraries/ESP8266WiFi/src/WiFiUdp.cpp b/libraries/ESP8266WiFi/src/WiFiUdp.cpp index 80b005556b..aa7e071d76 100644 --- a/libraries/ESP8266WiFi/src/WiFiUdp.cpp +++ b/libraries/ESP8266WiFi/src/WiFiUdp.cpp @@ -113,12 +113,22 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui return 1; } +extern "C" void optimistic_yield(); + /* return number of bytes available in the current packet, will return zero if parsePacket hasn't been called yet */ int WiFiUDP::available() { - if (!_ctx) - return 0; - return static_cast(_ctx->getSize()); + int result = 0; + + if (_ctx) { + result = static_cast(_ctx->getSize()); + } + + if (!result) { + optimistic_yield(); + } + + return result; } /* Release any resources being used by this WiFiUDP instance */ diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 7591592032..39a2526ba5 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -160,8 +160,16 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){ return quantity; } +extern "C" void optimistic_yield(); + int TwoWire::available(void){ - return rxBufferLength - rxBufferIndex; + int result = rxBufferLength - rxBufferIndex; + + if (!result) { + optimistic_yield(); + } + + return result; } int TwoWire::read(void){ From ef9b324ffdf8c12f8706c1e3264d793dba040664 Mon Sep 17 00:00:00 2001 From: Bertus Kruger Date: Tue, 14 Jul 2015 09:04:12 +1200 Subject: [PATCH 09/13] Changed Telnet Port to port 23 Best to stick to standard port numbers https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers --- .../examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino index 43a9d8259d..7770cdc29a 100644 --- a/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino +++ b/libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino @@ -25,7 +25,7 @@ const char* ssid = "**********"; const char* password = "**********"; -WiFiServer server(21); +WiFiServer server(23); WiFiClient serverClients[MAX_SRV_CLIENTS]; void setup() { @@ -45,7 +45,7 @@ void setup() { Serial1.print("Ready! Use 'telnet "); Serial1.print(WiFi.localIP()); - Serial1.println(" 21' to connect"); + Serial1.println(" 23' to connect"); } void loop() { From 4b8f5342cdda6ac682b154b69795ede4936a9ccb Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Tue, 14 Jul 2015 11:05:53 -0700 Subject: [PATCH 10/13] adjust clock stretch --- cores/esp8266/core_esp8266_si2c.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cores/esp8266/core_esp8266_si2c.c b/cores/esp8266/core_esp8266_si2c.c index d825c4445b..b21b964210 100644 --- a/cores/esp8266/core_esp8266_si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -1,9 +1,9 @@ -/* +/* si2c.c - Software I2C library for esp8266 Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -26,10 +26,10 @@ unsigned char twi_dcount = 18; static unsigned char twi_sda, twi_scl; #define SDA_LOW() (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low) -#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high) +#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high) #define SDA_READ() ((GPI & (1 << twi_sda)) != 0) -#define SCL_LOW() (GPES = (1 << twi_scl)) -#define SCL_HIGH() (GPEC = (1 << twi_scl)) +#define SCL_LOW() (GPES = (1 << twi_scl)) +#define SCL_HIGH() (GPEC = (1 << twi_scl)) #define SCL_READ() ((GPI & (1 << twi_scl)) != 0) #ifndef FCPU80 @@ -37,9 +37,9 @@ static unsigned char twi_sda, twi_scl; #endif #if F_CPU == FCPU80 -#define TWI_CLOCK_STRETCH 200 +#define TWI_CLOCK_STRETCH 800 #else -#define TWI_CLOCK_STRETCH 400 +#define TWI_CLOCK_STRETCH 1600 #endif void twi_setClock(unsigned int freq){ @@ -99,7 +99,7 @@ static bool twi_write_stop(void){ twi_delay(twi_dcount); SDA_HIGH(); twi_delay(twi_dcount); - + return true; } From 87001fea23338b30cb12d1d9e26fe755af30f665 Mon Sep 17 00:00:00 2001 From: bbx10node Date: Tue, 14 Jul 2015 21:07:35 -1000 Subject: [PATCH 11/13] NACK last byte when read The TCS34725 RGB color sensor works reliably with this change. See #535 for details. --- cores/esp8266/core_esp8266_si2c.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cores/esp8266/core_esp8266_si2c.c b/cores/esp8266/core_esp8266_si2c.c index d825c4445b..a40483f6b5 100644 --- a/cores/esp8266/core_esp8266_si2c.c +++ b/cores/esp8266/core_esp8266_si2c.c @@ -1,9 +1,9 @@ -/* +/* si2c.c - Software I2C library for esp8266 Copyright (c) 2015 Hristo Gochkov. All rights reserved. This file is part of the esp8266 core for Arduino environment. - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either @@ -26,10 +26,10 @@ unsigned char twi_dcount = 18; static unsigned char twi_sda, twi_scl; #define SDA_LOW() (GPES = (1 << twi_sda)) //Enable SDA (becomes output and since GPO is 0 for the pin, it will pull the line low) -#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high) +#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high) #define SDA_READ() ((GPI & (1 << twi_sda)) != 0) -#define SCL_LOW() (GPES = (1 << twi_scl)) -#define SCL_HIGH() (GPEC = (1 << twi_scl)) +#define SCL_LOW() (GPES = (1 << twi_scl)) +#define SCL_HIGH() (GPEC = (1 << twi_scl)) #define SCL_READ() ((GPI & (1 << twi_scl)) != 0) #ifndef FCPU80 @@ -99,7 +99,7 @@ static bool twi_write_stop(void){ twi_delay(twi_dcount); SDA_HIGH(); twi_delay(twi_dcount); - + return true; } @@ -166,7 +166,8 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i unsigned int i; if(!twi_write_start()) return 4;//line busy if(!twi_write_byte(((address << 1) | 1) & 0xFF)) return 2;//received NACK on transmit of address - for(i=0; i Date: Wed, 15 Jul 2015 15:06:41 -0700 Subject: [PATCH 12/13] never yield within an ISR --- cores/esp8266/core_esp8266_main.cpp | 3 ++- tools/sdk/include/ets_sys.h | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 04ab9f116f..53f154bd0f 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -88,7 +88,8 @@ extern "C" void __yield() { extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); extern "C" void optimistic_yield() { - if (system_get_time() - g_micros_at_last_task_yield > OPTIMISTIC_YIELD_TIME_US) + if (!ETS_INTR_WITHINISR() && + (system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US) { __yield(); } diff --git a/tools/sdk/include/ets_sys.h b/tools/sdk/include/ets_sys.h index a96e2f0be7..8d7adbde3f 100644 --- a/tools/sdk/include/ets_sys.h +++ b/tools/sdk/include/ets_sys.h @@ -61,6 +61,14 @@ typedef void (*int_handler_t)(void*); #define ETS_INTR_DISABLE(inum) \ ets_isr_mask((1< 0); +} + inline uint32_t ETS_INTR_ENABLED(void) { uint32_t enabled; From 17de2d7a4e786c18ae6352c4179a9986ebfc894c Mon Sep 17 00:00:00 2001 From: Makuna Date: Wed, 15 Jul 2015 16:32:49 -0700 Subject: [PATCH 13/13] define in header remove extern from cpp files --- cores/esp8266/Arduino.h | 1 + cores/esp8266/HardwareSerial.cpp | 2 -- cores/esp8266/core_esp8266_main.cpp | 2 +- libraries/ESP8266WiFi/src/WiFiClient.cpp | 2 -- libraries/ESP8266WiFi/src/WiFiServer.cpp | 2 -- libraries/ESP8266WiFi/src/WiFiUdp.cpp | 2 -- libraries/Wire/Wire.cpp | 2 -- 7 files changed, 2 insertions(+), 11 deletions(-) diff --git a/cores/esp8266/Arduino.h b/cores/esp8266/Arduino.h index c712bf756b..ad0e7cb36d 100644 --- a/cores/esp8266/Arduino.h +++ b/cores/esp8266/Arduino.h @@ -39,6 +39,7 @@ extern "C" { #include "twi.h" void yield(void); +void optimistic_yield(void); #define HIGH 0x1 #define LOW 0x0 diff --git a/cores/esp8266/HardwareSerial.cpp b/cores/esp8266/HardwareSerial.cpp index 7f1f2cc92b..493561a24e 100644 --- a/cores/esp8266/HardwareSerial.cpp +++ b/cores/esp8266/HardwareSerial.cpp @@ -551,8 +551,6 @@ bool HardwareSerial::isRxEnabled(void) { return _uart->rxEnabled; } -extern "C" void optimistic_yield(); - int HardwareSerial::available(void) { int result = 0; diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 53f154bd0f..ca78055696 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -87,7 +87,7 @@ extern "C" void __yield() { } extern "C" void yield(void) __attribute__ ((weak, alias("__yield"))); -extern "C" void optimistic_yield() { +extern "C" void optimistic_yield(void) { if (!ETS_INTR_WITHINISR() && (system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US) { diff --git a/libraries/ESP8266WiFi/src/WiFiClient.cpp b/libraries/ESP8266WiFi/src/WiFiClient.cpp index 4327b90416..083463444e 100644 --- a/libraries/ESP8266WiFi/src/WiFiClient.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClient.cpp @@ -177,8 +177,6 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size) return _client->write(reinterpret_cast(buf), size); } -extern "C" void optimistic_yield(); - int WiFiClient::available() { int result = 0; diff --git a/libraries/ESP8266WiFi/src/WiFiServer.cpp b/libraries/ESP8266WiFi/src/WiFiServer.cpp index 8c5378cd51..cf975a330f 100644 --- a/libraries/ESP8266WiFi/src/WiFiServer.cpp +++ b/libraries/ESP8266WiFi/src/WiFiServer.cpp @@ -89,8 +89,6 @@ bool WiFiServer::hasClient(){ return false; } -extern "C" void optimistic_yield(); - WiFiClient WiFiServer::available(byte* status) { if (_unclaimed) diff --git a/libraries/ESP8266WiFi/src/WiFiUdp.cpp b/libraries/ESP8266WiFi/src/WiFiUdp.cpp index aa7e071d76..71f8ff41a5 100644 --- a/libraries/ESP8266WiFi/src/WiFiUdp.cpp +++ b/libraries/ESP8266WiFi/src/WiFiUdp.cpp @@ -113,8 +113,6 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui return 1; } -extern "C" void optimistic_yield(); - /* return number of bytes available in the current packet, will return zero if parsePacket hasn't been called yet */ int WiFiUDP::available() { diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 39a2526ba5..84b4c8c224 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -160,8 +160,6 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){ return quantity; } -extern "C" void optimistic_yield(); - int TwoWire::available(void){ int result = rxBufferLength - rxBufferIndex;