Commit 38efa482 authored by Robert Foss's avatar Robert Foss
Browse files

Merge remote-tracking branch 'upstream/dev' into dev

parents d2fc8782 340edbbe
sudo: false
language: cpp
before_install:
- sudo apt-get install -y python-serial srecord
addons:
apt:
packages:
- python-serial
- srecord
install:
- tar -zxvf tools/esp-open-sdk.tar.gz
- export PATH=$PATH:$PWD/esp-open-sdk/sdk:$PWD/esp-open-sdk/xtensa-lx106-elf/bin
- export PATH=$PATH:$PWD/esp-open-sdk/xtensa-lx106-elf/bin
script:
- make all
- export BUILD_DATE=$(date +%Y%m%d)
- make EXTRA_CCFLAGS="-DBUILD_DATE='\"'$BUILD_DATE'\"'" all
- cd bin/
- file_name_float="nodemcu_float_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_float} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
- cd ../
- make clean
- make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL"
- make EXTRA_CCFLAGS="-DLUA_NUMBER_INTEGRAL -DBUILD_DATE='\"'$BUILD_DATE'\"'"
- cd bin/
- file_name_integer="nodemcu_integer_${TRAVIS_TAG}.bin"
- srec_cat -output ${file_name_integer} -binary 0x00000.bin -binary -fill 0xff 0x00000 0x10000 0x10000.bin -binary -offset 0x10000
......
## Contributing
# Contributing to NodeMCU
Thank you everyone for contributing to this project.
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
Pull requests for new features and major fixes should be opened against the `dev` branch.
The following is a set of guidelines for contributing to NodeMCU on GitHub. These are just guidelines, not rules, use your best judgment and feel free to propose changes to this document in a pull request.
*Note that the `pre_build` bin in the dev branch is never up-to-date.*
It is appreciated but optional if you raise an issue _before_ you start changing NodeMCU, discussing the proposed change; emphasising that the you are proposing to develop the patch yourself, and outling the strategy for implementation. This type of discussion is what we should be doing on the issues list and it is better to do this before or in parallel to developing the patch rather than having "you should have done it this way" type of feedback on the PR itself.
### Table Of Contents
* [Development environment setup](#development-environment-setup)
* [Working with Git and GitHub](#working-with-git-and-github)
* [General flow](#general-flow)
* [Keeping your fork in sync](#keeping-your-fork-in-sync)
* [Commit messages](#commit-messages)
## Development environment setup
Use the platform and tools you feel most comfortable with. There are no constraints imposed by this project. You have (at least) two options to set up the toolchain to build the NodeMCU firmware:
- [Full-fledged Linux enviroment](http://www.esp8266.com/wiki/doku.php?id=toolchain#how_to_setup_a_vm_to_host_your_toolchain), either physical or virtual.
- [Docker image](https://hub.docker.com/r/marcelstoer/nodemcu-build/) which allows to run the build inside the container as if you were running a build script on your local machine.
## Working with Git and GitHub
*Pull requests for new features and major fixes should be opened against the `dev` branch.*
Avoid intermediate merge commits. [Rebase](https://www.atlassian.com/git/tutorials/merging-vs-rebasing) your feature branch onto `dev` to pull updates and verify your local changes against them before placing the pull request.
### General flow
1. [Fork](https://help.github.com/articles/fork-a-repo) the NodeMCU repo on GitHub.
1. [Create a branch](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/#creating-a-branch) in your fork on GitHub **based on the `dev` branch**.
1. Clone the fork on your machine with `git clone https://github.com/<your-account>/<nodemcu-fork>.git`
1. `cd <nodemcu-fork>` then run `git remote add upstream https://github.com/nodemcu/nodemcu-firmware.git`
1. `git checkout <branch-name>`
1. Make changes to the code base and commit them using e.g. `git commit -a -m 'Look ma, I did it'`
1. When you're done:
1. [Squash your commits](http://stackoverflow.com/a/5201642/131929) into one. There are several ways of doing this.
1. Bring your fork up-to-date with the NodeMCU upstream repo ([see below](#keeping-your-fork-in-sync)). Then rebase your branch on `dev` running `git rebase dev`.
1. `git push`
1. [Create a pull request](https://help.github.com/articles/creating-a-pull-request/) (PR) on GitHub.
This is just one way of doing things. If you're proficient in Git matters you're free to choose your own. If you want to read more then the [GitHub chapter in the Git book](http://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project#The-GitHub-Flow) is a way to start. [GitHub's own documenation](https://help.github.com/categories/collaborating/) contains a wealth of information as well.
### Keeping your fork in sync
You need to sync your fork with the NodeMCU upstream repository from time to time, latest before you rebase (see flow above).
1. `git fetch upstream`
1. `git checkout dev` but you may do this for `master` as well
1. `git merge upstream/dev`
### Commit messages
From: [http://git-scm.com/book/ch5-2.html](http://git-scm.com/book/ch5-2.html)
<pre>
Short (50 chars or less) summary of changes
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded by a
single space, with blank lines in between, but conventions vary here
</pre>
Don't forget to [reference affected issues](https://help.github.com/articles/closing-issues-via-commit-messages/) in the commit message to have them closed automatically on GitHub.
[Amend](https://help.github.com/articles/changing-a-commit-message/) your commit messages if necessary to make sure what the world sees on GitHub is as expressive and meaningful as possible.
# copyright (c) 2010 Espressif System
#
.NOTPARALLEL:
ifndef PDIR
endif
# SDK version NodeMCU is locked to
SDK_VER:=1.4.0
# Ensure we search "our" SDK before the tool-chain's SDK (if any)
TOP_DIR:=$(dir $(lastword $(MAKEFILE_LIST)))
SDK_DIR:=$(TOP_DIR)sdk/esp_iot_sdk_v$(SDK_VER)
CCFLAGS:= -I$(TOP_DIR)sdk-overrides/include -I$(SDK_DIR)/include
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld $(LDFLAGS)
#############################################################
# Select compile
#
......
......@@ -81,13 +81,13 @@ tools/esptool.py supported NodeMCU devkit automatic flash.
<th scope="col">IO index</th><th scope="col">ESP8266 pin</th><th scope="col">IO index</th><th scope="col">ESP8266 pin</th>
</tr>
<tr>
<td>0 [*]</td><td>GPIO16</td><td>8</td><td>GPIO15</td>
<td>0 [*]</td><td>GPIO16</td><td>8</td><td>GPIO15 (SPI CS)</td>
</tr>
<tr>
<td>1</td><td>GPIO5</td><td>9</td><td>GPIO3</td>
<td>1</td><td>GPIO5</td><td>9</td><td>GPIO3 (UART RX)</td>
</tr>
<tr>
<td>2</td><td>GPIO4</td><td>10</td><td>GPIO1</td>
<td>2</td><td>GPIO4</td><td>10</td><td>GPIO1 (UART TX)</td>
</tr>
<tr>
<td>3</td><td>GPIO0</td><td>11</td><td>GPIO9</td>
......@@ -96,13 +96,13 @@ tools/esptool.py supported NodeMCU devkit automatic flash.
<td>4</td><td>GPIO2</td><td>12</td><td>GPIO10</td>
</tr>
<tr>
<td>5</td><td>GPIO14</td><td></td><td></td>
<td>5</td><td>GPIO14 (SPI CLK)</td><td></td><td></td>
</tr>
<tr>
<td>6</td><td>GPIO12</td><td></td><td></td>
<td>6</td><td>GPIO12 (SPI MISO)</td><td></td><td></td>
</tr>
<tr>
<td>7</td><td>GPIO13</td><td></td><td></td>
<td>7</td><td>GPIO13 (SPI MOSI)</td><td></td><td></td>
</tr>
</table>
#### [*] D0(GPIO16) can only be used as gpio read/write. no interrupt supported. no pwm/i2c/ow supported.
......@@ -360,8 +360,27 @@ cu:send("hello")
```
####Operate a display with u8glib
u8glib is a graphics library with support for many different displays.
The integration in nodemcu is developed for SSD1306 based display attached via the I2C port. Further display types and SPI connectivity will be added in the future.
u8glib is a graphics library with support for many different displays. The nodemcu firmware supports a subset of these.
Both I2C and SPI:
* sh1106_128x64
* ssd1306 - 128x64 and 64x48 variants
* ssd1309_128x64
* ssd1327_96x96_gr
* uc1611 - dogm240 and dogxl240 variants
SPI only:
* ld7032_60x32
* pcd8544_84x48
* pcf8812_96x65
* ssd1322_nhd31oled - bw and gr variants
* ssd1325_nhd27oled - bw and gr variants
* ssd1351_128x128 - gh and hicolor variants
* st7565_64128n - variants 64128n, dogm128/132, lm6059/lm6063, c12832/c12864
* uc1601_c128032
* uc1608 - 240x128 and 240x64 variants
* uc1610_dogxl160 - bw and gr variants
* uc1611 - dogm240 and dogxl240 variants
* uc1701 - dogs102 and mini12864 variants
U8glib v1.18.1
......@@ -386,7 +405,7 @@ All other pins can be assigned to any available GPIO:
Also refer to the initialization sequence eg in [u8g_graphics_test.lua](lua_examples/u8glib/u8g_graphics_test.lua):
```lua
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0)
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
```
......@@ -451,6 +470,61 @@ In contrast to the source code based inclusion of XBMs into u8glib, it's require
- [ ] setRGB()
- [ ] setDefaultMidColor()
####Operate a display with ucglib
Ucglib is a graphics library with support for color TFT displays.
Ucglib v1.3.3
#####SPI connection
The HSPI module is used, so certain pins are fixed:
* HSPI CLK = GPIO14
* HSPI MOSI = GPIO13
* HSPI MISO = GPIO12 (not used)
All other pins can be assigned to any available GPIO:
* CS
* D/C
* RES (optional for some displays)
Also refer to the initialization sequence eg in [GraphicsTest.lua](lua_examples/ucglib/GraphicsRest.lua):
```lua
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 8)
```
#####Library usage
The Lua bindings for this library closely follow ucglib's object oriented C++ API. Based on the ucg class, you create an object for your display type.
ILI9341 via SPI:
```lua
cs = 8 -- GPIO15, pull-down 10k to GND
dc = 4 -- GPIO2
res = 0 -- GPIO16, RES is optional YMMV
disp = ucg.ili9341_18x240x320_hw_spi(cs, dc, res)
```
This object provides all of ucglib's methods to control the display.
Again, refer to [GraphicsTest.lua](lua_examples/ucglib/GraphicsTest.lua) to get an impression how this is achieved with Lua code. Visit the [ucglib homepage](https://github.com/olikraus/ucglib) for technical details.
#####Displays
To get access to the display constructors, add the desired entries to the display table in [app/include/ucg_config.h](app/include/ucg_config.h):
```c
#define UCG_DISPLAY_TABLE \
UCG_DISPLAY_TABLE_ENTRY(ili9341_18x240x320_hw_spi, ucg_dev_ili9341_18x240x320, ucg_ext_ili9341_18) \
UCG_DISPLAY_TABLE_ENTRY(st7735_18x128x160_hw_spi, ucg_dev_st7735_18x128x160, ucg_ext_st7735_18) \
```
#####Fonts
ucglib comes with a wide range of fonts for small displays. Since they need to be compiled into the firmware image, you'd need to include them in [app/include/ucg_config.h](app/include/ucg_config.h) and recompile. Simply add the desired fonts to the font table:
```c
#define UCG_FONT_TABLE \
UCG_FONT_TABLE_ENTRY(font_7x13B_tr) \
UCG_FONT_TABLE_ENTRY(font_helvB12_hr) \
UCG_FONT_TABLE_ENTRY(font_helvB18_hr) \
UCG_FONT_TABLE_ENTRY(font_ncenR12_tr) \
UCG_FONT_TABLE_ENTRY(font_ncenR14_hr)
```
They'll be available as `ucg.<font_name>` in Lua.
####Control a WS2812 based light strip
```lua
......@@ -499,3 +573,13 @@ value = { true, { foo = "bar" } }
json_text = cjson.encode(value)
-- Returns: '[true,{"foo":"bar"}]'
```
####Read an HX711 load cell ADC.
Note: currently only chanel A with gain 128 is supported.
The HX711 is an inexpensive 24bit ADC with programmable 128x, 64x, and 32x gain.
```lua
-- Initialize the hx711 with clk on pin 5 and data on pin 6
hx711.init(5,6)
-- Read ch A with 128 gain.
raw_data = hx711.read(0)
```
......@@ -24,22 +24,24 @@ SPECIAL_MKTARGETS=$(APP_MKTARGETS)
SUBDIRS= \
user \
driver \
lwip \
json \
upgrade \
platform \
libc \
lua \
lwip \
coap \
mqtt \
u8glib \
ucglib \
smart \
wofs \
modules \
spiffs \
cjson \
crypto \
dhtlib
dhtlib \
tsl2561
endif # } PDIR
......@@ -62,44 +64,39 @@ ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -Os
endif
LD_FILE = $(LDDIR)/eagle.app.v6.ld
ifeq ($(APP), 1)
LD_FILE = $(LDDIR)/eagle.app.v6.app1.ld
endif
ifeq ($(APP), 2)
LD_FILE = $(LDDIR)/eagle.app.v6.app2.ld
endif
LD_FILE = $(LDDIR)/nodemcu.ld
COMPONENTS_eagle.app.v6 = \
user/libuser.a \
driver/libdriver.a \
lwip/liblwip.a \
json/libjson.a \
upgrade/libupgrade.a \
platform/libplatform.a \
libc/liblibc.a \
lua/liblua.a \
lwip/liblwip.a \
coap/coap.a \
mqtt/mqtt.a \
u8glib/u8glib.a \
ucglib/ucglib.a \
smart/smart.a \
wofs/wofs.a \
spiffs/spiffs.a \
cjson/libcjson.a \
crypto/libcrypto.a \
dhtlib/libdhtlib.a \
modules/libmodules.a
tsl2561/tsl2561lib.a \
modules/libmodules.a
LINKFLAGS_eagle.app.v6 = \
-L../lib \
-Wl,--gc-sections \
-Xlinker -Map=mapfile \
-Wl,-Map=mapfile \
-nostdlib \
-T$(LD_FILE) \
-T$(LD_FILE) \
-Wl,@../ld/defsym.rom \
-Wl,--no-check-sections \
-Wl,--wrap=_xtos_set_exception_handler \
-Wl,--wrap=_xtos_set_exception_handler \
-Wl,-static \
-Wl,--start-group \
-lc \
......@@ -119,7 +116,7 @@ LINKFLAGS_eagle.app.v6 = \
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld
Makefile
#############################################################
# Configuration i.e. compile options etc.
......
......@@ -5,6 +5,8 @@
extern "C" {
#endif
#include "c_types.h"
#include "lwip/ip_addr.h"
#include "espconn.h"
#include "pdu.h"
#include "hash.h"
......
......@@ -8,6 +8,8 @@
#include "lualib.h"
#include "os_type.h"
#include "user_interface.h"
#include "user_config.h"
void build_well_known_rsp(char *rsp, uint16_t rsplen);
......@@ -164,8 +166,6 @@ end:
}
extern lua_Load gLoad;
extern os_timer_t lua_timer;
extern void dojob(lua_Load *load);
static const coap_endpoint_path_t path_command = {2, {"v1", "c"}};
static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo)
{
......@@ -184,9 +184,7 @@ static int handle_post_command(const coap_endpoint_t *ep, coap_rw_buffer_t *scra
NODE_DBG("Get command:\n");
NODE_DBG(load->line); // buggy here
NODE_DBG("\nResult(if any):\n");
os_timer_disarm(&lua_timer);
os_timer_setfn(&lua_timer, (os_timer_func_t *)dojob, load);
os_timer_arm(&lua_timer, READLINE_INTERVAL, 0); // no repeat
system_os_post (LUA_TASK_PRIO, LUA_PROCESS_LINE_SIG, 0);
}
return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, &inpkt->tok, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN);
}
......
......@@ -30,7 +30,8 @@
#include "digests.h"
#include "user_config.h"
#include "rom.h"
#include "lwip/mem.h"
#include "osapi.h"
#include "mem.h"
#include <string.h>
#include <c_errno.h>
......@@ -108,7 +109,7 @@ int ICACHE_FLASH_ATTR crypto_hash (const digest_mech_info_t *mi,
if (!mi)
return EINVAL;
void *ctx = os_malloc (mi->ctx_size);
void *ctx = (void *)os_malloc (mi->ctx_size);
if (!ctx)
return ENOMEM;
......@@ -129,7 +130,7 @@ int ICACHE_FLASH_ATTR crypto_hmac (const digest_mech_info_t *mi,
if (!mi)
return EINVAL;
void *ctx = os_malloc (mi->ctx_size);
void *ctx = (void *)os_malloc (mi->ctx_size);
if (!ctx)
return ENOMEM;
......
......@@ -253,7 +253,7 @@ int dht_readSensor(uint8_t pin, uint8_t wakeupDelay)
// delay(wakeupDelay);
for (i = 0; i < wakeupDelay; i++) os_delay_us(1000);
// Disable interrupts
os_intr_lock();
ets_intr_lock();
// digitalWrite(pin, HIGH); // T-go
DIRECT_WRITE_HIGH(pin);
os_delay_us(40);
......@@ -306,7 +306,7 @@ int dht_readSensor(uint8_t pin, uint8_t wakeupDelay)
}
}
// Enable interrupts
os_intr_unlock();
ets_intr_unlock();
// pinMode(pin, OUTPUT);
DIRECT_MODE_OUTPUT(pin);
// digitalWrite(pin, HIGH);
......@@ -316,4 +316,4 @@ int dht_readSensor(uint8_t pin, uint8_t wakeupDelay)
}
//
// END OF FILE
//
\ No newline at end of file
//
......@@ -60,10 +60,13 @@ sample code bearing this copyright.
#include "platform.h"
#include "osapi.h"
#define noInterrupts os_intr_lock
#define interrupts os_intr_unlock
#define noInterrupts ets_intr_lock
#define interrupts ets_intr_unlock
#define delayMicroseconds os_delay_us
// 1 for keeping the parasitic power on H
#define owDefaultPower 1
#if ONEWIRE_SEARCH
// global search state
static unsigned char ROM_NO[NUM_OW][8];
......@@ -185,7 +188,7 @@ void onewire_write(uint8_t pin, uint8_t v, uint8_t power /* = 0 */) {
void onewire_write_bytes(uint8_t pin, const uint8_t *buf, uint16_t count, bool power /* = 0 */) {
uint16_t i;
for (i = 0 ; i < count ; i++)
onewire_write(pin, buf[i], 0);
onewire_write(pin, buf[i], owDefaultPower);
if (!power) {
noInterrupts();
DIRECT_MODE_INPUT(pin);
......@@ -220,9 +223,9 @@ void onewire_select(uint8_t pin, const uint8_t rom[8])
{
uint8_t i;
onewire_write(pin, 0x55, 0); // Choose ROM
onewire_write(pin, 0x55, owDefaultPower); // Choose ROM
for (i = 0; i < 8; i++) onewire_write(pin, rom[i], 0);
for (i = 0; i < 8; i++) onewire_write(pin, rom[i], owDefaultPower);
}
//
......@@ -230,7 +233,7 @@ void onewire_select(uint8_t pin, const uint8_t rom[8])
//
void onewire_skip(uint8_t pin)
{
onewire_write(pin, 0xCC, 0); // Skip ROM
onewire_write(pin, 0xCC, owDefaultPower); // Skip ROM
}
void onewire_depower(uint8_t pin)
......@@ -319,7 +322,7 @@ uint8_t onewire_search(uint8_t pin, uint8_t *newAddr)
}
// issue the search command
onewire_write(pin, 0xF0, 0);
onewire_write(pin, 0xF0, owDefaultPower);
// loop to do the search
do
......
......@@ -64,7 +64,7 @@ void spi_lcd_9bit_write(uint8 spi_no,uint8 high_bit,uint8 low_8bit)
* Description : SPI master initial function for common byte units transmission
* Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid
*******************************************************************************/
void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, unsigned databits, uint32_t clock)
void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, uint32_t clock_div)
{
uint32 regvalue;
......@@ -85,62 +85,225 @@ void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, unsigned databi
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to spi mode
}
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD|SPI_DOUTDIN|SPI_USR_MOSI);
//set clock polarity
// TODO: This doesn't work
//if (cpol == 1) {
// SET_PERI_REG_MASK(SPI_CTRL2(spi_no), (SPI_CK_OUT_HIGH_MODE<<SPI_CK_OUT_HIGH_MODE_S));
//} else {
// SET_PERI_REG_MASK(SPI_CTRL2(spi_no), (SPI_CK_OUT_LOW_MODE<<SPI_CK_OUT_LOW_MODE_S));
//}
//os_printf("SPI_CTRL2 is %08x\n",READ_PERI_REG(SPI_CTRL2(spi_no)));
//set clock phase
if (cpha == 1) {
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CK_OUT_EDGE|SPI_CK_I_EDGE);
} else {
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_CK_OUT_EDGE|SPI_CK_I_EDGE);
}
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD|SPI_RD_BYTE_ORDER|SPI_WR_BYTE_ORDER|SPI_DOUTDIN);
//set clock polarity
// TODO: This doesn't work
//if (cpol == 1) {
// SET_PERI_REG_MASK(SPI_CTRL2(spi_no), (SPI_CK_OUT_HIGH_MODE<<SPI_CK_OUT_HIGH_MODE_S));
//} else {
// SET_PERI_REG_MASK(SPI_CTRL2(spi_no), (SPI_CK_OUT_LOW_MODE<<SPI_CK_OUT_LOW_MODE_S));
//}
//os_printf("SPI_CTRL2 is %08x\n",READ_PERI_REG(SPI_CTRL2(spi_no)));
//set clock phase
if (cpha == 1) {
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CK_OUT_EDGE|SPI_CK_I_EDGE);
} else {
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_CK_OUT_EDGE|SPI_CK_I_EDGE);
}
CLEAR_PERI_REG_MASK(SPI_USER(HSPI), SPI_FLASH_MODE|SPI_WR_BYTE_ORDER|SPI_USR_MISO|
SPI_RD_BYTE_ORDER|SPI_USR_ADDR|SPI_USR_COMMAND|SPI_USR_DUMMY);
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE|SPI_USR_MISO|SPI_USR_ADDR|SPI_USR_COMMAND|SPI_USR_DUMMY);
//clear Daul or Quad lines transmission mode
//clear Dual or Quad lines transmission mode
CLEAR_PERI_REG_MASK(SPI_CTRL(spi_no), SPI_QIO_MODE|SPI_DIO_MODE|SPI_DOUT_MODE|SPI_QOUT_MODE);
// SPI clock=CPU clock/8
// SPI clock = CPU clock / clock_div
// the divider needs to be a multiple of 2 to get a proper waveform shape
if ((clock_div & 0x01) != 0) {
// bump the divider to the next N*2
clock_div += 0x02;
}
clock_div >>= 1;
// clip to maximum possible CLKDIV_PRE
clock_div = clock_div > SPI_CLKDIV_PRE ? SPI_CLKDIV_PRE : clock_div - 1;
WRITE_PERI_REG(SPI_CLOCK(spi_no),
((1&SPI_CLKDIV_PRE)<<SPI_CLKDIV_PRE_S)|
((3&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
((1&SPI_CLKCNT_H)<<SPI_CLKCNT_H_S)|
((3&SPI_CLKCNT_L)<<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div
((clock_div&SPI_CLKDIV_PRE)<<SPI_CLKDIV_PRE_S)|
((1&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
((0&SPI_CLKCNT_H)<<SPI_CLKCNT_H_S)|
((1&SPI_CLKCNT_L)<<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div
}
//set 8bit output buffer length, the buffer is the low 8bit of register"SPI_FLASH_C0"
WRITE_PERI_REG(SPI_USER1(spi_no),
((7&SPI_USR_MOSI_BITLEN)<<SPI_USR_MOSI_BITLEN_S)|
((7&SPI_USR_MISO_BITLEN)<<SPI_USR_MISO_BITLEN_S));
/******************************************************************************
* FunctionName : spi_mast_set_mosi
* Description : Enter provided data into MOSI buffer.
* The data is regarded as a sequence of bits with length 'bitlen'.
* It will be written left-aligned starting from position 'offset'.
* Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid
* uint8 offset - offset into MOSI buffer (number of bits)
* uint8 bitlen - valid number of bits in data
* uint32 data - data to be written into buffer
*******************************************************************************/
void spi_mast_set_mosi(uint8 spi_no, uint8 offset, uint8 bitlen, uint32 data)
{
uint8 wn, wn_offset, wn_bitlen;
uint32 wn_data;
if (spi_no > 1)
return; // handle invalid input number
if (bitlen > 32)
return; // handle invalid input number
while(READ_PERI_REG(SPI_CMD(spi_no)) & SPI_USR);
// determine which SPI_Wn register is addressed
wn = offset >> 5;
if (wn > 15)
return; // out of range
wn_offset = offset & 0x1f;
if (32 - wn_offset < bitlen)
{
// splitting required
wn_bitlen = 32 - wn_offset;
wn_data = data >> (bitlen - wn_bitlen);
}
else
{
wn_bitlen = bitlen;
wn_data = data;
}
do
{
// write payload data to SPI_Wn
SET_PERI_REG_BITS(REG_SPI_BASE(spi_no) +0x40 + wn*4, BIT(wn_bitlen) - 1, wn_data, 32 - (wn_offset + wn_bitlen));
// prepare writing of dangling data part
wn += 1;
wn_offset = 0;
if (wn <= 15)
bitlen -= wn_bitlen;
else
bitlen = 0; // force abort
wn_bitlen = bitlen;
wn_data = data;
} while (bitlen > 0);
return;
}
/******************************************************************************
* FunctionName : spi_mast_byte_write
* Description : SPI master 1 byte transmission function
* Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid
* uint8 data- transmitted data
* FunctionName : spi_mast_get_miso
* Description : Retrieve data from MISO buffer.
* The data is regarded as a sequence of bits with length 'bitlen'.
* It will be read starting left-aligned from position 'offset'.
* Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid
* uint8 offset - offset into MISO buffer (number of bits)
* uint8 bitlen - requested number of bits in data
*******************************************************************************/
void spi_mast_byte_write(uint8 spi_no, uint8 *data)
uint32 spi_mast_get_miso(uint8 spi_no, uint8 offset, uint8 bitlen)
{
if(spi_no>1) return; //handle invalid input number
uint8 wn, wn_offset, wn_bitlen;
uint32 wn_data = 0;
while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR);
if (spi_no > 1)
return 0; // handle invalid input number
WRITE_PERI_REG(SPI_W0(spi_no), *data);
while(READ_PERI_REG(SPI_CMD(spi_no)) & SPI_USR);
// determine which SPI_Wn register is addressed
wn = offset >> 5;
if (wn > 15)
return 0; // out of range
wn_offset = offset & 0x1f;
if (bitlen > (32 - wn_offset))
{
// splitting required
wn_bitlen = 32 - wn_offset;
}
else
{
wn_bitlen = bitlen;
}
do
{
wn_data |= (READ_PERI_REG(REG_SPI_BASE(spi_no) +0x40 + wn*4) >> (32 - (wn_offset + wn_bitlen))) & (BIT(wn_bitlen) - 1);
// prepare reading of dangling data part
wn_data <<= bitlen - wn_bitlen;
wn += 1;
wn_offset = 0;
if (wn <= 15)
bitlen -= wn_bitlen;
else
bitlen = 0; // force abort
wn_bitlen = bitlen;
} while (bitlen > 0);
return wn_data;
}
/******************************************************************************
* FunctionName : spi_mast_transaction
* Description : Start a transaction and wait for completion.
* Parameters : uint8 spi_no - SPI module number, Only "SPI" and "HSPI" are valid
* uint8 cmd_bitlen - Valid number of bits in cmd_data.
* uint16 cmd_data - Command data.
* uint8 addr_bitlen - Valid number of bits in addr_data.
* uint32 addr_data - Address data.
* uint16 mosi_bitlen - Valid number of bits in MOSI buffer.
* uint8 dummy_bitlen - Number of dummy cycles.
* sint16 miso_bitlen - number of bits to be captured in MISO buffer.
* negative value activates full-duplex mode.
*******************************************************************************/
void spi_mast_transaction(uint8 spi_no, uint8 cmd_bitlen, uint16 cmd_data, uint8 addr_bitlen, uint32 addr_data,
uint16 mosi_bitlen, uint8 dummy_bitlen, sint16 miso_bitlen)
{
if (spi_no > 1)
return; // handle invalid input number
while(READ_PERI_REG(SPI_CMD(spi_no)) & SPI_USR);
// default disable COMMAND, ADDR, MOSI, DUMMY, MISO, and DOUTDIN (aka full-duplex)
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_COMMAND|SPI_USR_ADDR|SPI_USR_MOSI|SPI_USR_DUMMY|SPI_USR_MISO|SPI_DOUTDIN);
// default set bit lengths
WRITE_PERI_REG(SPI_USER1(spi_no),
((addr_bitlen - 1) & SPI_USR_ADDR_BITLEN) << SPI_USR_ADDR_BITLEN_S |
((mosi_bitlen - 1) & SPI_USR_MOSI_BITLEN) << SPI_USR_MOSI_BITLEN_S |
((dummy_bitlen - 1) & SPI_USR_DUMMY_CYCLELEN) << SPI_USR_DUMMY_CYCLELEN_S |
((miso_bitlen - 1) & SPI_USR_MISO_BITLEN) << SPI_USR_MISO_BITLEN_S);
// handle the transaction components
if (cmd_bitlen > 0)
{
uint16 cmd = cmd_data << (16 - cmd_bitlen); // align to MSB
cmd = (cmd >> 8) | (cmd << 8); // swap byte order
WRITE_PERI_REG(SPI_USER2(spi_no),
((cmd_bitlen - 1 & SPI_USR_COMMAND_BITLEN) << SPI_USR_COMMAND_BITLEN_S) |
(cmd & SPI_USR_COMMAND_VALUE));
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_COMMAND);
}
if (addr_bitlen > 0)
{
WRITE_PERI_REG(SPI_ADDR(spi_no), addr_data << (32 - addr_bitlen));
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_ADDR);
}
if (mosi_bitlen > 0)
{
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MOSI);
}
if (dummy_bitlen > 0)
{
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_DUMMY);
}
if (miso_bitlen > 0)
{
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_USR_MISO);
}
else if (miso_bitlen < 0)
{
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_DOUTDIN);
}
// start transaction
SET_PERI_REG_MASK(SPI_CMD(spi_no), SPI_USR);
while(READ_PERI_REG(SPI_CMD(spi_no))&SPI_USR);
*data = (uint8)(READ_PERI_REG(SPI_W0(spi_no))&0xff);
}
while(READ_PERI_REG(SPI_CMD(spi_no)) & SPI_USR);
}
/******************************************************************************
* FunctionName : spi_byte_write_espslave
......
......@@ -13,10 +13,19 @@
#include "osapi.h"
#include "driver/uart.h"
#include "user_config.h"
#include "user_interface.h"
#define UART0 0
#define UART1 1
#ifndef FUNC_U0RXD
#define FUNC_U0RXD 0
#endif
// For event signalling
static uint8 task = USER_TASK_PRIO_MAX;
static os_signal_t sig;
// UartDev is defined and initialized in rom code.
extern UartDevice UartDev;
......@@ -183,6 +192,7 @@ uart0_rx_intr_handler(void *para)
*/
RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para;
uint8 RcvChar;
bool got_input = false;
if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) {
return;
......@@ -216,7 +226,12 @@ uart0_rx_intr_handler(void *para)
pRxBuff->pReadPos++;
}
}
got_input = true;
}
if (got_input && task != USER_TASK_PRIO_MAX)
system_os_post (task, sig, UART0);
}
/******************************************************************************
......@@ -224,11 +239,16 @@ uart0_rx_intr_handler(void *para)
* Description : user interface for init uart
* Parameters : UartBautRate uart0_br - uart0 bautrate
* UartBautRate uart1_br - uart1 bautrate
* uint8 task_prio - task priority to signal on input
* os_signal_t sig_input - signal to post
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
uart_init(UartBautRate uart0_br, UartBautRate uart1_br, uint8 task_prio, os_signal_t sig_input)
{
task = task_prio;
sig = sig_input;
// rom use 74880 baut_rate, here reinitialize
UartDev.baut_rate = uart0_br;
uart_config(UART0);
......
......@@ -18,9 +18,14 @@ void spi_lcd_mode_init(uint8 spi_no);
void spi_lcd_9bit_write(uint8 spi_no,uint8 high_bit,uint8 low_8bit);
//spi master init funtion
void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, unsigned databits, uint32_t clock);
//use spi send 8bit data
void spi_mast_byte_write(uint8 spi_no,uint8 *data);
void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, uint32_t clock_div);
// fill MOSI buffer
void spi_set_mosi(uint8 spi_no, uint8 offset, uint8 bitlen, uint32 data);
// retrieve data from MISO buffer
uint32 spi_get_miso(uint8 spi_no, uint8 offset, uint8 bitlen);
// initiate SPI transaction
void spi_mast_transaction(uint8 spi_no, uint8 cmd_bitlen, uint16 cmd_data, uint8 addr_bitlen, uint32 addr_data,
uint16 mosi_bitlen, uint8 dummy_bitlen, sint16 miso_bitlen);
//transmit data to esp8266 slave buffer,which needs 16bit transmission ,
//first byte is master command 0x04, second byte is master data
......
......@@ -4,6 +4,7 @@
#include "uart_register.h"
#include "eagle_soc.h"
#include "c_types.h"
#include "os_type.h"
#define RX_BUFF_SIZE 0x100
#define TX_BUFF_SIZE 100
......@@ -100,7 +101,7 @@ typedef struct {
int buff_uart_no; //indicate which uart use tx/rx buffer
} UartDevice;
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br);
void uart_init(UartBautRate uart0_br, UartBautRate uart1_br, uint8 task_prio, os_signal_t sig_input);
void uart0_sendStr(const char *str);
void uart0_putc(const char c);
void uart0_tx_buffer(uint8 *buf, uint16 len);
......
#ifndef __DHCPS_H__
#define __DHCPS_H__
typedef struct dhcps_state{
sint16_t state;
} dhcps_state;
// ����dhcpclient�Զ����һ��DHCP msg�ṹ��
typedef struct dhcps_msg {
uint8_t op, htype, hlen, hops;
uint8_t xid[4];
uint16_t secs, flags;
uint8_t ciaddr[4];
uint8_t yiaddr[4];
uint8_t siaddr[4];
uint8_t giaddr[4];
uint8_t chaddr[16];
uint8_t sname[64];
uint8_t file[128];
uint8_t options[312];
}dhcps_msg;
#ifndef LWIP_OPEN_SRC
struct dhcps_lease {
uint32 start_ip;
uint32 end_ip;
};
#endif
struct dhcps_pool{
struct ip_addr ip;
uint8 mac[6];
uint32 lease_timer;
};
typedef struct _list_node{
void *pnode;
struct _list_node *pnext;
}list_node;
#define DHCPS_LEASE_TIMER 0x05A0
#define DHCPS_MAX_LEASE 0x64
#define BOOTP_BROADCAST 0x8000
#define DHCP_REQUEST 1
#define DHCP_REPLY 2
#define DHCP_HTYPE_ETHERNET 1
#define DHCP_HLEN_ETHERNET 6
#define DHCP_MSG_LEN 236
#define DHCPS_SERVER_PORT 67
#define DHCPS_CLIENT_PORT 68
/*
* Advertise DNS capability in DHCP OFFER
*/
#define USE_DNS 0
#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7
#define DHCP_OPTION_SUBNET_MASK 1
#define DHCP_OPTION_ROUTER 3
#define DHCP_OPTION_DNS_SERVER 6
#define DHCP_OPTION_REQ_IPADDR 50
#define DHCP_OPTION_LEASE_TIME 51
#define DHCP_OPTION_MSG_TYPE 53
#define DHCP_OPTION_SERVER_ID 54
#define DHCP_OPTION_INTERFACE_MTU 26
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
#define DHCP_OPTION_BROADCAST_ADDRESS 28
#define DHCP_OPTION_REQ_LIST 55
#define DHCP_OPTION_END 255
//#define USE_CLASS_B_NET 1
#define DHCPS_DEBUG 0
#define DHCPS_STATE_OFFER 1
#define DHCPS_STATE_DECLINE 2
#define DHCPS_STATE_ACK 3
#define DHCPS_STATE_NAK 4
#define DHCPS_STATE_IDLE 5
void dhcps_start(struct ip_info *info);
void dhcps_stop(void);
#endif
#ifndef __DHCPS_H__
#define __DHCPS_H__
#define USE_DNS
typedef struct dhcps_state{
sint16_t state;
} dhcps_state;
// ����dhcpclient�Զ����һ��DHCP msg�ṹ��
typedef struct dhcps_msg {
uint8_t op, htype, hlen, hops;
uint8_t xid[4];
uint16_t secs, flags;
uint8_t ciaddr[4];
uint8_t yiaddr[4];
uint8_t siaddr[4];
uint8_t giaddr[4];
uint8_t chaddr[16];
uint8_t sname[64];
uint8_t file[128];
uint8_t options[312];
}dhcps_msg;
#ifndef LWIP_OPEN_SRC
struct dhcps_lease {
bool enable;
struct ip_addr start_ip;
struct ip_addr end_ip;
};
enum dhcps_offer_option{
OFFER_START = 0x00,
OFFER_ROUTER = 0x01,
OFFER_END
};
#endif
struct dhcps_pool{
struct ip_addr ip;
uint8 mac[6];
uint32 lease_timer;
};
typedef struct _list_node{
void *pnode;
struct _list_node *pnext;
}list_node;
extern uint32 dhcps_lease_time;
#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0
#define DHCPS_MAX_LEASE 0x64
#define BOOTP_BROADCAST 0x8000
#define DHCP_REQUEST 1
#define DHCP_REPLY 2
#define DHCP_HTYPE_ETHERNET 1
#define DHCP_HLEN_ETHERNET 6
#define DHCP_MSG_LEN 236
#define DHCPS_SERVER_PORT 67
#define DHCPS_CLIENT_PORT 68
#define DHCPDISCOVER 1
#define DHCPOFFER 2
#define DHCPREQUEST 3
#define DHCPDECLINE 4
#define DHCPACK 5
#define DHCPNAK 6
#define DHCPRELEASE 7
#define DHCP_OPTION_SUBNET_MASK 1
#define DHCP_OPTION_ROUTER 3
#define DHCP_OPTION_DNS_SERVER 6
#define DHCP_OPTION_REQ_IPADDR 50
#define DHCP_OPTION_LEASE_TIME 51
#define DHCP_OPTION_MSG_TYPE 53
#define DHCP_OPTION_SERVER_ID 54
#define DHCP_OPTION_INTERFACE_MTU 26
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY 31
#define DHCP_OPTION_BROADCAST_ADDRESS 28
#define DHCP_OPTION_REQ_LIST 55
#define DHCP_OPTION_END 255
//#define USE_CLASS_B_NET 1
#define DHCPS_DEBUG 0
#define MAX_STATION_NUM 8
#define DHCPS_STATE_OFFER 1
#define DHCPS_STATE_DECLINE 2
#define DHCPS_STATE_ACK 3
#define DHCPS_STATE_NAK 4
#define DHCPS_STATE_IDLE 5
#define DHCPS_STATE_RELEASE 6
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
void dhcps_start(struct ip_info *info);
void dhcps_stop(void);
#endif
......@@ -21,7 +21,8 @@ typedef void (* espconn_reconnect_callback)(void *arg, sint8 err);
#define ESPCONN_MEM -1 /* Out of memory error. */
#define ESPCONN_TIMEOUT -3 /* Timeout. */
#define ESPCONN_RTE -4 /* Routing problem. */
#define ESPCONN_INPROGRESS -5 /* Operation in progress */
#define ESPCONN_INPROGRESS -5 /* Operation in progress */
#define ESPCONN_MAXNUM -7 /* Total number exceeds the set maximum*/
#define ESPCONN_ABRT -8 /* Connection aborted. */
#define ESPCONN_RST -9 /* Connection reset. */
......@@ -29,8 +30,13 @@ typedef void (* espconn_reconnect_callback)(void *arg, sint8 err);
#define ESPCONN_CONN -11 /* Not connected. */
#define ESPCONN_ARG -12 /* Illegal argument. */
#define ESPCONN_IF -14 /* Low_level error */
#define ESPCONN_ISCONN -15 /* Already connected. */
#define ESPCONN_HANDSHAKE -28 /* ssl handshake failed */
#define ESPCONN_RESP_TIMEOUT -29 /* ssl handshake no response*/
#define ESPCONN_PROTO_MSG -61 /* ssl application invalid */
#define ESPCONN_SSL 0x01
#define ESPCONN_NORM 0x00
......@@ -69,6 +75,7 @@ typedef struct _esp_tcp {
espconn_connect_callback connect_callback;
espconn_reconnect_callback reconnect_callback;
espconn_connect_callback disconnect_callback;
espconn_connect_callback write_finish_fn;
} esp_tcp;
typedef struct _esp_udp {
......@@ -106,34 +113,107 @@ struct espconn {
};
enum espconn_option{
ESPCONN_REUSEADDR = 1,
ESPCONN_START = 0x00,
ESPCONN_REUSEADDR = 0x01,
ESPCONN_NODELAY = 0x02,
ESPCONN_COPY = 0x04,
ESPCONN_KEEPALIVE = 0x08,
ESPCONN_END
};
enum espconn_level{
ESPCONN_KEEPIDLE,
ESPCONN_KEEPINTVL,
ESPCONN_KEEPCNT
};
struct espconn_packet{
uint16 sent_length; /* sent length successful*/
uint16 snd_buf_size; /* Available buffer size for sending */
uint16 snd_queuelen; /* Available buffer space for sending */
uint16 total_queuelen; /* total Available buffer space for sending */
uint32 packseqno; /* seqno to be sent */
uint32 packseq_nxt; /* seqno expected */
uint32 packnum;
};
typedef struct _espconn_buf{
uint8 *payload;
uint8 *punsent;
uint16 unsent;
uint16 len;
uint16 tot_len;
struct _espconn_buf *pnext;
} espconn_buf;
typedef struct _comon_pkt{
void *pcb;
int remote_port;
uint8 remote_ip[4];
uint8 *ptrbuf;
uint32 local_port;
uint32 local_ip;
espconn_buf *pbuf;
espconn_buf *ptail;
uint8* ptrbuf;
uint16 cntr;
uint16 write_len;
uint16 write_total;
sint8 err;
uint32 timeout;
uint32 recv_check;
uint8 pbuf_num;
struct espconn_packet packet_info;
bool write_flag;
enum espconn_option espconn_opt;
os_timer_t ptimer;
}comon_pkt;
typedef struct _espconn_msg{
struct espconn *pespconn;
comon_pkt pcommon;
uint8 count_opt;
int16_t hs_status; //the status of the handshake
void *preverse;
void *pssl;
struct _espconn_msg *pnext;
//***********Code for WIFI_BLOCK from upper**************
uint8 recv_hold_flag;
uint16 recv_holded_buf_Len;
}espconn_msg;
#ifndef _MDNS_INFO
#define _MDNS_INFO
struct mdns_info {
char *host_name;
char *server_name;
uint16 server_port;
unsigned long ipAddr;
char *txt_data[10];
};
#endif
#define linkMax 15
#define espconn_delay_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_NODELAY) != 0)
#define espconn_delay_enabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_NODELAY) == 0)
#define espconn_reuse_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_REUSEADDR) != 0)
#define espconn_copy_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_COPY) != 0)
#define espconn_copy_enabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_COPY) == 0)
#define espconn_keepalive_disabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_KEEPALIVE) != 0)
#define espconn_keepalive_enabled(espconn) (((espconn)->pcommon.espconn_opt & ESPCONN_KEEPALIVE) == 0)
#define espconn_TaskPrio 26
#define espconn_TaskQueueLen 15
enum espconn_sig {
SIG_ESPCONN_NONE,
SIG_ESPCONN_ERRER,
SIG_ESPCONN_LISTEN,
SIG_ESPCONN_CONNECT,
SIG_ESPCONN_WRITE,
SIG_ESPCONN_SEND,
SIG_ESPCONN_READ,
SIG_ESPCONN_CLOSE
};
/******************************************************************************
* FunctionName : espconn_copy_partial
* Description : reconnect with host
......@@ -181,6 +261,16 @@ bool espconn_find_connection(struct espconn *pespconn, espconn_msg **pnode);
sint8 espconn_get_connection_info(struct espconn *pespconn, remot_info **pcon_info, uint8 typeflags);
/******************************************************************************
* FunctionName : espconn_get_packet_info
* Description : get the packet info with host
* Parameters : espconn -- the espconn used to disconnect the connection
* infoarg -- the packet info
* Returns : the errur code
*******************************************************************************/
sint8 espconn_get_packet_info(struct espconn *espconn, struct espconn_packet* infoarg);
/******************************************************************************
* FunctionName : espconn_connect
* Description : The function given as the connect
......@@ -226,6 +316,23 @@ extern sint8 espconn_accept(struct espconn *espconn);
extern sint8 espconn_create(struct espconn *espconn);
/******************************************************************************
* FunctionName : espconn_tcp_get_wnd
* Description : get the window size of simulatenously active TCP connections
* Parameters : none
* Returns : the number of TCP_MSS active TCP connections
*******************************************************************************/
extern uint8 espconn_tcp_get_wnd(void);
/******************************************************************************
* FunctionName : espconn_tcp_set_max_con
* Description : set the window size simulatenously active TCP connections
* Parameters : num -- the number of TCP_MSS
* Returns : ESPCONN_ARG -- Illegal argument
* ESPCONN_OK -- No error
*******************************************************************************/
extern sint8 espconn_tcp_set_wnd(uint8 num);
/******************************************************************************
* FunctionName : espconn_tcp_get_max_con
* Description : get the number of simulatenously active TCP connections
......@@ -243,6 +350,42 @@ extern uint8 espconn_tcp_get_max_con(void);
*******************************************************************************/
extern sint8 espconn_tcp_set_max_con(uint8 num);
/******************************************************************************
* FunctionName : espconn_tcp_get_max_retran
* Description : get the Maximum number of retransmissions of data active TCP connections
* Parameters : none
* Returns : the Maximum number of retransmissions
*******************************************************************************/
extern uint8 espconn_tcp_get_max_retran(void);
/******************************************************************************
* FunctionName : espconn_tcp_set_max_retran
* Description : set the Maximum number of retransmissions of data active TCP connections
* Parameters : num -- the Maximum number of retransmissions
* Returns : result
*******************************************************************************/
extern sint8 espconn_tcp_set_max_retran(uint8 num);
/******************************************************************************
* FunctionName : espconn_tcp_get_max_syn
* Description : get the Maximum number of retransmissions of SYN segments
* Parameters : none
* Returns : the Maximum number of retransmissions
*******************************************************************************/
extern uint8 espconn_tcp_get_max_syn(void);
/******************************************************************************
* FunctionName : espconn_tcp_set_max_syn
* Description : set the Maximum number of retransmissions of SYN segments
* Parameters : num -- the Maximum number of retransmissions
* Returns : result
*******************************************************************************/
extern sint8 espconn_tcp_set_max_syn(uint8 num);
/******************************************************************************
* FunctionName : espconn_tcp_get_max_con_allow
* Description : get the count of simulatenously active connections on the server
......@@ -261,6 +404,16 @@ extern sint8 espconn_tcp_get_max_con_allow(struct espconn *espconn);
extern sint8 espconn_tcp_set_max_con_allow(struct espconn *espconn, uint8 num);
/******************************************************************************
* FunctionName : espconn_tcp_set_buf_count
* Description : set the total number of espconn_buf on the unsent lists
* Parameters : espconn -- espconn to set the count
* num -- the total number of espconn_buf
* Returns : result
*******************************************************************************/
extern sint8 espconn_tcp_set_buf_count(struct espconn *espconn, uint8 num);
/******************************************************************************
* FunctionName : espconn_regist_time
* Description : used to specify the time that should be called when don't recv data
......@@ -283,6 +436,17 @@ extern sint8 espconn_regist_time(struct espconn *espconn, uint32 interval, uint8
extern sint8 espconn_regist_sentcb(struct espconn *espconn, espconn_sent_callback sent_cb);
/******************************************************************************
* FunctionName : espconn_regist_sentcb
* Description : Used to specify the function that should be called when data
* has been successfully delivered to the remote host.
* Parameters : espconn -- espconn to set the sent callback
* sent_cb -- sent callback function to call for this espconn
* when data is successfully sent
* Returns : none
*******************************************************************************/
extern sint8 espconn_regist_write_finish(struct espconn *espconn, espconn_connect_callback write_finish_fn);
/******************************************************************************
* FunctionName : espconn_sent
* Description : sent data for client or server
......@@ -356,6 +520,27 @@ extern uint32 espconn_port(void);
*******************************************************************************/
extern sint8 espconn_set_opt(struct espconn *espconn, uint8 opt);
/******************************************************************************
* FunctionName : espconn_set_keepalive
* Description : access level value for connection so that we set the value for
* keep alive
* Parameters : espconn -- the espconn used to set the connection
* level -- the connection's level
* value -- the value of time(s)
* Returns : access port value
*******************************************************************************/
extern sint8 espconn_set_keepalive(struct espconn *espconn, uint8 level, void* optarg);
/******************************************************************************
* FunctionName : espconn_get_keepalive
* Description : access level value for connection so that we get the value for
* keep alive
* Parameters : espconn -- the espconn used to get the connection
* level -- the connection's level
* Returns : access keep alive value
*******************************************************************************/
extern sint8 espconn_get_keepalive(struct espconn *espconn, uint8 level, void *optarg);
/******************************************************************************
* FunctionName : espconn_gethostbyname
* Description : Resolve a hostname (string) into an IP address.
......@@ -395,20 +580,85 @@ extern sint8 espconn_igmp_join(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
extern sint8 espconn_igmp_leave(ip_addr_t *host_ip, ip_addr_t *multicast_ip);
/******************************************************************************
* FunctionName : espconn_recv_hold
* Description : hold tcp receive
* Parameters : espconn -- espconn to hold
* FunctionName : espconn_mdns_init
* Description : register a device with mdns
* Parameters : ipAddr -- the ip address of device
* hostname -- the hostname of device
* Returns : none
*******************************************************************************/
extern sint8 espconn_recv_hold(struct espconn *pespconn);
extern void espconn_mdns_init(struct mdns_info *info);
/******************************************************************************
* FunctionName : espconn_recv_unhold
* Description : unhold tcp receive
* Parameters : espconn -- espconn to unhold
* FunctionName : espconn_mdns_init
* Description : close mdns socket
* Parameters : void
* Returns : none
*******************************************************************************/
extern sint8 espconn_recv_unhold(struct espconn *pespconn);
extern void espconn_mdns_close(void);
/******************************************************************************
* FunctionName : mdns_server_register
* Description : register a server and join a multicast group
* Parameters : none
* Returns : none
*******************************************************************************/
extern void espconn_mdns_server_register(void);
/******************************************************************************
* FunctionName : mdns_server_register
* Description : unregister server and leave multicast group
* Parameters : none
* Returns : none
*******************************************************************************/
extern void espconn_mdns_server_unregister(void);
/******************************************************************************
* FunctionName : espconn_mdns_get_servername
* Description : get server name
* Parameters : none
* Returns : server name
*******************************************************************************/
extern char* espconn_mdns_get_servername(void);
/******************************************************************************
* FunctionName : espconn_mdns_get_servername
* Description : set server name
* Parameters : server name
* Returns : none
*******************************************************************************/
extern void espconn_mdns_set_servername(const char *name);
/******************************************************************************
* FunctionName : espconn_mdns_set_hostname
* Description : set host name
* Parameters : host name
* Returns : none
*******************************************************************************/
extern void espconn_mdns_set_hostname(char *name);
/******************************************************************************
* FunctionName : espconn_mdns_init
* Description : get host name
* Parameters : void
* Returns : hostname
*******************************************************************************/
extern char* espconn_mdns_get_hostname(void);
/******************************************************************************
* FunctionName : espconn_mdns_disable
* Description : join a multicast group
* Parameters : host_ip -- the ip address of udp server
* multicast_ip -- multicast ip given by user
* Returns : none
*******************************************************************************/
extern void espconn_mdns_disable(void);
/******************************************************************************
* FunctionName : espconn_mdns_enable
* Description : enable mdns
* Parameters : void
* Returns : none
*******************************************************************************/
extern void espconn_mdns_enable(void);
/******************************************************************************
* FunctionName : espconn_dns_setserver
* Description : Initialize one of the DNS servers.
* Parameters : numdns -- the index of the DNS server to set must
* be < DNS_MAX_SERVERS = 2
* dnsserver -- IP address of the DNS server to set
* Returns : none
*******************************************************************************/
extern void espconn_dns_setserver(u8_t numdns, ip_addr_t *dnsserver);
#endif
#ifndef __ESPCONN_TCP_H__
#define __ESPCONN_TCP_H__
#ifndef ESPCONN_TCP_DEBUG
#define ESPCONN_TCP_DEBUG LWIP_DBG_OFF
#endif
#include "lwip/app/espconn.h"
#ifndef ESPCONN_TCP_TIMER
#define ESPCONN_TCP_TIMER 40
#endif
/******************************************************************************
* FunctionName : espconn_tcp_disconnect
* Description : A new incoming connection has been disconnected.
* Parameters : espconn -- the espconn used to disconnect with host
* Returns : none
*******************************************************************************/
extern void espconn_tcp_disconnect(espconn_msg *pdiscon);
/******************************************************************************
* FunctionName : espconn_tcp_client
* Description : Initialize the client: set up a connect PCB and bind it to
* the defined port
* Parameters : espconn -- the espconn used to build client
* Returns : none
*******************************************************************************/
extern sint8 espconn_tcp_client(struct espconn* espconn);
/******************************************************************************
* FunctionName : espconn_tcp_server
* Description : Initialize the server: set up a listening PCB and bind it to
* the defined port
* Parameters : espconn -- the espconn used to build server
* Returns : none
*******************************************************************************/
extern sint8 espconn_tcp_server(struct espconn *espconn);
#endif /* __CLIENT_TCP_H__ */
#ifndef __ESPCONN_TCP_H__
#define __ESPCONN_TCP_H__
#ifndef ESPCONN_TCP_DEBUG
#define ESPCONN_TCP_DEBUG LWIP_DBG_OFF
#endif
#include "lwip/app/espconn.h"
#ifndef ESPCONN_TCP_TIMER
#define ESPCONN_TCP_TIMER 40
#endif
#define espconn_keepalive_enable(pcb) ((pcb)->so_options |= SOF_KEEPALIVE)
#define espconn_keepalive_disable(pcb) ((pcb)->so_options &= ~SOF_KEEPALIVE)
/******************************************************************************
* FunctionName : espconn_kill_oldest_pcb
* Description : A oldest incoming connection has been killed.
* Parameters : none
* Returns : none
*******************************************************************************/
extern void espconn_kill_oldest_pcb(void);
/******************************************************************************
* FunctionName : espconn_tcp_disconnect
* Description : A new incoming connection has been disconnected.
* Parameters : espconn -- the espconn used to disconnect with host
* Returns : none
*******************************************************************************/
extern void espconn_tcp_disconnect(espconn_msg *pdiscon);
/******************************************************************************
* FunctionName : espconn_tcp_client
* Description : Initialize the client: set up a connect PCB and bind it to
* the defined port
* Parameters : espconn -- the espconn used to build client
* Returns : none
*******************************************************************************/
extern sint8 espconn_tcp_client(struct espconn* espconn);
/******************************************************************************
* FunctionName : espconn_tcp_server
* Description : Initialize the server: set up a listening PCB and bind it to
* the defined port
* Parameters : espconn -- the espconn used to build server
* Returns : none
*******************************************************************************/
extern sint8 espconn_tcp_server(struct espconn *espconn);
#endif /* __CLIENT_TCP_H__ */
#ifndef __ESPCONN_UDP_H__
#define __ESPCONN_UDP_H__
#ifndef ESPCONN_UDP_DEBUG
#define ESPCONN_UDP_DEBUG LWIP_DBG_OFF
#endif
#include "lwip/app/espconn.h"
/******************************************************************************
* FunctionName : espconn_udp_client
* Description : Initialize the client: set up a PCB and bind it to the port
* Parameters : pespconn -- the espconn used to build client
* Returns : none
*******************************************************************************/
extern sint8 espconn_udp_client(struct espconn *pespconn);
/******************************************************************************
* FunctionName : espconn_udp_disconnect
* Description : A new incoming connection has been disconnected.
* Parameters : espconn -- the espconn used to disconnect with host
* Returns : none
*******************************************************************************/
extern void espconn_udp_disconnect(espconn_msg *pdiscon);
/******************************************************************************
* FunctionName : espconn_udp_server
* Description : Initialize the server: set up a PCB and bind it to the port
* Parameters : pespconn -- the espconn used to build server
* Returns : none
*******************************************************************************/
extern sint8 espconn_udp_server(struct espconn *espconn);
/******************************************************************************
* FunctionName : espconn_udp_sent
* Description : sent data for client or server
* Parameters : void *arg -- client or server to send
* uint8* psent -- Data to send
* uint16 length -- Length of data to send
* Returns : none
*******************************************************************************/
extern void espconn_udp_sent(void *arg, uint8 *psent, uint16 length);
#endif /* __ESPCONN_UDP_H__ */
#ifndef __ESPCONN_UDP_H__
#define __ESPCONN_UDP_H__
#ifndef ESPCONN_UDP_DEBUG
#define ESPCONN_UDP_DEBUG LWIP_DBG_OFF
#endif
#include "lwip/app/espconn.h"
/******************************************************************************
* FunctionName : espconn_udp_client
* Description : Initialize the client: set up a PCB and bind it to the port
* Parameters : pespconn -- the espconn used to build client
* Returns : none
*******************************************************************************/
extern sint8 espconn_udp_client(struct espconn *pespconn);
/******************************************************************************
* FunctionName : espconn_udp_disconnect
* Description : A new incoming connection has been disconnected.
* Parameters : espconn -- the espconn used to disconnect with host
* Returns : none
*******************************************************************************/
extern void espconn_udp_disconnect(espconn_msg *pdiscon);
/******************************************************************************
* FunctionName : espconn_udp_server
* Description : Initialize the server: set up a PCB and bind it to the port
* Parameters : pespconn -- the espconn used to build server
* Returns : none
*******************************************************************************/
extern sint8 espconn_udp_server(struct espconn *espconn);
/******************************************************************************
* FunctionName : espconn_udp_sent
* Description : sent data for client or server
* Parameters : void *arg -- client or server to send
* uint8* psent -- Data to send
* uint16 length -- Length of data to send
* Returns : none
*******************************************************************************/
extern err_t espconn_udp_sent(void *arg, uint8 *psent, uint16 length);
/******************************************************************************
* FunctionName : espconn_udp_sendto
* Description : sent data for UDP
* Parameters : void *arg -- UDP to send
* uint8* psent -- Data to send
* uint16 length -- Length of data to send
* Returns : return espconn error code.
* - ESPCONN_OK. Successful. No error occured.
* - ESPCONN_MEM. Out of memory.
* - ESPCONN_RTE. Could not find route to destination address.
* - More errors could be returned by lower protocol layers.
*******************************************************************************/
extern err_t espconn_udp_sendto(void *arg, uint8 *psent, uint16 length);
#endif /* __ESPCONN_UDP_H__ */
......@@ -207,6 +207,15 @@ void dhcp_fine_tmr(void);
#define DHCP_OPTION_TCP_TTL 37
#define DHCP_OPTION_END 255
/**add options for support more router by liuHan**/
#define DHCP_OPTION_DOMAIN_NAME 15
#define DHCP_OPTION_PRD 31
#define DHCP_OPTION_STATIC_ROUTER 33
#define DHCP_OPTION_VSN 43
#define DHCP_OPTION_NB_TINS 44
#define DHCP_OPTION_NB_TINT 46
#define DHCP_OPTION_NB_TIS 47
#define DHCP_OPTION_CLASSLESS_STATIC_ROUTER 121
/** DHCP options */
#define DHCP_OPTION_REQUESTED_IP 50 /* RFC 2132 9.1, requested IP address */
#define DHCP_OPTION_LEASE_TIME 51 /* RFC 2132 9.2, time in seconds, in 4 bytes */
......
......@@ -96,7 +96,7 @@ void igmp_input(struct pbuf *p, struct netif *inp, ip_addr_t *dest)ICACHE_FLAS
err_t igmp_joingroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
err_t igmp_leavegroup(ip_addr_t *ifaddr, ip_addr_t *groupaddr)ICACHE_FLASH_ATTR;
void igmp_tmr(void)ICACHE_FLASH_ATTR;
#define LWIP_RAND() rand()
#define LWIP_RAND() r_rand()
#ifdef __cplusplus
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment