1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-22 21:23:07 +03:00

Merge pull request #5 from Links2004/esp8266

merging some changes
This commit is contained in:
ficeto 2015-05-01 16:06:18 +03:00
commit bc3d847c4c
7 changed files with 101 additions and 29 deletions

View File

@ -24,23 +24,55 @@ extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
#define kHz (1000L)
#define MHz (1000L*kHz)
#define GHz (1000L*MHz)
#define kBit (1024L)
#define MBit (1024L*kBit)
#define GBit (1024L*MBit)
#define kB (1024L)
#define MB (1024L*kB)
#define GB (1024L*MB)
//extern "C" void ets_wdt_init(uint32_t val); //extern "C" void ets_wdt_init(uint32_t val);
extern "C" void ets_wdt_enable(void); extern "C" void ets_wdt_enable(void);
extern "C" void ets_wdt_disable(void); extern "C" void ets_wdt_disable(void);
extern "C" void wdt_feed(void); extern "C" void wdt_feed(void);
/**
* User-defined Literals
* usage:
*
* uint32_t = test = 10_MHz; // --> 10000000
*/
unsigned long long operator"" _kHz(unsigned long long x) {
return x * 1000;
}
unsigned long long operator"" _MHz(unsigned long long x) {
return x * 1000 * 1000;
}
unsigned long long operator"" _GHz(unsigned long long x) {
return x * 1000 * 1000 * 1000;
}
unsigned long long operator"" _kBit(unsigned long long x) {
return x * 1024;
}
unsigned long long operator"" _MBit(unsigned long long x) {
return x * 1024 * 1024;
}
unsigned long long operator"" _GBit(unsigned long long x) {
return x * 1024 * 1024 * 1024;
}
unsigned long long operator"" _kB(unsigned long long x) {
return x * 1024;
}
unsigned long long operator"" _MB(unsigned long long x) {
return x * 1024 * 1024;
}
unsigned long long operator"" _GB(unsigned long long x) {
return x * 1024 * 1024 * 1024;
}
EspClass ESP; EspClass ESP;
EspClass::EspClass() EspClass::EspClass()
@ -134,15 +166,15 @@ uint32_t EspClass::getFlashChipSize(void)
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
switch((bytes[3] & 0xf0) >> 4) { switch((bytes[3] & 0xf0) >> 4) {
case 0x0: // 4 Mbit (512KB) case 0x0: // 4 Mbit (512KB)
return (512 * kB); return (512_kB);
case 0x1: // 2 MBit (256KB) case 0x1: // 2 MBit (256KB)
return (256 * kB); return (256_kB);
case 0x2: // 8 MBit (1MB) case 0x2: // 8 MBit (1MB)
return (1 * MB); return (1_MB);
case 0x3: // 16 MBit (2MB) case 0x3: // 16 MBit (2MB)
return (2 * MB); return (2_MB);
case 0x4: // 32 MBit (4MB) case 0x4: // 32 MBit (4MB)
return (4 * MB); return (4_MB);
default: // fail? default: // fail?
return 0; return 0;
} }
@ -158,13 +190,13 @@ uint32_t EspClass::getFlashChipSpeed(void)
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) { if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
switch(bytes[3] & 0x0F) { switch(bytes[3] & 0x0F) {
case 0x0: // 40 MHz case 0x0: // 40 MHz
return (40 * MHz); return (40_MHz);
case 0x1: // 26 MHz case 0x1: // 26 MHz
return (26 * MHz); return (26_MHz);
case 0x2: // 20 MHz case 0x2: // 20 MHz
return (20 * MHz); return (20_MHz);
case 0xf: // 80 MHz case 0xf: // 80 MHz
return (80 * MHz); return (80_MHz);
default: // fail? default: // fail?
return 0; return 0;
} }
@ -186,3 +218,32 @@ FlashMode_t EspClass::getFlashChipMode(void)
} }
return mode; return mode;
} }
/**
* Infos from
* http://www.wlxmall.com/images/stock_item/att/A1010004.pdf
* http://www.gigadevice.com/product-series/5.html?locale=en_US
*/
uint32_t EspClass::getFlashChipSizeByChipId(void) {
uint32_t chipId = getFlashChipId();
switch(chipId) {
case 0x1740C8: // GD25Q64B
return (8_MB);
case 0x1640C8: // GD25Q32B
return (4_MB);
case 0x1540C8: // GD25Q16B
return (2_MB);
case 0x1440C8: // GD25Q80
return (1_MB);
case 0x1340C8: // GD25Q40
return (512_kB);
case 0x1240C8: // GD25Q20
return (256_kB);
case 0x1140C8: // GD25Q10
return (128_kB);
case 0x1040C8: // GD25Q12
return (64_kB);
default:
return 0;
}
}

View File

@ -90,6 +90,7 @@ class EspClass {
uint32_t getFlashChipSize(void); uint32_t getFlashChipSize(void);
uint32_t getFlashChipSpeed(void); uint32_t getFlashChipSpeed(void);
FlashMode_t getFlashChipMode(void); FlashMode_t getFlashChipMode(void);
uint32_t getFlashChipSizeByChipId(void);
}; };

View File

@ -510,6 +510,9 @@ void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) {
} }
void ICACHE_FLASH_ATTR HardwareSerial::end() { void ICACHE_FLASH_ATTR HardwareSerial::end() {
if(uart_get_debug() == _uart_nr) {
uart_set_debug(UART_NO);
}
uart_uninit(_uart); uart_uninit(_uart);
delete _rx_buffer; delete _rx_buffer;
delete _tx_buffer; delete _tx_buffer;

View File

@ -48,7 +48,7 @@ extern void setup();
void preloop_update_frequency() __attribute__((weak)); void preloop_update_frequency() __attribute__((weak));
void preloop_update_frequency() { void preloop_update_frequency() {
#if defined(F_CPU) && (F_CPU == 16000000L) #if defined(F_CPU) && (F_CPU == 160000000L)
REG_SET_BIT(0x3ff00014, BIT(0)); REG_SET_BIT(0x3ff00014, BIT(0));
ets_update_cpu_frequency(160); ets_update_cpu_frequency(160);
#endif #endif

View File

@ -59,12 +59,16 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
GPC(pin) = (GPC(pin) & (0xF << GPCI)); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED) GPC(pin) = (GPC(pin) & (0xF << GPCI)); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
GPES = (1 << pin); //Enable GPES = (1 << pin); //Enable
} else if(mode == INPUT || mode == INPUT_PULLUP){ } else if(mode == INPUT || mode == INPUT_PULLUP || mode == INPUT_PULLDOWN){
GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO
GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED) GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
GPEC = (1 << pin); //Disable GPEC = (1 << pin); //Disable
if(mode == INPUT_PULLUP){ if(mode == INPUT_PULLUP) {
GPF(pin) |= (1 << GPFPU);//Enable Pullup GPF(pin) &= ~(1 << GPFPD); // Disable Pulldown
GPF(pin) |= (1 << GPFPU); // Enable Pullup
} else if(mode == INPUT_PULLDOWN) {
GPF(pin) &= ~(1 << GPFPU); // Disable Pullup
GPF(pin) |= (1 << GPFPD); // Enable Pulldown
} }
} }
} else if(pin == 16){ } else if(pin == 16){
@ -81,7 +85,7 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
} }
} }
extern void __digitalWrite(uint8_t pin, uint8_t val) { extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
val &= 0x01; val &= 0x01;
if(pin < 16){ if(pin < 16){
if(val) GPOS = (1 << pin); if(val) GPOS = (1 << pin);
@ -92,12 +96,13 @@ extern void __digitalWrite(uint8_t pin, uint8_t val) {
} }
} }
extern int __digitalRead(uint8_t pin) { extern int ICACHE_RAM_ATTR __digitalRead(uint8_t pin) {
if(pin < 16){ if(pin < 16){
return GPIP(pin); return GPIP(pin);
} else if(pin == 16){ } else if(pin == 16){
return GP16I & 0x01; return GP16I & 0x01;
} }
return 0;
} }
/* /*

View File

@ -93,9 +93,11 @@ static uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C,
//GPIO (0-15) PIN Function Bits //GPIO (0-15) PIN Function Bits
#define GPFSOE 0 //Sleep OE #define GPFSOE 0 //Sleep OE
#define GPFSS 1 //Sleep Sel #define GPFSS 1 //Sleep Sel
#define GPFSPD 2 //Sleep Pulldown
#define GPFSPU 3 //Sleep Pullup #define GPFSPU 3 //Sleep Pullup
#define GPFFS0 4 //Function Select bit 0 #define GPFFS0 4 //Function Select bit 0
#define GPFFS1 5 //Function Select bit 1 #define GPFFS1 5 //Function Select bit 1
#define GPFPD 6 //Pulldown
#define GPFPU 7 //Pullup #define GPFPU 7 //Pullup
#define GPFFS2 8 //Function Select bit 2 #define GPFFS2 8 //Function Select bit 2
#define GPFFS(f) (((((f) & 4) != 0) << GPFFS2) | ((((f) & 2) != 0) << GPFFS1) | ((((f) & 1) != 0) << GPFFS0)) #define GPFFS(f) (((((f) & 4) != 0) << GPFFS2) | ((((f) & 2) != 0) << GPFFS1) | ((((f) & 1) != 0) << GPFFS0))

View File

@ -23,7 +23,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD
compiler.c.elf.ldscript=eagle.app.v6.ld compiler.c.elf.ldscript=eagle.app.v6.ld
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}" 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}"
compiler.c.elf.cmd=xtensa-lx106-elf-gcc compiler.c.elf.cmd=xtensa-lx106-elf-gcc
compiler.c.elf.libs=-lc -lm -lg -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig compiler.c.elf.libs=-lm -lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp -lsmartconfig
compiler.cpp.cmd=xtensa-lx106-elf-g++ compiler.cpp.cmd=xtensa-lx106-elf-g++
compiler.cpp.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD compiler.cpp.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD