Skip to content

Commit bc3d847

Browse files
author
ficeto
committed
Merge pull request #5 from Links2004/esp8266
merging some changes
2 parents c94128c + a250492 commit bc3d847

File tree

7 files changed

+101
-29
lines changed

7 files changed

+101
-29
lines changed

cores/esp8266/Esp.cpp

+82-21
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,55 @@ extern "C" {
2424
#include "user_interface.h"
2525
}
2626

27-
#define kHz (1000L)
28-
#define MHz (1000L*kHz)
29-
#define GHz (1000L*MHz)
30-
31-
#define kBit (1024L)
32-
#define MBit (1024L*kBit)
33-
#define GBit (1024L*MBit)
34-
35-
#define kB (1024L)
36-
#define MB (1024L*kB)
37-
#define GB (1024L*MB)
38-
3927
//extern "C" void ets_wdt_init(uint32_t val);
4028
extern "C" void ets_wdt_enable(void);
4129
extern "C" void ets_wdt_disable(void);
4230
extern "C" void wdt_feed(void);
4331

32+
/**
33+
* User-defined Literals
34+
* usage:
35+
*
36+
* uint32_t = test = 10_MHz; // --> 10000000
37+
*/
38+
39+
unsigned long long operator"" _kHz(unsigned long long x) {
40+
return x * 1000;
41+
}
42+
43+
unsigned long long operator"" _MHz(unsigned long long x) {
44+
return x * 1000 * 1000;
45+
}
46+
47+
unsigned long long operator"" _GHz(unsigned long long x) {
48+
return x * 1000 * 1000 * 1000;
49+
}
50+
51+
unsigned long long operator"" _kBit(unsigned long long x) {
52+
return x * 1024;
53+
}
54+
55+
unsigned long long operator"" _MBit(unsigned long long x) {
56+
return x * 1024 * 1024;
57+
}
58+
59+
unsigned long long operator"" _GBit(unsigned long long x) {
60+
return x * 1024 * 1024 * 1024;
61+
}
62+
63+
unsigned long long operator"" _kB(unsigned long long x) {
64+
return x * 1024;
65+
}
66+
67+
unsigned long long operator"" _MB(unsigned long long x) {
68+
return x * 1024 * 1024;
69+
}
70+
71+
unsigned long long operator"" _GB(unsigned long long x) {
72+
return x * 1024 * 1024 * 1024;
73+
}
74+
75+
4476
EspClass ESP;
4577

4678
EspClass::EspClass()
@@ -134,15 +166,15 @@ uint32_t EspClass::getFlashChipSize(void)
134166
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
135167
switch((bytes[3] & 0xf0) >> 4) {
136168
case 0x0: // 4 Mbit (512KB)
137-
return (512 * kB);
169+
return (512_kB);
138170
case 0x1: // 2 MBit (256KB)
139-
return (256 * kB);
171+
return (256_kB);
140172
case 0x2: // 8 MBit (1MB)
141-
return (1 * MB);
173+
return (1_MB);
142174
case 0x3: // 16 MBit (2MB)
143-
return (2 * MB);
175+
return (2_MB);
144176
case 0x4: // 32 MBit (4MB)
145-
return (4 * MB);
177+
return (4_MB);
146178
default: // fail?
147179
return 0;
148180
}
@@ -158,13 +190,13 @@ uint32_t EspClass::getFlashChipSpeed(void)
158190
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
159191
switch(bytes[3] & 0x0F) {
160192
case 0x0: // 40 MHz
161-
return (40 * MHz);
193+
return (40_MHz);
162194
case 0x1: // 26 MHz
163-
return (26 * MHz);
195+
return (26_MHz);
164196
case 0x2: // 20 MHz
165-
return (20 * MHz);
197+
return (20_MHz);
166198
case 0xf: // 80 MHz
167-
return (80 * MHz);
199+
return (80_MHz);
168200
default: // fail?
169201
return 0;
170202
}
@@ -186,3 +218,32 @@ FlashMode_t EspClass::getFlashChipMode(void)
186218
}
187219
return mode;
188220
}
221+
222+
/**
223+
* Infos from
224+
* http://www.wlxmall.com/images/stock_item/att/A1010004.pdf
225+
* http://www.gigadevice.com/product-series/5.html?locale=en_US
226+
*/
227+
uint32_t EspClass::getFlashChipSizeByChipId(void) {
228+
uint32_t chipId = getFlashChipId();
229+
switch(chipId) {
230+
case 0x1740C8: // GD25Q64B
231+
return (8_MB);
232+
case 0x1640C8: // GD25Q32B
233+
return (4_MB);
234+
case 0x1540C8: // GD25Q16B
235+
return (2_MB);
236+
case 0x1440C8: // GD25Q80
237+
return (1_MB);
238+
case 0x1340C8: // GD25Q40
239+
return (512_kB);
240+
case 0x1240C8: // GD25Q20
241+
return (256_kB);
242+
case 0x1140C8: // GD25Q10
243+
return (128_kB);
244+
case 0x1040C8: // GD25Q12
245+
return (64_kB);
246+
default:
247+
return 0;
248+
}
249+
}

cores/esp8266/Esp.h

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class EspClass {
9090
uint32_t getFlashChipSize(void);
9191
uint32_t getFlashChipSpeed(void);
9292
FlashMode_t getFlashChipMode(void);
93+
uint32_t getFlashChipSizeByChipId(void);
9394

9495
};
9596

cores/esp8266/HardwareSerial.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,9 @@ void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) {
510510
}
511511

512512
void ICACHE_FLASH_ATTR HardwareSerial::end() {
513+
if(uart_get_debug() == _uart_nr) {
514+
uart_set_debug(UART_NO);
515+
}
513516
uart_uninit(_uart);
514517
delete _rx_buffer;
515518
delete _tx_buffer;

cores/esp8266/core_esp8266_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern void setup();
4848

4949
void preloop_update_frequency() __attribute__((weak));
5050
void preloop_update_frequency() {
51-
#if defined(F_CPU) && (F_CPU == 16000000L)
51+
#if defined(F_CPU) && (F_CPU == 160000000L)
5252
REG_SET_BIT(0x3ff00014, BIT(0));
5353
ets_update_cpu_frequency(160);
5454
#endif

cores/esp8266/core_esp8266_wiring_digital.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
5959
GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
6060
GPC(pin) = (GPC(pin) & (0xF << GPCI)); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
6161
GPES = (1 << pin); //Enable
62-
} else if(mode == INPUT || mode == INPUT_PULLUP){
62+
} else if(mode == INPUT || mode == INPUT_PULLUP || mode == INPUT_PULLDOWN){
6363
GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
6464
GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
6565
GPEC = (1 << pin); //Disable
66-
if(mode == INPUT_PULLUP){
67-
GPF(pin) |= (1 << GPFPU);//Enable Pullup
68-
}
66+
if(mode == INPUT_PULLUP) {
67+
GPF(pin) &= ~(1 << GPFPD); // Disable Pulldown
68+
GPF(pin) |= (1 << GPFPU); // Enable Pullup
69+
} else if(mode == INPUT_PULLDOWN) {
70+
GPF(pin) &= ~(1 << GPFPU); // Disable Pullup
71+
GPF(pin) |= (1 << GPFPD); // Enable Pulldown
72+
}
6973
}
7074
} else if(pin == 16){
7175
GPF16 = GP16FFS(GPFFS_GPIO(pin));//Set mode to GPIO
@@ -81,7 +85,7 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
8185
}
8286
}
8387

84-
extern void __digitalWrite(uint8_t pin, uint8_t val) {
88+
extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
8589
val &= 0x01;
8690
if(pin < 16){
8791
if(val) GPOS = (1 << pin);
@@ -92,12 +96,13 @@ extern void __digitalWrite(uint8_t pin, uint8_t val) {
9296
}
9397
}
9498

95-
extern int __digitalRead(uint8_t pin) {
99+
extern int ICACHE_RAM_ATTR __digitalRead(uint8_t pin) {
96100
if(pin < 16){
97101
return GPIP(pin);
98102
} else if(pin == 16){
99103
return GP16I & 0x01;
100104
}
105+
return 0;
101106
}
102107

103108
/*

cores/esp8266/esp8266_peri.h

+2
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ static uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C,
9393
//GPIO (0-15) PIN Function Bits
9494
#define GPFSOE 0 //Sleep OE
9595
#define GPFSS 1 //Sleep Sel
96+
#define GPFSPD 2 //Sleep Pulldown
9697
#define GPFSPU 3 //Sleep Pullup
9798
#define GPFFS0 4 //Function Select bit 0
9899
#define GPFFS1 5 //Function Select bit 1
100+
#define GPFPD 6 //Pulldown
99101
#define GPFPU 7 //Pullup
100102
#define GPFFS2 8 //Function Select bit 2
101103
#define GPFFS(f) (((((f) & 4) != 0) << GPFFS2) | ((((f) & 2) != 0) << GPFFS1) | ((((f) & 1) != 0) << GPFFS0))

platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD
2323
compiler.c.elf.ldscript=eagle.app.v6.ld
2424
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}"
2525
compiler.c.elf.cmd=xtensa-lx106-elf-gcc
26-
compiler.c.elf.libs=-lc -lm -lg -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig
26+
compiler.c.elf.libs=-lm -lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig
2727

2828
compiler.cpp.cmd=xtensa-lx106-elf-g++
2929
compiler.cpp.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD

0 commit comments

Comments
 (0)