Skip to content

add the LED to the server example #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 82 additions & 21 deletions hardware/esp8266com/esp8266/cores/esp8266/Esp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,55 @@ extern "C" {
#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_enable(void);
extern "C" void ets_wdt_disable(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::EspClass()
Expand Down Expand Up @@ -134,15 +166,15 @@ uint32_t EspClass::getFlashChipSize(void)
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
switch((bytes[3] & 0xf0) >> 4) {
case 0x0: // 4 Mbit (512KB)
return (512 * kB);
return (512_kB);
case 0x1: // 2 MBit (256KB)
return (256 * kB);
return (256_kB);
case 0x2: // 8 MBit (1MB)
return (1 * MB);
return (1_MB);
case 0x3: // 16 MBit (2MB)
return (2 * MB);
return (2_MB);
case 0x4: // 32 MBit (4MB)
return (4 * MB);
return (4_MB);
default: // fail?
return 0;
}
Expand All @@ -158,13 +190,13 @@ uint32_t EspClass::getFlashChipSpeed(void)
if(spi_flash_read(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
switch(bytes[3] & 0x0F) {
case 0x0: // 40 MHz
return (40 * MHz);
return (40_MHz);
case 0x1: // 26 MHz
return (26 * MHz);
return (26_MHz);
case 0x2: // 20 MHz
return (20 * MHz);
return (20_MHz);
case 0xf: // 80 MHz
return (80 * MHz);
return (80_MHz);
default: // fail?
return 0;
}
Expand All @@ -186,3 +218,32 @@ FlashMode_t EspClass::getFlashChipMode(void)
}
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;
}
}
1 change: 1 addition & 0 deletions hardware/esp8266com/esp8266/cores/esp8266/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class EspClass {
uint32_t getFlashChipSize(void);
uint32_t getFlashChipSpeed(void);
FlashMode_t getFlashChipMode(void);
uint32_t getFlashChipSizeByChipId(void);

};

Expand Down
3 changes: 3 additions & 0 deletions hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ void ICACHE_FLASH_ATTR HardwareSerial::begin(unsigned long baud, byte config) {
}

void ICACHE_FLASH_ATTR HardwareSerial::end() {
if(uart_get_debug() == _uart_nr) {
uart_set_debug(UART_NO);
}
uart_uninit(_uart);
delete _rx_buffer;
delete _tx_buffer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern void setup();

void preloop_update_frequency() __attribute__((weak));
void preloop_update_frequency() {
#if defined(F_CPU) && (F_CPU == 16000000L)
#if defined(F_CPU) && (F_CPU == 160000000L)
REG_SET_BIT(0x3ff00014, BIT(0));
ets_update_cpu_frequency(160);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
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)
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
GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
GPEC = (1 << pin); //Disable
if(mode == INPUT_PULLUP){
GPF(pin) |= (1 << GPFPU);//Enable Pullup
}
if(mode == INPUT_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){
GPF16 = GP16FFS(GPFFS_GPIO(pin));//Set mode to GPIO
Expand All @@ -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;
if(pin < 16){
if(val) GPOS = (1 << pin);
Expand All @@ -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){
return GPIP(pin);
} else if(pin == 16){
return GP16I & 0x01;
}
return 0;
}

/*
Expand Down Expand Up @@ -154,6 +159,11 @@ extern void __detachInterrupt(uint8_t pin) {
}

void initPins() {
//Disable UART interrupts
system_set_os_print(0);
U0IE = 0;
U1IE = 0;

for (int i = 0; i <= 5; ++i) {
pinMode(i, INPUT);
}
Expand Down
2 changes: 2 additions & 0 deletions hardware/esp8266com/esp8266/cores/esp8266/esp8266_peri.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ static uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C,
//GPIO (0-15) PIN Function Bits
#define GPFSOE 0 //Sleep OE
#define GPFSS 1 //Sleep Sel
#define GPFSPD 2 //Sleep Pulldown
#define GPFSPU 3 //Sleep Pullup
#define GPFFS0 4 //Function Select bit 0
#define GPFFS1 5 //Function Select bit 1
#define GPFPD 6 //Pulldown
#define GPFPU 7 //Pullup
#define GPFFS2 8 //Function Select bit 2
#define GPFFS(f) (((((f) & 4) != 0) << GPFFS2) | ((((f) & 2) != 0) << GPFFS1) | ((((f) & 1) != 0) << GPFFS0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@ MDNSResponder mdns;

ESP8266WebServer server(80);

const int led = 13;

void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp8266!");
digitalWrite(led, 0);
}

void handleNotFound(){
String message = "URI: ";
digitalWrite(led, 1);
String message += "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nNot Found!\n\n";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}

void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
Expand Down
2 changes: 1 addition & 1 deletion hardware/esp8266com/esp8266/platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD
Expand Down