Skip to content

Commit

Permalink
Merge branch 'master' into espino-support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodmg committed Dec 7, 2015
2 parents 8847d7a + 93aaa86 commit 5163391
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 59 deletions.
8 changes: 3 additions & 5 deletions cores/esp8266/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,12 @@ void loop(void);
void yield(void);
void optimistic_yield(uint32_t interval_us);

// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
#define digitalPinToPort(pin) (0)
#define digitalPinToBitMask(pin) (1UL << (pin))
#define digitalPinToTimer(pin) (0)
#define portOutputRegister(port) ((volatile uint32_t*) GPO)
#define portInputRegister(port) ((volatile uint32_t*) GPI)
#define portModeRegister(port) ((volatile uint32_t*) GPE)
#define portOutputRegister(port) ((volatile uint32_t*) &GPO)
#define portInputRegister(port) ((volatile uint32_t*) &GPI)
#define portModeRegister(port) ((volatile uint32_t*) &GPE)

#define NOT_A_PIN -1
#define NOT_A_PORT -1
Expand Down
5 changes: 1 addition & 4 deletions cores/esp8266/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,18 +617,15 @@ size_t HardwareSerial::write(uint8_t c) {
size_t room = uart_get_tx_fifo_room(_uart);
if(room > 0 && _tx_buffer->empty()) {
uart_transmit_char(_uart, c);
if(room < 10) {
uart_arm_tx_interrupt(_uart);
}
return 1;
}

while(_tx_buffer->room() == 0) {
yield();
uart_arm_tx_interrupt(_uart);
}

_tx_buffer->write(c);
uart_arm_tx_interrupt(_uart);
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/Updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class UpdaterClass {
Call this to check the space needed for the update
Will return false if there is not enough space
*/
bool begin(size_t size, int = U_FLASH);
bool begin(size_t size, int command = U_FLASH);

/*
Writes a buffer to the flash and increments the address
Expand Down
4 changes: 4 additions & 0 deletions cores/esp8266/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ void __throw_length_error(char const*) {
void __throw_bad_alloc() {
panic();
}

void __throw_logic_error(const char* str) {
panic();
}
}

// TODO: rebuild windows toolchain to make this unnecessary:
Expand Down
17 changes: 8 additions & 9 deletions cores/esp8266/cbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class cbuf {
if(_end >= _begin) {
return _size - (_end - _begin) - 1;
}
if(_begin == _end) {
return _size;
}
return _begin - _end - 1;
}

Expand All @@ -62,7 +59,7 @@ class cbuf {
if(getSize() == 0) return -1;

char result = *_begin;
if(++_begin == _bufend) _begin = _buf;
_begin = wrap_if_bufend(_begin + 1);
return static_cast<int>(result);
}

Expand All @@ -78,16 +75,15 @@ class cbuf {
dst += top_size;
}
memcpy(dst, _begin, size_to_read);
_begin += size_to_read;
if(_begin == _bufend) _begin = _buf;
_begin = wrap_if_bufend(_begin + size_to_read);
return size_read;
}

size_t write(char c) {
if(room() == 0) return 0;

*_end = c;
if(++_end == _bufend) _end = _buf;
_end = wrap_if_bufend(_end + 1);
return 1;
}

Expand All @@ -103,8 +99,7 @@ class cbuf {
src += top_size;
}
memcpy(_end, src, size_to_write);
_end += size_to_write;
if(_end == _bufend) _end = _buf;
_end = wrap_if_bufend(_end + size_to_write);
return size_written;
}

Expand All @@ -114,6 +109,10 @@ class cbuf {
}

private:
inline char* wrap_if_bufend(char* ptr) {
return (ptr == _bufend) ? _buf : ptr;
}

size_t _size;
char* _buf;
char* _bufend;
Expand Down
2 changes: 1 addition & 1 deletion cores/esp8266/esp8266_peri.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ extern uint8_t esp8266_gpioToFn[16];

//SPI Phase Length Locations
#define SPILCOMMAND 28 //4 bit in SPIxU2 default 7 (8bit)
#define SPILADDR 16 //6 bit in SPIxU1 default:23 (24bit)
#define SPILADDR 26 //6 bit in SPIxU1 default:23 (24bit)
#define SPILDUMMY 0 //8 bit in SPIxU1 default:0 (0 cycles)
#define SPILMISO 8 //9 bit in SPIxU1 default:0 (1bit)
#define SPILMOSI 17 //9 bit in SPIxU1 default:0 (1bit)
Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/pgmspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
(__extension__({ \
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
ptrdiff_t __offset = ((uint32_t)__local & 0x00000003); /* byte aligned mask */ \
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local)-__offset); \
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local)-__offset); \
uint8_t __result = ((*__addr32) >> (__offset * 8)); \
__result; \
}))
Expand All @@ -87,7 +87,7 @@ int vsnprintf_P(char *str, size_t strSize, PGM_P formatP, va_list ap) __attribut
(__extension__({ \
PGM_P __local = (PGM_P)(addr); /* isolate varible for macro expansion */ \
ptrdiff_t __offset = ((uint32_t)__local & 0x00000002); /* word aligned mask */ \
const uint32_t* __addr32 = reinterpret_cast<const uint32_t*>(reinterpret_cast<const uint8_t*>(__local) - __offset); \
const uint32_t* __addr32 = (const uint32_t*)((const uint8_t*)(__local) - __offset); \
uint16_t __result = ((*__addr32) >> (__offset * 8)); \
__result; \
}))
Expand Down
11 changes: 11 additions & 0 deletions cores/esp8266/spiffs_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ class SPIFFSDirImpl : public DirImpl {
FileImplPtr SPIFFSImpl::open(const char* path, OpenMode openMode, AccessMode accessMode) {
int mode = getSpiffsMode(openMode, accessMode);
int fd = SPIFFS_open(&_fs, path, mode, 0);
if (fd < 0 && _fs.err_code == SPIFFS_ERR_DELETED && (openMode & OM_CREATE)) {
DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d, trying to remove\r\n",
fd, path, openMode, accessMode, _fs.err_code);
auto rc = SPIFFS_remove(&_fs, path);
if (rc != SPIFFS_OK) {
DEBUGV("SPIFFSImpl::open: SPIFFS_ERR_DELETED, but failed to remove path=`%s` openMode=%d accessMode=%d err=%d\r\n",
path, openMode, accessMode, _fs.err_code);
return FileImplPtr();
}
fd = SPIFFS_open(&_fs, path, mode, 0);
}
if (fd < 0) {
DEBUGV("SPIFFSImpl::open: fd=%d path=`%s` openMode=%d accessMode=%d err=%d\r\n",
fd, path, openMode, accessMode, _fs.err_code);
Expand Down
39 changes: 39 additions & 0 deletions doc/eclipse/makefile.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
vecho := @echo
Q := @

PROJECT_NAME=project_name

OTA_IP=192.168.254.100
OTA_PORT=8266

SERIAL_PORT=COM3
SERIAL_BAUD=230400

ARDUINO_BASE = D:/Coding/avr/Programme/arduino-nightly
ESP8266_BASE = $(ARDUINO_BASE)/hardware/esp8266com/esp8266
ESP8266_TOOLS = $(ESP8266_BASE)/tools
XTENSA_TOOLS_ROOT = $(ESP8266_TOOLS)/xtensa-lx106-elf/bin

PYTHON_BIN = python
ESPTOOL_PY_BIN = $(ESP8266_TOOLS)/esptool.py
ESPOTA_PY_BIN = $(ESP8266_TOOLS)/espota.py
ESPTOOL_BIN = $(ESP8266_TOOLS)/esptool/esptool.exe

ota:
$(vecho) ota...
$(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -f ./$(PROJECT_NAME).bin

ota_spiffs:
$(vecho) ota spiffs...
$(PYTHON_BIN) $(ESPOTA_PY_BIN) -i $(OTA_IP) -p $(OTA_PORT) --auth= -s -f ./$(PROJECT_NAME)_spiffs.bin

erase_flash:
$(vecho) "Erase Flash"
$(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) erase_flash

dumpmem:
$(vecho) "Read Flash need some time..."
$(PYTHON_BIN) $(ESPTOOL_PY_BIN) -p $(SERIAL_PORT) -b $(SERIAL_BAUD) read_flash 0 4194304 dump.bin

objdump:
"$(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-objdump" -S $(PROJECT_NAME).elf > $(PROJECT_NAME).dobj
9 changes: 8 additions & 1 deletion libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ void loop() {
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
int timeout = millis() + 5000;
while (client.available() == 0) {
if (timeout - millis() < 0) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}

// Read all the lines of the reply from server and print them to Serial
while(client.available()){
Expand Down
68 changes: 68 additions & 0 deletions libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This sketch sends a message to a TCP server
*
*/

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

ESP8266WiFiMulti WiFiMulti;

void setup() {
Serial.begin(115200);
delay(10);

// We start by connecting to a WiFi network
WiFiMulti.addAP("SSID", "passpasspass");

Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");

while(WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

delay(500);
}


void loop() {
const uint16_t port = 80;
const char * host = "192.168.1.1"; // ip or dns



Serial.print("connecting to ");
Serial.println(host);

// Use WiFiClient class to create TCP connections
WiFiClient client;

if (!client.connect(host, port)) {
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(5000);
return;
}

// This will send the request to the server
client.print("Send this data to server");

//read back one line from server
String line = client.readStringUntil('\r');
client.println(line);

Serial.println("closing connection");
client.stop();

Serial.println("wait 5 sec...");
delay(5000);
}

Loading

0 comments on commit 5163391

Please sign in to comment.