Skip to content

Commit d641b3f

Browse files
committed
Merge pull request #4 from esp8266/esp8266
pull master
2 parents 53c8d87 + c363b2d commit d641b3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2390
-594
lines changed

Diff for: .travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ script:
2424
- which arduino
2525
- source hardware/esp8266com/esp8266/tests/common.sh
2626
- arduino --board esp8266com:esp8266:generic --save-prefs
27+
- arduino --get-pref sketchbook.path
28+
- install_libraries
2729
- build_sketches arduino $PWD/hardware/esp8266com/esp8266
2830

2931
notifications:

Diff for: boards.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ nodemcu.name=NodeMCU 0.9 (ESP-12 Module)
181181

182182
nodemcu.upload.tool=esptool
183183
nodemcu.upload.speed=115200
184-
nodemcu.upload.resetmethod=ck
184+
nodemcu.upload.resetmethod=nodemcu
185185
nodemcu.upload.maximum_size=1044464
186186
nodemcu.upload.maximum_data_size=81920
187187
nodemcu.upload.wait_for_upload_port=true

Diff for: cores/esp8266/Arduino.h

+27-15
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,29 @@ void timer0_detachInterrupt(void);
137137
void ets_intr_lock();
138138
void ets_intr_unlock();
139139

140-
// level (0-15),
141-
// level 15 will disable ALL interrupts,
142-
// level 0 will disable most software interrupts
140+
#ifndef __STRINGIFY
141+
#define __STRINGIFY(a) #a
142+
#endif
143+
144+
// these low level routines provide a replacement for SREG interrupt save that AVR uses
145+
// but are esp8266 specific. A normal use pattern is like
143146
//
144-
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state))
145-
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
147+
//{
148+
// uint32_t savedPS = xt_rsil(1); // this routine will allow level 2 and above
149+
// // do work here
150+
// xt_wsr_ps(savedPS); // restore the state
151+
//}
152+
//
153+
// level (0-15), interrupts of the given level and above will be active
154+
// level 15 will disable ALL interrupts,
155+
// level 0 will enable ALL interrupts,
156+
//
157+
#define xt_rsil(level) (__extension__({uint32_t state; __asm__ __volatile__("rsil %0," __STRINGIFY(level) : "=a" (state)); state;}))
158+
#define xt_wsr_ps(state) __asm__ __volatile__("wsr %0,ps; isync" :: "a" (state) : "memory")
146159

147-
extern uint32_t interruptsState;
160+
#define interrupts() xt_rsil(0)
161+
#define noInterrupts() xt_rsil(15)
148162

149-
#define interrupts() xt_enable_interrupts(interruptsState)
150-
#define noInterrupts() __asm__ __volatile__("rsil %0,15" : "=a" (interruptsState))
151163

152164
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
153165
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
@@ -179,12 +191,12 @@ void initVariant(void);
179191

180192
int atexit(void (*func)()) __attribute__((weak));
181193

182-
void pinMode(uint8_t, uint8_t);
183-
void digitalWrite(uint8_t, uint8_t);
184-
int digitalRead(uint8_t);
185-
int analogRead(uint8_t);
194+
void pinMode(uint8_t pin, uint8_t mode);
195+
void digitalWrite(uint8_t pin, uint8_t val);
196+
int digitalRead(uint8_t pin);
197+
int analogRead(uint8_t pin);
186198
void analogReference(uint8_t mode);
187-
void analogWrite(uint8_t, int);
199+
void analogWrite(uint8_t pin, int val);
188200
void analogWriteFreq(uint32_t freq);
189201
void analogWriteRange(uint32_t range);
190202

@@ -198,8 +210,8 @@ unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
198210
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
199211
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
200212

201-
void attachInterrupt(uint8_t, void (*)(void), int mode);
202-
void detachInterrupt(uint8_t);
213+
void attachInterrupt(uint8_t pin, void (*)(void), int mode);
214+
void detachInterrupt(uint8_t pin);
203215

204216
void setup(void);
205217
void loop(void);

Diff for: cores/esp8266/Esp.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/*
1+
/*
22
Esp.cpp - ESP8266-specific APIs
33
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
44
This file is part of the esp8266 core for Arduino environment.
5-
5+
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
88
License as published by the Free Software Foundation; either
@@ -22,6 +22,7 @@
2222
#include "flash_utils.h"
2323
#include "eboot_command.h"
2424
#include <memory>
25+
#include "interrupts.h"
2526

2627
extern "C" {
2728
#include "user_interface.h"
@@ -32,7 +33,7 @@ extern struct rst_info resetInfo;
3233

3334
//#define DEBUG_SERIAL Serial
3435

35-
36+
3637
/**
3738
* User-defined Literals
3839
* usage:
@@ -92,23 +93,25 @@ void EspClass::wdtEnable(WDTO_t timeout_ms)
9293

9394
void EspClass::wdtDisable(void)
9495
{
95-
/// Please dont stop software watchdog too long (less than 6 seconds),
96+
/// Please don't stop software watchdog too long (less than 6 seconds),
9697
/// otherwise it will trigger hardware watchdog reset.
9798
system_soft_wdt_stop();
9899
}
99100

100101
void EspClass::wdtFeed(void)
101102
{
102-
103+
system_soft_wdt_feed();
103104
}
104105

106+
extern "C" void esp_yield();
107+
105108
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
106109
{
107-
system_deep_sleep_set_option(static_cast<int>(mode));
108-
system_deep_sleep(time_us);
110+
system_deep_sleep_set_option(static_cast<int>(mode));
111+
system_deep_sleep(time_us);
112+
esp_yield();
109113
}
110114

111-
extern "C" void esp_yield();
112115
extern "C" void __real_system_restart_local();
113116
void EspClass::reset(void)
114117
{
@@ -119,13 +122,11 @@ void EspClass::restart(void)
119122
{
120123
system_restart();
121124
esp_yield();
122-
// todo: provide an alternative code path if this was called
123-
// from system context, not from continuation
124-
// (implement esp_is_cont_ctx()?)
125125
}
126126

127127
uint16_t EspClass::getVcc(void)
128128
{
129+
InterruptLock lock;
129130
return system_get_vdd33();
130131
}
131132

@@ -333,7 +334,7 @@ uint32_t EspClass::getSketchSize() {
333334
DEBUG_SERIAL.printf("num_segments=%u\r\n", image_header.num_segments);
334335
#endif
335336
for (uint32_t section_index = 0;
336-
section_index < image_header.num_segments;
337+
section_index < image_header.num_segments;
337338
++section_index)
338339
{
339340
section_header_t section_header = {0};
@@ -395,8 +396,7 @@ bool EspClass::updateSketch(Stream& in, uint32_t size, bool restartOnFail, bool
395396

396397
#ifdef DEBUG_SERIAL
397398
DEBUG_SERIAL.println("Update SUCCESS");
398-
#endif
399+
#endif
399400
if(restartOnSuccess) ESP.restart();
400401
return true;
401402
}
402-

Diff for: cores/esp8266/Esp.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/*
1+
/*
22
Esp.h - ESP8266-specific APIs
33
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
44
This file is part of the esp8266 core for Arduino environment.
5-
5+
66
This library is free software; you can redistribute it and/or
77
modify it under the terms of the GNU Lesser General Public
88
License as published by the Free Software Foundation; either
@@ -20,6 +20,9 @@
2020

2121
#ifndef ESP_H
2222
#define ESP_H
23+
24+
#include <Arduino.h>
25+
2326
/**
2427
* AVR macros for WDT managment
2528
*/

Diff for: cores/esp8266/FS.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include "FS.h"
2222
#include "FSImpl.h"
2323

24+
using namespace fs;
25+
2426
static bool sflags(const char* mode, OpenMode& om, AccessMode& am);
2527

2628
size_t File::write(uint8_t c) {
@@ -41,7 +43,7 @@ int File::available() {
4143
if (!_p)
4244
return false;
4345

44-
return _p->position() < _p->size();
46+
return _p->size() - _p->position();
4547
}
4648

4749
int File::read() {
@@ -112,6 +114,13 @@ File::operator bool() const {
112114
return !!_p;
113115
}
114116

117+
const char* File::name() const {
118+
if (!_p)
119+
return nullptr;
120+
121+
return _p->name();
122+
}
123+
115124
File Dir::openFile(const char* mode) {
116125
if (!_impl) {
117126
return File();
@@ -135,6 +144,14 @@ String Dir::fileName() {
135144
return _impl->fileName();
136145
}
137146

147+
size_t Dir::fileSize() {
148+
if (!_impl) {
149+
return 0;
150+
}
151+
152+
return _impl->fileSize();
153+
}
154+
138155
bool Dir::next() {
139156
if (!_impl) {
140157
return false;

Diff for: cores/esp8266/FS.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <Arduino.h>
2525
#include <memory>
2626

27+
namespace fs {
28+
2729
class File;
2830
class Dir;
2931

@@ -64,6 +66,7 @@ class File : public Stream
6466
size_t size() const;
6567
void close();
6668
operator bool() const;
69+
const char* name() const;
6770

6871
protected:
6972
FileImplPtr _p;
@@ -75,6 +78,7 @@ class Dir {
7578

7679
File openFile(const char* mode);
7780
String fileName();
81+
size_t fileSize();
7882
bool next();
7983

8084
protected:
@@ -102,9 +106,18 @@ class FS
102106

103107
protected:
104108
FSImplPtr _impl;
105-
106109
};
107110

111+
} // namespace fs
112+
113+
using fs::FS;
114+
using fs::File;
115+
using fs::Dir;
116+
using fs::SeekMode;
117+
using fs::SeekSet;
118+
using fs::SeekCur;
119+
using fs::SeekEnd;
120+
108121
extern FS SPIFFS;
109122

110123
#endif //FS_H

Diff for: cores/esp8266/FSImpl.h

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <stddef.h>
2424
#include <stdint.h>
2525

26+
namespace fs {
27+
2628
class FileImpl {
2729
public:
2830
virtual ~FileImpl() { }
@@ -33,6 +35,7 @@ class FileImpl {
3335
virtual size_t position() const = 0;
3436
virtual size_t size() const = 0;
3537
virtual void close() = 0;
38+
virtual const char* name() const = 0;
3639
};
3740

3841
enum OpenMode {
@@ -53,6 +56,7 @@ class DirImpl {
5356
virtual ~DirImpl() { }
5457
virtual FileImplPtr openFile(OpenMode openMode, AccessMode accessMode) = 0;
5558
virtual const char* fileName() = 0;
59+
virtual size_t fileSize() = 0;
5660
virtual bool next() = 0;
5761
};
5862

@@ -66,5 +70,6 @@ class FSImpl {
6670

6771
};
6872

73+
} // namespace fs
6974

7075
#endif //FSIMPL_H

Diff for: cores/esp8266/Tone.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
#include "Arduino.h"
3636
#include "pins_arduino.h"
3737

38+
/*
3839
static int8_t toneBegin(uint8_t _pin) {
3940
//TODO implement tone
4041
return 0;
4142
}
43+
*/
4244

4345
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) {
4446
//TODO implement tone

Diff for: cores/esp8266/Updater.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ class UpdaterClass {
108108
void _reset();
109109
bool _writeBuffer();
110110

111+
uint8_t _error;
111112
uint8_t *_buffer;
112113
size_t _bufferLen;
113114
size_t _size;
114115
uint32_t _startAddress;
115116
uint32_t _currentAddress;
116-
uint8_t _error;
117117
};
118118

119119
extern UpdaterClass Update;

Diff for: cores/esp8266/cbuf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class cbuf {
7070
size_t bytes_available = getSize();
7171
size_t size_to_read = (size < bytes_available) ? size : bytes_available;
7272
size_t size_read = size_to_read;
73-
if(_end < _begin && size_to_read > _bufend - _begin) {
73+
if(_end < _begin && size_to_read > (size_t)(_bufend - _begin)) {
7474
size_t top_size = _bufend - _begin;
7575
memcpy(dst, _begin, top_size);
7676
_begin = _buf;
@@ -95,7 +95,7 @@ class cbuf {
9595
size_t bytes_available = room();
9696
size_t size_to_write = (size < bytes_available) ? size : bytes_available;
9797
size_t size_written = size_to_write;
98-
if(_end > _begin && size_to_write > _bufend - _end) {
98+
if(_end > _begin && size_to_write > (size_t)(_bufend - _end)) {
9999
size_t top_size = _bufend - _end;
100100
memcpy(_end, src, top_size);
101101
_end = _buf;

Diff for: cores/esp8266/core_esp8266_main.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ extern "C" void abort() {
7474
}
7575

7676
extern "C" void esp_yield() {
77-
cont_yield(&g_cont);
77+
if (cont_can_yield(&g_cont)) {
78+
cont_yield(&g_cont);
79+
}
7880
}
7981

8082
extern "C" void esp_schedule() {

0 commit comments

Comments
 (0)