Skip to content

Commit 5533d14

Browse files
committed
Merge remote-tracking branch 'remotes/esp8266/esp8266' into esp8266
2 parents f945741 + 5ba3a59 commit 5533d14

File tree

9 files changed

+147
-35
lines changed

9 files changed

+147
-35
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ Before using I2C, pins for SDA and SCL need to be set by calling
108108
An initial SPI support for the HSPI interface (GPIO12-15) was implemented by [Sermus](https://github.com/Sermus).
109109
The implementation supports the entire Arduino SPI API including transactions, except setting phase and polarity as it's unclear how to set them in ESP8266 yet.
110110

111+
#### ESP-specific APIs ####
112+
113+
APIs related to deep sleep and watchdog timer are available in the ```ESP``` object.
114+
115+
```ESP.deepSleep(microseconds, mode)``` will put the chip into deep sleep. ```mode``` is one of ```WAKE_DEFAULT```, ```WAKE_RFCAL```, ```WAKE_NO_RFCAL```, ```WAKE_RF_DISABLED```.
116+
117+
```ESP.wdtEnable()```, ```ESP.wdtDisable()```, and ```ESP.wdtFeed()``` provide some control over the watchdog timer.
118+
111119
#### OneWire (from https://www.pjrc.com/teensy/td_libs_OneWire.html) ####
112120

113121
Library was adapted to work with ESP8266 by including register definitions into OneWire.h

hardware/esp8266com/esp8266/cores/esp8266/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ volatile uint32_t* portModeRegister(uint32_t port);
158158
#include "WString.h"
159159

160160
#include "HardwareSerial.h"
161+
#include "Esp.h"
161162

162163
uint16_t makeWord(uint16_t w);
163164
uint16_t makeWord(byte h, byte l);
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Esp.cpp - ESP8266-specific APIs
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "Arduino.h"
22+
23+
extern "C" {
24+
#include "user_interface.h"
25+
}
26+
27+
extern "C" void ets_wdt_enable (void);
28+
extern "C" void ets_wdt_disable (void);
29+
extern "C" void wdt_feed (void);
30+
31+
EspClass ESP;
32+
33+
EspClass::EspClass()
34+
{
35+
36+
}
37+
38+
void EspClass::wdtEnable(int)
39+
{
40+
ets_wdt_enable();
41+
}
42+
43+
void EspClass::wdtDisable()
44+
{
45+
ets_wdt_disable();
46+
}
47+
48+
void EspClass::wdtFeed()
49+
{
50+
wdt_feed();
51+
}
52+
53+
void EspClass::deepSleep(uint32_t time_us, WakeMode mode)
54+
{
55+
system_deep_sleep_set_option(static_cast<int>(mode));
56+
system_deep_sleep(time_us);
57+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Esp.h - ESP8266-specific APIs
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
This file is part of the esp8266 core for Arduino environment.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#ifndef ESP_H
22+
#define ESP_H
23+
24+
25+
enum WakeMode {
26+
WAKE_RF_DEFAULT = 0, // RF_CAL or not after deep-sleep wake up, depends on init data byte 108.
27+
WAKE_RFCAL = 1, // RF_CAL after deep-sleep wake up, there will be large current.
28+
WAKE_NO_RFCAL = 2, // no RF_CAL after deep-sleep wake up, there will only be small current.
29+
WAKE_RF_DISABLED = 4 // disable RF after deep-sleep wake up, just like modem sleep, there will be the smallest current.
30+
};
31+
32+
class EspClass {
33+
public:
34+
EspClass();
35+
36+
void wdtEnable(int timeout_ms = 0);
37+
// TODO: figure out how to set WDT timeout
38+
void wdtDisable();
39+
void wdtFeed();
40+
41+
void deepSleep(uint32_t time_us, WakeMode mode = WAKE_RF_DEFAULT);
42+
};
43+
44+
extern EspClass ESP;
45+
46+
#endif //ESP_H

hardware/esp8266com/esp8266/cores/esp8266/i2c.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ static inline void i2c_wait() {
6666
delayMicroseconds(s_i2c_delay);
6767
}
6868

69-
void i2c_freq(int freq_hz) {
69+
void ICACHE_FLASH_ATTR i2c_freq(int freq_hz) {
7070
s_i2c_delay = 1000000 / freq_hz / 4 - 1;
7171
if(s_i2c_delay < 0)
7272
s_i2c_delay = 0;
7373
}
7474

75-
void i2c_init(int sda_pin, int scl_pin) {
75+
void ICACHE_FLASH_ATTR i2c_init(int sda_pin, int scl_pin) {
7676
s_sda_pin = sda_pin;
7777
s_scl_pin = scl_pin;
7878
pinMode(ESP_PINS_OFFSET + sda_pin, OUTPUT_OPEN_DRAIN);
@@ -81,7 +81,7 @@ void i2c_init(int sda_pin, int scl_pin) {
8181
i2c_wait();
8282
}
8383

84-
void i2c_release() {
84+
void ICACHE_FLASH_ATTR i2c_release() {
8585
pinMode(ESP_PINS_OFFSET + s_sda_pin, INPUT);
8686
pinMode(ESP_PINS_OFFSET + s_scl_pin, INPUT);
8787
}
@@ -151,7 +151,7 @@ void i2c_write(uint8_t val) {
151151
i2c_set_sda(1);
152152
}
153153

154-
size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop) {
154+
size_t ICACHE_FLASH_ATTR i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendStop) {
155155
i2c_start();
156156
i2c_write(address << 1 | 1);
157157
int ack = i2c_get_ack();
@@ -171,7 +171,7 @@ size_t i2c_master_read_from(int address, uint8_t* data, size_t size, bool sendSt
171171
return size;
172172
}
173173

174-
size_t i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop) {
174+
size_t ICACHE_FLASH_ATTR i2c_master_write_to(int address, const uint8_t* data, size_t size, bool sendStop) {
175175
i2c_start();
176176
i2c_write(address << 1);
177177
int ack = i2c_get_ack();
@@ -193,11 +193,11 @@ void twi_init(void) {
193193
void twi_setAddress(uint8_t) {
194194
}
195195

196-
uint8_t twi_readFrom(uint8_t addr, uint8_t* data, uint8_t size, uint8_t sendStop) {
196+
uint8_t ICACHE_FLASH_ATTR twi_readFrom(uint8_t addr, uint8_t* data, uint8_t size, uint8_t sendStop) {
197197
return i2c_master_read_from(addr, data, size, sendStop);
198198
}
199199

200-
uint8_t twi_writeTo(uint8_t addr, uint8_t* data, uint8_t size, uint8_t wait, uint8_t sendStop) {
200+
uint8_t ICACHE_FLASH_ATTR twi_writeTo(uint8_t addr, uint8_t* data, uint8_t size, uint8_t wait, uint8_t sendStop) {
201201
return i2c_master_write_to(addr, data, size, sendStop);
202202
}
203203

hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ int strncmp(const char *s1, const char *s2, size_t len) {
111111
return ets_strncmp(s1, s2, len);
112112
}
113113

114-
char *strncpy(char * dest, const char * src, size_t n) {
114+
char* strncpy(char * dest, const char * src, size_t n) {
115115
return ets_strncpy(dest, src, n);
116116
}
117117

118-
char *ets_strstr(const char *haystack, const char *needle) {
119-
return strstr(haystack, needle);
118+
char* strstr(const char *haystack, const char *needle) {
119+
return ets_strstr(haystack, needle);
120120
}
121121

122-
char * strchr(const char * str, int character) {
122+
char* strchr(const char * str, int character) {
123123
while(1) {
124124
if(*str == 0x00) {
125125
return NULL;
@@ -144,11 +144,11 @@ char * strrchr(const char * str, int character) {
144144
}
145145
}
146146

147-
char * strcat(char * dest, const char * src) {
147+
char* ICACHE_FLASH_ATTR strcat(char * dest, const char * src) {
148148
return strncat(dest, src, strlen(src));
149149
}
150150

151-
char * strncat(char * dest, const char * src, size_t n) {
151+
char* ICACHE_FLASH_ATTR strncat(char * dest, const char * src, size_t n) {
152152
uint32_t offset = strlen(dest);
153153
for(uint32_t i = 0; i < n; i++) {
154154
*(dest + i + offset) = *(src + i);
@@ -159,7 +159,7 @@ char * strncat(char * dest, const char * src, size_t n) {
159159
return dest;
160160
}
161161

162-
char * strtok_r(char * str, const char * delimiters, char ** temp) {
162+
char* ICACHE_FLASH_ATTR strtok_r(char * str, const char * delimiters, char ** temp) {
163163
static char * ret = NULL;
164164
char * start = NULL;
165165
char * end = NULL;
@@ -213,7 +213,7 @@ int strcasecmp(const char * str1, const char * str2) {
213213
return d;
214214
}
215215

216-
char * strdup(const char *str) {
216+
char* ICACHE_FLASH_ATTR strdup(const char *str) {
217217
size_t len = strlen(str) + 1;
218218
char *cstr = malloc(len);
219219
if(cstr) {
@@ -441,7 +441,7 @@ int isblank(int c) {
441441

442442
static int errno_var = 0;
443443

444-
int * __errno(void) {
444+
int* ICACHE_FLASH_ATTR __errno(void) {
445445
os_printf("__errno is called last error: %d (not current)\n", errno_var);
446446
return &errno_var;
447447
}
@@ -450,67 +450,67 @@ int * __errno(void) {
450450
// __ieee754 functions
451451
// ##########################################################################
452452

453-
double __ieee754_sinh(double x) {
453+
double ICACHE_FLASH_ATTR __ieee754_sinh(double x) {
454454
return sinh(x);
455455
}
456456

457-
double __ieee754_hypot(double x, double y) {
457+
double ICACHE_FLASH_ATTR __ieee754_hypot(double x, double y) {
458458
return hypot(x, y);
459459
}
460460

461-
float __ieee754_hypotf(float x, float y) {
461+
float ICACHE_FLASH_ATTR __ieee754_hypotf(float x, float y) {
462462
return hypotf(x, y);
463463
}
464464

465-
float __ieee754_logf(float x) {
465+
float ICACHE_FLASH_ATTR __ieee754_logf(float x) {
466466
return logf(x);
467467
}
468468

469-
double __ieee754_log10(double x) {
469+
double ICACHE_FLASH_ATTR __ieee754_log10(double x) {
470470
return log10(x);
471471
}
472472

473-
double __ieee754_exp(double x) {
473+
double ICACHE_FLASH_ATTR __ieee754_exp(double x) {
474474
return exp(x);
475475
}
476476

477-
double __ieee754_cosh(double x) {
477+
double ICACHE_FLASH_ATTR __ieee754_cosh(double x) {
478478
return cosh(x);
479479
}
480480

481-
float __ieee754_expf(float x) {
481+
float ICACHE_FLASH_ATTR __ieee754_expf(float x) {
482482
return expf(x);
483483
}
484484

485-
float __ieee754_log10f(float x) {
485+
float ICACHE_FLASH_ATTR __ieee754_log10f(float x) {
486486
return log10f(x);
487487
}
488488

489-
double __ieee754_atan2(double x, double y) {
489+
double ICACHE_FLASH_ATTR __ieee754_atan2(double x, double y) {
490490
return atan2(x, y);
491491
}
492492

493-
float __ieee754_sqrtf(float x) {
493+
float ICACHE_FLASH_ATTR __ieee754_sqrtf(float x) {
494494
return sqrtf(x);
495495
}
496496

497-
float __ieee754_sinhf(float x) {
497+
float ICACHE_FLASH_ATTR __ieee754_sinhf(float x) {
498498
return sinhf(x);
499499
}
500500

501-
double __ieee754_log(double x) {
501+
double ICACHE_FLASH_ATTR __ieee754_log(double x) {
502502
return log(x);
503503
}
504504

505-
double __ieee754_sqrt(double x) {
505+
double ICACHE_FLASH_ATTR __ieee754_sqrt(double x) {
506506
return sqrt(x);
507507
}
508508

509-
float __ieee754_coshf(float x) {
509+
float ICACHE_FLASH_ATTR __ieee754_coshf(float x) {
510510
return coshf(x);
511511
}
512512

513-
float __ieee754_atan2f(float x, float y) {
513+
float ICACHE_FLASH_ATTR __ieee754_atan2f(float x, float y) {
514514
return atan2f(x, y);
515515
}
516516

hardware/esp8266com/esp8266/libraries/Adafruit_ILI9341/Adafruit_ILI9341.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern "C"{
55
#include <ets_sys.h>
66
#include <os_type.h>
77
#include <osapi.h>
8-
#include "driver\hspi.h"
8+
#include "driver/hspi.h"
99
}
1010

1111
#define SWAPBYTES(i) ((i>>8) | (i<<8))

hardware/esp8266com/esp8266/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern "C"
88
#include <c_types.h>
99
#include <osapi.h>
1010
#include <gpio.h>
11-
#include "driver\hspi.h"
11+
#include "driver/hspi.h"
1212
}
1313

1414
#define ILI9341_TFTWIDTH 240

hardware/esp8266com/esp8266/libraries/Adafruit_ILI9341/hspi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "driver\hspi.h"
1+
#include "driver/hspi.h"
22

33
/*
44
Pinout:

0 commit comments

Comments
 (0)