Skip to content

Commit 1031e26

Browse files
committed
Merge pull request #1 from esp8266/esp8266
pull master
2 parents a6d8253 + 01361fc commit 1031e26

18 files changed

+113
-64
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ Libraries that don't rely on low-level access to AVR registers should work well.
213213
- [Blynk](https://github.com/blynkkk/blynk-library) - easy IoT framework for Makers (check out the [Kickstarter page](http://tiny.cc/blynk-kick)).
214214
- [DallasTemperature](https://github.com/milesburton/Arduino-Temperature-Control-Library.git)
215215
- [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);```
216-
- [NeoPixelBus](https://github.com/Makuna/NeoPixelBus) - Arduino NeoPixel library compatible with esp8266.
216+
- [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).
217+
- [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.
217218
- [PubSubClient](https://github.com/Imroy/pubsubclient) MQTT library by @Imroy.
218219
- [RTC](https://github.com/Makuna/Rtc) - Arduino Library for Ds1307 & Ds3231 compatible with esp8266.
219220
- [Souliss, Smart Home](https://github.com/souliss/souliss) - Framework for Smart Home based on Arduino, Android and openHAB.
221+
- [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.
220222

221223
#### Upload via serial port ####
222224
Pick the correct serial port.

cores/esp8266/Arduino.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
#include "twi.h"
4040

4141
void yield(void);
42+
void optimistic_yield(void);
4243

4344
#define HIGH 0x1
4445
#define LOW 0x0

cores/esp8266/HardwareSerial.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -552,13 +552,17 @@ bool HardwareSerial::isRxEnabled(void) {
552552
}
553553

554554
int HardwareSerial::available(void) {
555-
if(_uart == 0)
556-
return 0;
557-
if(_uart->rxEnabled) {
558-
return static_cast<int>(_rx_buffer->getSize());
559-
} else {
560-
return 0;
555+
int result = 0;
556+
557+
if (_uart != NULL && _uart->rxEnabled) {
558+
result = static_cast<int>(_rx_buffer->getSize());
559+
}
560+
561+
if (!result) {
562+
optimistic_yield();
561563
}
564+
565+
return result;
562566
}
563567

564568
int HardwareSerial::peek(void) {

cores/esp8266/core_esp8266_main.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ extern "C" {
3434
#define LOOP_TASK_PRIORITY 0
3535
#define LOOP_QUEUE_SIZE 1
3636

37+
#define OPTIMISTIC_YIELD_TIME_US 16000
38+
3739
struct rst_info resetInfo;
3840

3941
int atexit(void (*func)()) {
@@ -62,18 +64,16 @@ extern void (*__init_array_end)(void);
6264
cont_t g_cont __attribute__ ((aligned (16)));
6365
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
6466

65-
static uint32_t g_micros_at_task_start;
67+
static uint32_t g_micros_at_last_task_yield;
6668

67-
extern "C" uint32_t esp_micros_at_task_start() {
68-
return g_micros_at_task_start;
69-
}
7069

7170
extern "C" void abort() {
7271
while(1) {
7372
}
7473
}
7574

7675
extern "C" void esp_yield() {
76+
g_micros_at_last_task_yield = system_get_time();
7777
cont_yield(&g_cont);
7878
}
7979

@@ -87,6 +87,14 @@ extern "C" void __yield() {
8787
}
8888
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
8989

90+
extern "C" void optimistic_yield(void) {
91+
if (!ETS_INTR_WITHINISR() &&
92+
(system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US)
93+
{
94+
__yield();
95+
}
96+
}
97+
9098
static void loop_wrapper() {
9199
static bool setup_done = false;
92100
if(!setup_done) {
@@ -99,7 +107,7 @@ static void loop_wrapper() {
99107
}
100108

101109
static void loop_task(os_event_t *events) {
102-
g_micros_at_task_start = system_get_time();
110+
g_micros_at_last_task_yield = system_get_time();
103111
cont_run(&g_cont, &loop_wrapper);
104112
if(cont_check(&g_cont) != 0) {
105113
ets_printf("\r\nheap collided with sketch stack\r\n");

cores/esp8266/core_esp8266_noniso.c

+24-15
Original file line numberDiff line numberDiff line change
@@ -149,49 +149,58 @@ char* ultoa(unsigned long value, char* result, int base) {
149149

150150
char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
151151

152-
if(isnan(number)) {
152+
if (isnan(number)) {
153153
strcpy(s, "nan");
154154
return s;
155155
}
156-
if(isinf(number)) {
156+
if (isinf(number)) {
157157
strcpy(s, "inf");
158158
return s;
159159
}
160160

161-
if(number > 4294967040.0 || number < -4294967040.0) {
161+
if (number > 4294967040.0 || number < -4294967040.0) {
162162
strcpy(s, "ovf");
163163
return s;
164164
}
165+
165166
char* out = s;
167+
int signInt_Part = 1;
168+
166169
// Handle negative numbers
167-
if(number < 0.0) {
168-
*out = '-';
169-
++out;
170+
if (number < 0.0) {
171+
signInt_Part = -1;
170172
number = -number;
171173
}
172174

175+
// calc left over digits
176+
if (prec > 0)
177+
{
178+
width -= (prec + 1);
179+
}
180+
173181
// Round correctly so that print(1.999, 2) prints as "2.00"
174182
double rounding = 0.5;
175-
for(uint8_t i = 0; i < prec; ++i)
183+
for (uint8_t i = 0; i < prec; ++i)
176184
rounding /= 10.0;
177185

178186
number += rounding;
179187

180188
// Extract the integer part of the number and print it
181-
unsigned long int_part = (unsigned long) number;
182-
double remainder = number - (double) int_part;
183-
out += sprintf(out, "%ld", int_part);
189+
unsigned long int_part = (unsigned long)number;
190+
double remainder = number - (double)int_part;
191+
out += sprintf(out, "%*ld", width, int_part * signInt_Part);
184192

185193
// Print the decimal point, but only if there are digits beyond
186-
if(prec > 0) {
194+
if (prec > 0) {
187195
*out = '.';
188196
++out;
189-
}
190197

191-
for (unsigned char decShift = prec; decShift > 0; decShift--) {
192-
remainder *= 10.0;
198+
199+
for (unsigned char decShift = prec; decShift > 0; decShift--) {
200+
remainder *= 10.0;
201+
}
202+
sprintf(out, "%0*d", prec, (int)remainder);
193203
}
194-
sprintf(out, "%0*d", prec, (int)remainder);
195204

196205
return s;
197206
}

cores/esp8266/core_esp8266_si2c.c

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
1+
/*
22
si2c.c - Software I2C library for esp8266
33
44
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
55
This file is part of the esp8266 core for Arduino environment.
6-
6+
77
This library is free software; you can redistribute it and/or
88
modify it under the terms of the GNU Lesser General Public
99
License as published by the Free Software Foundation; either
@@ -26,20 +26,20 @@ unsigned char twi_dcount = 18;
2626
static unsigned char twi_sda, twi_scl;
2727

2828
#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)
29-
#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
29+
#define SDA_HIGH() (GPEC = (1 << twi_sda)) //Disable SDA (becomes input and since it has pullup it will go high)
3030
#define SDA_READ() ((GPI & (1 << twi_sda)) != 0)
31-
#define SCL_LOW() (GPES = (1 << twi_scl))
32-
#define SCL_HIGH() (GPEC = (1 << twi_scl))
31+
#define SCL_LOW() (GPES = (1 << twi_scl))
32+
#define SCL_HIGH() (GPEC = (1 << twi_scl))
3333
#define SCL_READ() ((GPI & (1 << twi_scl)) != 0)
3434

3535
#ifndef FCPU80
3636
#define FCPU80 80000000L
3737
#endif
3838

3939
#if F_CPU == FCPU80
40-
#define TWI_CLOCK_STRETCH 200
40+
#define TWI_CLOCK_STRETCH 800
4141
#else
42-
#define TWI_CLOCK_STRETCH 400
42+
#define TWI_CLOCK_STRETCH 1600
4343
#endif
4444

4545
void twi_setClock(unsigned int freq){
@@ -99,7 +99,7 @@ static bool twi_write_stop(void){
9999
twi_delay(twi_dcount);
100100
SDA_HIGH();
101101
twi_delay(twi_dcount);
102-
102+
103103
return true;
104104
}
105105

@@ -166,7 +166,8 @@ unsigned char twi_readFrom(unsigned char address, unsigned char* buf, unsigned i
166166
unsigned int i;
167167
if(!twi_write_start()) return 4;//line busy
168168
if(!twi_write_byte(((address << 1) | 1) & 0xFF)) return 2;//received NACK on transmit of address
169-
for(i=0; i<len; i++) buf[i] = twi_read_byte(false);
169+
for(i=0; i<(len-1); i++) buf[i] = twi_read_byte(false);
170+
buf[len-1] = twi_read_byte(true);
170171
if(sendStop) twi_write_stop();
171172
i = 0;
172173
while(SDA_READ() == 0 && (i++) < 10){

cores/esp8266/core_esp8266_wiring_digital.c

-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
7777
}
7878

7979
extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
80-
val &= 0x01;
8180
if(pin < 16){
8281
if(val) GPOS = (1 << pin);
8382
else GPOC = (1 << pin);

cores/esp8266/pgmspace.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,17 @@ int printf_P(const char* formatP, ...) {
135135
return ret;
136136
}
137137

138+
int sprintf_P(char* str, const char* formatP, ...) {
139+
int ret;
140+
va_list arglist;
141+
va_start(arglist, formatP);
142+
143+
ret = vsnprintf_P(str, SIZE_IRRELEVANT, formatP, arglist);
144+
145+
va_end(arglist);
146+
return ret;
147+
}
148+
138149
int snprintf_P(char* str, size_t strSize, const char* formatP, ...) {
139150
int ret;
140151
va_list arglist;

cores/esp8266/pgmspace.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ size_t strnlen_P(const char *s, size_t size);
5050
#define strlen_P(strP) strnlen_P((strP), SIZE_IRRELEVANT)
5151

5252
int printf_P(const char *formatP, ...) __attribute__ ((format (printf, 1, 2)));
53-
int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__ ((format (printf, 3, 4)));
53+
int sprintf_P(char *str, const char *formatP, ...) __attribute__((format(printf, 2, 3)));
54+
int snprintf_P(char *str, size_t strSize, const char *formatP, ...) __attribute__((format(printf, 3, 4)));
5455
int vsnprintf_P(char *str, size_t strSize, const char *formatP, va_list ap) __attribute__ ((format (printf, 3, 0)));
5556

5657
// flash memory must be read using 32 bit aligned addresses else a processor
File renamed without changes.

libraries/ESP8266WiFi/examples/WiFiTelnetToSerial/WiFiTelnetToSerial.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
const char* ssid = "**********";
2626
const char* password = "**********";
2727

28-
WiFiServer server(21);
28+
WiFiServer server(23);
2929
WiFiClient serverClients[MAX_SRV_CLIENTS];
3030

3131
void setup() {
@@ -45,7 +45,7 @@ void setup() {
4545

4646
Serial1.print("Ready! Use 'telnet ");
4747
Serial1.print(WiFi.localIP());
48-
Serial1.println(" 21' to connect");
48+
Serial1.println(" 23' to connect");
4949
}
5050

5151
void loop() {

libraries/ESP8266WiFi/src/WiFiClient.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,17 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size)
177177
return _client->write(reinterpret_cast<const char*>(buf), size);
178178
}
179179

180-
extern "C" uint32_t esp_micros_at_task_start();
181-
182180
int WiFiClient::available()
183181
{
184-
static uint32_t lastPollTime = 0;
185-
if (!_client)
186-
return 0;
182+
int result = 0;
187183

188-
if (lastPollTime > esp_micros_at_task_start())
189-
yield();
190-
191-
lastPollTime = micros();
184+
if (_client) {
185+
result = _client->getSize();
186+
}
192187

193-
int result = _client->getSize();
188+
if (!result) {
189+
optimistic_yield();
190+
}
194191
return result;
195192
}
196193

libraries/ESP8266WiFi/src/WiFiServer.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,13 @@ bool WiFiServer::getNoDelay(){
8484
return tcp_nagle_disabled(_pcb);
8585
}
8686

87-
extern "C" uint32_t esp_micros_at_task_start();
88-
8987
bool WiFiServer::hasClient(){
9088
if (_unclaimed) return true;
9189
return false;
9290
}
9391

9492
WiFiClient WiFiServer::available(byte* status)
9593
{
96-
static uint32_t lastPollTime = 0;
97-
9894
if (_unclaimed)
9995
{
10096
WiFiClient result(_unclaimed);
@@ -103,9 +99,7 @@ WiFiClient WiFiServer::available(byte* status)
10399
return result;
104100
}
105101

106-
if (lastPollTime > esp_micros_at_task_start())
107-
yield();
108-
lastPollTime = micros();
102+
optimistic_yield();
109103

110104
return WiFiClient();
111105
}

libraries/ESP8266WiFi/src/WiFiUdp.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,17 @@ uint8_t WiFiUDP::beginMulticast(IPAddress interfaceAddr, IPAddress multicast, ui
116116
/* return number of bytes available in the current packet,
117117
will return zero if parsePacket hasn't been called yet */
118118
int WiFiUDP::available() {
119-
if (!_ctx)
120-
return 0;
121-
return static_cast<int>(_ctx->getSize());
119+
int result = 0;
120+
121+
if (_ctx) {
122+
result = static_cast<int>(_ctx->getSize());
123+
}
124+
125+
if (!result) {
126+
optimistic_yield();
127+
}
128+
129+
return result;
122130
}
123131

124132
/* Release any resources being used by this WiFiUDP instance */
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name=ESP8266httpUpdate
22
version=1.0
33
author=Markus Sattler
4-
maintainer=Markus Sattler
4+
maintainer=Markus Sattler
55
sentence=Http Update for ESP8266
66
paragraph=
77
url=https://github.com/Links2004/Arduino/tree/esp8266/hardware/esp8266com/esp8266/libraries/ESP8266httpUpdate
8-
architectures=ESP8266
8+
architectures=esp8266

libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
*/
2525

26-
#include "ESP8266HTTPUpdate.h"
26+
#include "ESP8266httpUpdate.h"
2727

2828
ESP8266HTTPUpdate::ESP8266HTTPUpdate(void) {
2929

libraries/Wire/Wire.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,13 @@ size_t TwoWire::write(const uint8_t *data, size_t quantity){
161161
}
162162

163163
int TwoWire::available(void){
164-
return rxBufferLength - rxBufferIndex;
164+
int result = rxBufferLength - rxBufferIndex;
165+
166+
if (!result) {
167+
optimistic_yield();
168+
}
169+
170+
return result;
165171
}
166172

167173
int TwoWire::read(void){

0 commit comments

Comments
 (0)