diff --git a/.gitmodules b/.gitmodules index fde876f64f..f0eae41c30 100644 --- a/.gitmodules +++ b/.gitmodules @@ -24,3 +24,6 @@ path = Sming/third-party/umm_malloc url = https://github.com/rhempel/umm_malloc.git ignore = dirty +[submodule "Sming/third-party/esp-open-lwip"] + path = Sming/third-party/esp-open-lwip + url = https://github.com/pfalcon/esp-open-lwip.git diff --git a/.travis.yml b/.travis.yml index cfad6db21d..a428ad2054 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,17 @@ sudo: false language: cpp -os: - - linux - - osx + env: global: - SDK_BUILD=258 - matrix: - - SDK_VERSION=1.4.0 - - SDK_VERSION=1.5.0 + +matrix: + include: + - os: linux + env: SDK_VERSION=1.5.0 + - os: linux + env: SDK_VERSION=2.0.0 + git: submodules: false addons: @@ -18,28 +21,31 @@ addons: packages: - bsdtar install: - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"; fi + - if [ "$SDK_VERSION" != "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "osx" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-macos-x86_64.zip"; fi + - if [ "$SDK_VERSION" != "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export SDK_FILE_NAME="esp-alt-sdk-v${SDK_VERSION}.${SDK_BUILD}-linux-x86_64.tar.gz"; fi - mkdir -p $TRAVIS_BUILD_DIR/opt/esp-alt-sdk - - wget https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME} - - bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk + - if [ "$SDK_VERSION" != "2.0.0" ]; then wget https://bintray.com/artifact/download/kireevco/generic/${SDK_FILE_NAME}; fi + - if [ "$SDK_VERSION" != "2.0.0" ]; then bsdtar -xf ${SDK_FILE_NAME} -C $TRAVIS_BUILD_DIR/opt/esp-alt-sdk; fi + - if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then wget https://github.com/nodemcu/nodemcu-firmware/raw/master/tools/esp-open-sdk.tar.xz; tar -Jxvf esp-open-sdk.tar.xz; ln -s `pwd`/esp-open-sdk/xtensa-lx106-elf $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/. ; fi + - if [ "$SDK_VERSION" == "2.0.0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then wget http://bbs.espressif.com/download/file.php?id=1690 -O sdk.zip; unzip sdk.zip; ln -s `pwd`/ESP8266_NONOS_SDK/ $TRAVIS_BUILD_DIR/opt/esp-alt-sdk/sdk; fi script: - export CHANGED_FILES=`git diff --diff-filter=AMD HEAD HEAD^ --name-only` - export CHANGED_PROJECTS=`for i in $CHANGED_FILES; do echo "$i" | grep '^samples/' | cut -d'/' -f2; done | uniq` - export SMING_HOME=$TRAVIS_BUILD_DIR/Sming - export ESP_HOME=$TRAVIS_BUILD_DIR/opt/esp-alt-sdk - - export PATH=$PATH:$TRAVIS_BUILD_DIR/opt/esp-alt-sdk/utils/ + - export PATH=$PATH:$ESP_HOME/xtensa-lx106-elf/bin:$ESP_HOME/utils/:$SMING_HOME/../.travis/tools - cd $SMING_HOME - - make test + - make test - cd $SMING_HOME/../ - export SMING_HAS_CHANGED=`for i in $CHANGED_FILES; do if [[ $i == Sming/* ]]; then echo 1; break; fi; done` - if [ ! -z "$SMING_HAS_CHANGED" ]; then CHANGED_PROJECTS=`cd $SMING_HOME/../samples; ls -d *`; fi - for i in $CHANGED_PROJECTS; do echo "Compiling $i"; make -C "samples/$i"; if [ $? -ne 0 ]; then exit 1; fi; done - cd $SMING_HOME - - make clean + - make clean samples-clean - make ENABLE_GDB=1 - make Basic_Debug - - make clean + - make clean samples-clean - make ENABLE_CUSTOM_HEAP=1 - - make -C $SMING_HOME/../samples/Basic_Blink clean - make Basic_Blink ENABLE_CUSTOM_HEAP=1 + - make clean samples-clean + - make ENABLE_CUSTOM_LWIP=1; make samples ENABLE_CUSTOM_LWIP=1 diff --git a/.travis/tools/esptool2 b/.travis/tools/esptool2 new file mode 100755 index 0000000000..7de8b1f191 Binary files /dev/null and b/.travis/tools/esptool2 differ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8c57a58206..c376349a59 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,18 +1,104 @@ # Contributing to Sming Framework -All contributions (PRs) to Sming Framework have to be done to _develop_ branch. -If a feature or bugfix is a major change please contact Sming team to prepare feature specific handling. +All contributions (PRs) to Sming Framework have to be done to the _develop_ branch. __master__: Branch that contains latest production (stable) release. No PRs other than Final Release updates will be merged into __master__. __develop__: Main development branch: contains all current new features. -This will mean that __all contributors__ will have to submit a PR to a _develop_ , it will be tested and then merged to __develop__ for automated integration testing (via TravisCI, Jenkins or SemaphoreCI), as well as manual testing on a real device. +This means that __all contributors__ will have to submit a PR to a _develop_ , it will be tested and then merged to __develop__ for automated integration testing (via TravisCI, Jenkins or SemaphoreCI), as well as manual testing on a real device. __Sming Contributing flow__: -- Fork _Sming_ repo -- Create a branch off the _develop_: __MyNewFeature__ +- Fork [_Sming_ repo](https://github.com/SmingHub/Sming#fork-destination-box) + +After that clone your own fork. + +`git clone https://github.com//Sming.git` + +- Create a new branch off the _develop_ branch + +``` +cd Sming +git checkout develop +git branch feature/ +git checkout feature/ +``` + +Make sure to replace `short-explanation` with one or two words describing the purpose of the feature. +If you want to commit a fix use `fix/` as prefix for your branch name. + - Build, test your code + +Make sure that your code compiles and it is tested on real device. Sometimes you will be asked for a proof (usually screenshot) that it was tested on your device(s). + - Commit changes + +``` +git add +git commit -m "" +``` + - Push your changes to your fork on github + +``` +git push +``` + +- Rebase if needed + +If your branch cannot be merged automatically because there are new changes in the official __develop__ +branch that conflict with yours then make sure to rebase your branch. The following steps can help +you do this. + +First step: +You will need to add the `upstream` repository. This step should be executed ONLY once. + +``` +cd Sming +git remote add upstream https://github.com/SmingHub/Sming.git +git fetch upstream develop +git checkout develop +git reset --hard upstream/develop +``` + +Second step: +If you have already defined `upstream` repository and synchronized your `develop` branch to fetch the updates +from `upstream` ( the commands above do this) the next step is to get the latest changes from the official `develop` branch. + +This can be done using + +``` +cd Sming +git checkout develop +git pull +``` + +Final step: +Now you are ready to merge the latest changes from official `develop` branch into your branch and place your changes on top. +The commands below help you achieve this. + +``` +cd Sming +git checkout develop +git pull develop +git checkout feature/ +git merge develop +# Fix any merge conflicts if needed. +git rebase develop +# Fix any merge conflicts if needed. +``` + +If there were merge conflicts you will have to resolve them locally. This usually involves calling the following commands: + +``` +git mergetool +# After resolving conflicts you should type the command below to see what are the next steps +# Newer versions of `git` are kind enough to show hints +git status +``` + +After that operation you should have a branch that has all latest changes from __develop__ +with your changes on top. + + - Submit PR to the main Sming repo, __develop__ branch. - Work with other contributors to test your feature and get it merged to _develop_ diff --git a/Readme.md b/Readme.md index 87a85d79c3..5d5579e589 100644 --- a/Readme.md +++ b/Readme.md @@ -28,7 +28,19 @@ Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native develo * [SNI](https://tools.ietf.org/html/rfc6066#page-6) and [Maximum Fragment Length](https://tools.ietf.org/html/rfc6066#page-8) SSL support. * Optional alternative PWM support based on [Stefan Bruens PWM](https://github.com/StefanBruens/ESP8266_new_pwm.git) * Optional custom heap allocation based on [Umm Malloc](https://github.com/rhempel/umm_malloc.git) -* Based on Espressif NONOS SDK. Tested with versions 1.4 and 1.5. +* Based on Espressif NONOS SDK. Tested with versions 1.4, 1.5 and 2.0. + +## Compatibility + +OS/SDK | Linux | Mac OS X | Windows | FreeBSD-current | +-------|-------|----------|---------|-----------------| +UDK (1.4, 1.5) | n/a | n/a | :sunny: | n/a | +esp-alt-sdk (1.4, 1.5) | :sunny: | :sunny: | :sunny: | :sunny: | :sunny: | +esp-open-sdk (1.4, 1.5, 2.0) | :sunny: | :sunny: | n/a | n/a | + +OS = Operating System +SDK = Software Development Kit +n/a = The selected SDK is not available on that OS ## Latest Release - [Sming V3.0.1](https://github.com/SmingHub/Sming/releases/tag/3.0.1) @@ -42,16 +54,14 @@ Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native develo ## Additional needed software - Spiffy : Source included in Sming repository -- [ESPtool2] (https://github.com/raburton/esptool2) esptool2 +- [ESPtool2](https://github.com/raburton/esptool2) esptool2 ## Optional features -- Custom PWM: If Sming is compiled with ENABLE_CUSTOM_PWM=1 then instead of using the Espressif SDK pwm library -a [custom PWM library](https://github.com/StefanBruens/ESP8266_new_pwm) will be used. -- SSL: The SSL support is not built-in by default to conserve resources. If you want to enable it then take a look at the [Readme](https://github.com/SmingHub/Sming/blob/develop/samples/Basic_Ssl/README.md) in the Basic_Ssl samples. -- Custom Heap Allocation: If your application is experiencing heap fragmentation then you can try the Umm Malloc heap allocation. To enable it compile -Sming with ENABLE_CUSTOM_HEAP=1. In order to use it in your sample/application make sure to compile the sample with ENABLE_CUSTOM_HEAP=1. Avoid enabling -your custom heap allocation AND -mforce-l32 compiler flag. - +- Custom LWIP:(default:ON) By default we are using custom compiled LWIP stack instead of the binary one provided from Espressif. This is increasing the free memory and decreasing the space on the flash. All espconn_* functions are turned off by default. If your application requires the use of some of the espconn_* functions then add the ENABLE_ESPCONN=1 directive. See `Makefile-user.mk` from the [Basic_SmartConfig](https://github.com/SmingHub/Sming/blob/develop/samples/Basic_SmartConfig/Makefile-user.mk#L41) application for examples. If you would like to use the binary LWIP then you should turn off the custom LWIP compilation by providing ENABLE_CUSTOM_LWIP=0. +- SSL:(default:off) The SSL support is not built-in by default to conserve resources. If you want to enable it then take a look at the [Readme](https://github.com/SmingHub/Sming/blob/develop/samples/Basic_Ssl/README.md) in the Basic_Ssl samples. +- Custom PWM:(default:off) If you want to use the [open PWM implementation](https://github.com/StefanBruens/ESP8266_new_pwm) then compile your application with ENABLE_CUSTOM_PWM=1. There is no need to recompile the Sming library. +- Custom serial baud rate: (default:off) The default serial baud rate is 115200. If you want to change it to a higher baud rate you can recompile Sming and your application changing the COM_SPEED_SERIAL directive. For example COM_SPEED_SERIAL=921600 +- Custom Heap Allocation:(default:off) If your application is experiencing heap fragmentation then you can try the Umm Malloc heap allocation. To enable it compile Sming with ENABLE_CUSTOM_HEAP=1. In order to use it in your sample/application make sure to compile the sample with ENABLE_CUSTOM_HEAP=1. Avoid enabling your custom heap allocation AND -mforce-l32 compiler flag. You can find more information about compilation and flashing process by reading esp8266.com forum discussion thread. diff --git a/Sming/Libraries/AM2321/AM2321.cpp b/Sming/Libraries/AM2321/AM2321.cpp new file mode 100644 index 0000000000..3987b2bd26 --- /dev/null +++ b/Sming/Libraries/AM2321/AM2321.cpp @@ -0,0 +1,195 @@ +// +// AM2321 Temperature & Humidity Sensor library for Arduino +// +// The MIT License (MIT) +// +// Copyright (c) 2013 Wang Dong +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#include "AM2321.h" +#include + +#define I2C_ADDR_AM2321 (0xB8 >> 1) //AM2321温湿度计I2C地址 +#define PARAM_AM2321_READ 0x03 //读寄存器命令 +#define REG_AM2321_HUMIDITY_MSB 0x00 //湿度寄存器高位 +#define REG_AM2321_HUMIDITY_LSB 0x01 //湿度寄存器低位 +#define REG_AM2321_TEMPERATURE_MSB 0x02 //温度寄存器高位 +#define REG_AM2321_TEMPERATURE_LSB 0x03 //温度寄存器低位 +#define REG_AM2321_DEVICE_ID_BIT_24_31 0x0B //32位设备ID高8位 + +template +class DataReader { +protected: + enum { len = 32 }; + uint8_t buf[len]; + +protected: + DataReader() { + memset(buf, 0, len); + } + bool readRaw() { + // + // Wakeup + // + Wire.beginTransmission(I2CADDR); + Wire.endTransmission(); + delayMicroseconds(2000); + + Wire.beginTransmission(I2CADDR); + Wire.endTransmission(); + delayMicroseconds(2000); + + noInterrupts(); + // + // Read Command + // + Wire.beginTransmission(I2CADDR); + Wire.write(COMMAND); + Wire.write(REGADDR); + Wire.write(REGCOUNT); + if (Wire.endTransmission() != 0) + { + interrupts(); + debugf("AM2321: Read request failed"); + return false; + } + + // + // Waiting + // + delayMicroseconds(2000); + + // + // Read + // + // COMMAND + REGCOUNT + DATA + CRCLSB + CRCMSB + if (!Wire.requestFrom(I2CADDR, 2 + REGCOUNT + 2)) + { + interrupts(); + debugf("AM2321: Reading failed"); + return false; + } + + int i = 0; + for (; i < 2 + REGCOUNT; ++i) + buf[i] = Wire.read(); + + unsigned short crc = 0; + crc = Wire.read(); //CRC LSB + crc |= Wire.read() << 8;//CRC MSB + + interrupts(); + + if (crc == crc16(buf, i)) + return true; + + debugf("AM2321: CRC check failed: %d, %d", crc, crc16(buf, i)); + return false; + } + +private: + unsigned short crc16(unsigned char *ptr, unsigned char len) { + unsigned short crc = 0xFFFF; + unsigned char i = 0; + while(len--) { + crc ^= *ptr++; + for(i = 0 ; i < 8 ; i++) { + if(crc & 0x01) { + crc >>= 1; + crc ^= 0xA001; + } + else { + crc >>= 1; + } + } + } + return crc; + } +}; + +class UidReader : public DataReader +{ +public: + unsigned int uid; +public: + bool read() { + if(!readRaw()) + return false; + uid = buf[2] << 24; + uid += buf[3] << 16; + uid += buf[4] << 8; + uid += buf[5]; + return true; + } +}; + +class AirConditionReader : public DataReader +{ +public: + unsigned int humidity; + int temperature; +public: + bool read() { + if(!readRaw()) + return false; + humidity = buf[2] << 8; + humidity += buf[3]; + temperature = buf[4] << 8; + temperature += buf[5]; + return true; + } +}; + + +AM2321::AM2321() { + temperature = 0; + humidity = 0; +} + +void AM2321::begin() +{ + Wire.begin(); +} + +uint32_t AM2321::uid() { + UidReader reader; + if (reader.read()) + return reader.uid; + return -1; +} + + +bool AM2321::available() { + return !(temperature == 0 && humidity == 0); +} + +bool AM2321::read() { + AirConditionReader reader; + if (reader.read()) { + temperature = reader.temperature; + humidity = reader.humidity; + return true; + } + return false; +} +// +// END OF FILE +// diff --git a/Sming/Libraries/AM2321/AM2321.h b/Sming/Libraries/AM2321/AM2321.h new file mode 100644 index 0000000000..c07955b88f --- /dev/null +++ b/Sming/Libraries/AM2321/AM2321.h @@ -0,0 +1,58 @@ +// +// AM2321 Temperature & Humidity Sensor library for Arduino +// VERSION: 0.1.0 +// +// The MIT License (MIT) +// +// Copyright (c) 2013 Wang Dong +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +#ifndef __ARDUINO_AM2321_H__ +#define __ARDUINO_AM2321_H__ + +#include + +#define LIBAM2321_VERSION "0.1.0" + + +class AM2321 +{ +public: + int temperature; + unsigned int humidity; + +public: + void begin(); + bool read(); + bool available(); + +public: + uint32_t uid(); + +public: + AM2321(); +}; + + +#endif +// +// END OF FILE +// diff --git a/Sming/Libraries/AM2321/README.md b/Sming/Libraries/AM2321/README.md new file mode 100644 index 0000000000..03fadefe15 --- /dev/null +++ b/Sming/Libraries/AM2321/README.md @@ -0,0 +1,20 @@ +# AM2321 + +- AM2321 sensor support for Arduino. +- More: http://playground.arduino.cc/Main/AM2321 + +## Example: + + #include + + void readByAM2321() + { + AM2321 am2321; + am2321.read(); + + Serial.print("("); + Serial.print(am2321.temperature/10.0); + Serial.print(", "); + Serial.print(am2321.humidity/10.0); + Serial.println(')'); + } diff --git a/Sming/Libraries/AM2321/Weather.h b/Sming/Libraries/AM2321/Weather.h new file mode 100644 index 0000000000..4becca4343 --- /dev/null +++ b/Sming/Libraries/AM2321/Weather.h @@ -0,0 +1,53 @@ +#ifndef __H_ARDUINO_WEATHER__ +#define __H_ARDUINO_WEATHER__ + +namespace weather { + // Celsius to Fahrenheit conversion + inline + double fahrenheit(double celsius) { + return 1.8 * celsius + 32; + } + + // fast integer version with rounding + inline + int fahrenheitFast(int celcius) { + return (celcius * 18 + 5)/10 + 32; + } + + + // Celsius to Kelvin conversion + inline + double kelvin(double celsius) { + return celsius + 273.15; + } + + // dewPoint function NOAA + // reference: http://wahiduddin.net/calc/density_algorithms.htm + inline + double dewPoint(double celsius, double humidity) { + // RATIO was originally named A0, possibly confusing in Arduino context + double RATIO = 373.15 / (273.15 + celsius); + double SUM = -7.90298 * (RATIO - 1); + SUM += 5.02808 * log10(RATIO); + SUM += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ; + SUM += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ; + SUM += log10(1013.246); + double VP = pow(10, SUM - 3) * humidity; + double T = log(VP/0.61078); // temp var + return (241.88 * T) / (17.558 - T); + } + + // delta max = 0.6544 wrt dewPoint() + // 5x faster than dewPoint() + // reference: http://en.wikipedia.org/wiki/Dew_point + inline + double dewPointFast(double celsius, double humidity) { + double a = 17.271; + double b = 237.7; + double temp = (a * celsius) / (b + celsius) + log(humidity/100); + double Td = (b * temp) / (a - temp); + return Td; + } +}; + +#endif \ No newline at end of file diff --git a/Sming/Libraries/AM2321/examples/read_all/read_all.ino b/Sming/Libraries/AM2321/examples/read_all/read_all.ino new file mode 100644 index 0000000000..9b89dddfa6 --- /dev/null +++ b/Sming/Libraries/AM2321/examples/read_all/read_all.ino @@ -0,0 +1,22 @@ +#include +#include + +AM2321 ac; + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.print("("); + Serial.print(ac.read()); + Serial.print(","); + Serial.print(ac.temperature); + Serial.print(","); + Serial.print(ac.humidity); + Serial.println(")"); + delay(3000); + + Serial.println(ac.uid()); + delay(3000); +} diff --git a/Sming/Libraries/AM2321/keywords.txt b/Sming/Libraries/AM2321/keywords.txt new file mode 100644 index 0000000000..8c69463537 --- /dev/null +++ b/Sming/Libraries/AM2321/keywords.txt @@ -0,0 +1,19 @@ +####################################### +# Syntax Coloring Map For AM2321 +####################################### +# Datatypes (KEYWORD1) +####################################### + +AM2321 KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +read KEYWORD2 +available KEYWORD2 +uid KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/Sming/Libraries/DS18S20/ds18s20.cpp b/Sming/Libraries/DS18S20/ds18s20.cpp index 3c1331b1cc..99d5a4958f 100644 --- a/Sming/Libraries/DS18S20/ds18s20.cpp +++ b/Sming/Libraries/DS18S20/ds18s20.cpp @@ -150,6 +150,10 @@ void DS18S20::StartReadNext() { debugx(" DBG: DS18S20 reading task end"); InProgress=false; + if(readEndCallback) //If callback set, execute function + { + readEndCallback(); + } } } @@ -252,6 +256,15 @@ uint64_t DS18S20::GetSensorID(uint8_t index) uint8_t DS18S20::GetSensorsCount() { return numberOf; +} +void DS18S20::RegisterEndCallback(DS18S20CompletedDelegate callback) +{ + readEndCallback = callback; +} + +void DS18S20::UnRegisterCallback() +{ + readEndCallback = 0; } diff --git a/Sming/Libraries/DS18S20/ds18s20.h b/Sming/Libraries/DS18S20/ds18s20.h index 1532e47b97..1012188beb 100644 --- a/Sming/Libraries/DS18S20/ds18s20.h +++ b/Sming/Libraries/DS18S20/ds18s20.h @@ -22,13 +22,16 @@ #define ALARMSEARCH 0xEC // Query for alarm #define STARTCONVO 0x44 // temperature reading +typedef Delegate DS18S20CompletedDelegate; class DS18S20 { public: DS18S20(); - void Init(uint8_t); //call for OneWire init - void StartMeasure(); //Start measurement result after 1.2 seconds * number of sensors + void Init(uint8_t); //call for OneWire init + void StartMeasure(); //Start measurement result after 1.2 seconds * number of sensors + void RegisterEndCallback(DS18S20CompletedDelegate); //Add function called of conversion end - "interrupt" function of end conversion + void UnRegisterCallback(); //Unset conversion end function float GetCelsius(uint8_t); float GetFahrenheit(uint8_t); bool IsValidTemperature(uint8_t); @@ -54,6 +57,7 @@ class DS18S20 uint8_t numberOf=0; uint8_t numberOfread=0; + DS18S20CompletedDelegate readEndCallback; Timer DelaysTimer; diff --git a/Sming/Makefile b/Sming/Makefile index 703dc73880..b785fb5694 100644 --- a/Sming/Makefile +++ b/Sming/Makefile @@ -99,6 +99,16 @@ export COMPILE := gcc export PATH := $(ESP_HOME)/xtensa-lx106-elf/bin:$(PATH) XTENSA_TOOLS_ROOT := $(ESP_HOME)/xtensa-lx106-elf/bin +## COM port parameters +# Default COM port speed (generic) +COM_SPEED ?= 115200 + +# Default COM port speed (used for flashing) +COM_SPEED_ESPTOOL ?= $(COM_SPEED) + +# Default COM port speed (used in code) +COM_SPEED_SERIAL ?= $(COM_SPEED) + # Sming Framework Path SMF = $(SMING_HOME) @@ -150,13 +160,26 @@ ifeq ($(ENABLE_CUSTOM_HEAP), 1) CUSTOM_TARGETS += $(USER_LIBDIR)/libmainmm.a endif +# => Open Source LWIP +LIBLWIP = lwip +ENABLE_CUSTOM_LWIP ?= 1 +ENABLE_ESPCONN ?= 0 +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + THIRD_PARTY_DATA += third-party/esp-open-lwip/Makefile.open + EXTRA_INCDIR += third-party/esp-open-lwip/include + ifeq ($(ENABLE_ESPCONN), 1) + LIBLWIP = lwip_full + else + LIBLWIP = lwip_open + endif + CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBLWIP).a +endif + # libraries used in this project, mainly provided by the SDK USER_LIBDIR = compiler/lib -LIBS = microc microgcc hal phy pp net80211 lwip wpa main - +LIBS = microc microgcc hal phy pp net80211 $(LIBLWIP) wpa main ifeq ($(ENABLE_CUSTOM_PWM), 1) THIRD_PARTY_DATA += third-party/pwm/pwm.c - LIBS += pwm endif # compiler flags using during compilation of source files. Add '-pg' for debugging @@ -279,7 +302,7 @@ endef all: checkdirs $(APP_AR) spiffy ifeq ($(ENABLE_CUSTOM_PWM), 1) -$(USER_LIBDIR)/libpwm.a: third-party/pwm/pwm.c +$(USER_LIBDIR)/libpwm_open.a: third-party/pwm/pwm.c $(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $< -o $(dir $<)/pwm.o $(Q) $(AR) rcs $@ $(dir $<)/pwm.o endif @@ -296,6 +319,11 @@ $(USER_LIBDIR)/libmainmm.a: $(addprefix $(SDK_LIBDIR)/,libmain.a) $(Q) $(AR) -d $@ mem_manager.o endif +ifeq ($(ENABLE_CUSTOM_LWIP), 1) +$(USER_LIBDIR)/liblwip_%.a: third-party/esp-open-lwip/Makefile.open + $(Q) $(MAKE) -C third-party/esp-open-lwip/ -f Makefile.open ENABLE_ESPCONN=$(ENABLE_ESPCONN) SDK_BASE="$(SDK_BASE)" USER_LIBDIR="$(SMING_HOME)/$(USER_LIBDIR)/" all +endif + spiffy: spiffy/spiffy spiffy/spiffy: @@ -338,7 +366,7 @@ else $(Q) $(MAKE) --no-print-directory -C spiffy clean V=$(V) endif -test: all spiffy samples +test: Basic_Blink Basic_rBoot Basic_Ssl Basic_HwPWM docs/wiki/Home.md: $(vecho) "No Wiki submodule found. Using git to fetch it..." diff --git a/Sming/Makefile-bsd.mk b/Sming/Makefile-bsd.mk index a0c33f6fbe..fcf301fe94 100644 --- a/Sming/Makefile-bsd.mk +++ b/Sming/Makefile-bsd.mk @@ -12,5 +12,5 @@ SDK_TOOLS ?= $(SDK_BASE)/tools ESPTOOL ?= $(ESP_HOME)/esptool/esptool.py KILL_TERM ?= pkill -9 -f "$(COM_PORT) $(COM_SPEED_SERIAL)" || exit 0 GET_FILESIZE ?= stat -f "%-15z" -TERMINAL ?= python -m serial.tools.miniterm $(COM_PORT) $(COM_SPEED_SERIAL) +TERMINAL ?= python -m serial.tools.miniterm $(COM_PORT) $(COM_SPEED_SERIAL) $(COM_OPTS) MEMANALYZER ?= $(OBJDUMP) -h -j .data -j .rodata -j .bss -j .text -j .irom0.text \ No newline at end of file diff --git a/Sming/Makefile-linux.mk b/Sming/Makefile-linux.mk index d03dcc0539..3cbae7d8da 100644 --- a/Sming/Makefile-linux.mk +++ b/Sming/Makefile-linux.mk @@ -12,5 +12,5 @@ SDK_TOOLS ?= $(SDK_BASE)/tools ESPTOOL ?= $(ESP_HOME)/esptool/esptool.py KILL_TERM ?= pkill -9 -f "$(COM_PORT) $(COM_SPEED_SERIAL)" || exit 0 GET_FILESIZE ?= stat --printf="%s" -TERMINAL ?= python -m serial.tools.miniterm $(COM_PORT) $(COM_SPEED_SERIAL) +TERMINAL ?= python -m serial.tools.miniterm $(COM_PORT) $(COM_SPEED_SERIAL) $(COM_OPTS) MEMANALYZER ?= $(OBJDUMP) -h -j .data -j .rodata -j .bss -j .text -j .irom0.text \ No newline at end of file diff --git a/Sming/Makefile-macos.mk b/Sming/Makefile-macos.mk index 6f6ed8846c..0e626c0182 100644 --- a/Sming/Makefile-macos.mk +++ b/Sming/Makefile-macos.mk @@ -12,5 +12,5 @@ SDK_TOOLS ?= $(SDK_BASE)/tools ESPTOOL ?= $(ESP_HOME)/esptool/esptool.py KILL_TERM ?= pkill -9 -f "$(COM_PORT) $(COM_SPEED_SERIAL)" || exit 0 GET_FILESIZE ?= stat -L -f%z -TERMINAL ?= python -m serial.tools.miniterm $(COM_PORT) $(COM_SPEED_SERIAL) +TERMINAL ?= python -m serial.tools.miniterm $(COM_PORT) $(COM_SPEED_SERIAL) $(COM_OPTS) MEMANALYZER ?= $(OBJDUMP) -h -j .data -j .rodata -j .bss -j .text -j .irom0.text \ No newline at end of file diff --git a/Sming/Makefile-project.mk b/Sming/Makefile-project.mk index dd22a06ce4..194365c0a3 100644 --- a/Sming/Makefile-project.mk +++ b/Sming/Makefile-project.mk @@ -31,7 +31,13 @@ SPIFFY ?= $(SMING_HOME)/spiffy/spiffy #ESPTOOL2 config to generate rBootLESS images IMAGE_MAIN ?= 0x00000.bin -IMAGE_SDK ?= 0x09000.bin +IMAGE_SDK ?= 0x0a000.bin # The name must match the starting address of the irom0 section + # in the LD file ($SMING_HOME/compiler/ld/eagle.app.v6.cpp.ld). + # To calculate the value do the following: x = irom0_0_seg.org - 0x40200000 + # Example: 0x4020a000 - 0x40200000 = 0x0a000 +INIT_BIN_ADDR = 0x7c000 +BLANK_BIN_ADDR = 0x4b000 + # esptool2 path ESPTOOL2 ?= esptool2 # esptool2 parameters for rBootLESS images @@ -125,7 +131,12 @@ SPIFF_FILES ?= files BUILD_BASE = out/build FW_BASE = out/firmware -SPIFF_START_OFFSET = $(shell printf '0x%X\n' $$(( ($$($(GET_FILESIZE) $(FW_BASE)/0x09000.bin) + 16384 + 36864) & (0xFFFFC000) )) ) +# The line below calculates the next available sector after the IMAGE_SDK ROM. +# The math is the following: next_available_sector_start = (( address + size ) + one_sector_size) & 0xFFFFF000 +# 0x01000 is the size of one sector +# IMAGE_SDK contains starting address of the irom0 section and its size +# 0xFFFF000 mask that is used to show the start of a sector +SPIFF_START_OFFSET = $(shell printf '0x%X\n' $$(( ($$($(GET_FILESIZE) $(FW_BASE)/$(IMAGE_SDK)) + 0x1000 + $(basename $(IMAGE_SDK))) & (0xFFFFF000) )) ) #Firmware memory layout info files FW_MEMINFO_NEW = $(FW_BASE)/fwMeminfo.new @@ -137,16 +148,24 @@ TARGET = app THIRD_PARTY_DIR = $(SMING_HOME)/third-party +SMING_FEATURES = none LIBSMING = sming ifeq ($(ENABLE_SSL),1) LIBSMING = smingssl + SMING_FEATURES = SSL endif # which modules (subdirectories) of the project to include in compiling # define your custom directories in the project's own Makefile before including this one MODULES ?= app # default to app if not set by user EXTRA_INCDIR ?= include # default to include if not set by user -EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src + +ENABLE_CUSTOM_LWIP ?= 1 +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LWIP_INCDIR = $(SMING_HOME)/third-party/esp-open-lwip +endif + +EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src ENABLE_CUSTOM_HEAP ?= 0 @@ -155,9 +174,24 @@ ifeq ($(ENABLE_CUSTOM_HEAP),1) LIBMAIN = mainmm endif +LIBLWIP = lwip +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LIBLWIP = lwip_open + ifeq ($(ENABLE_ESPCONN), 1) + LIBLWIP = lwip_full + endif + CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBLWIP).a +endif + +LIBPWM = pwm +ifeq ($(ENABLE_CUSTOM_PWM), 1) + LIBPWM = pwm_open + CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBPWM).a +endif + # libraries used in this project, mainly provided by the SDK USER_LIBDIR = $(SMING_HOME)/compiler/lib/ -LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) $(LIBSMING) crypto pwm smartconfig $(EXTRA_LIBS) +LIBS = microc microgcc hal phy pp net80211 $(LIBLWIP) wpa $(LIBMAIN) $(LIBSMING) crypto $(LIBPWM) smartconfig $(EXTRA_LIBS) # compiler flags using during compilation of source files CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 -DCOM_SPEED_SERIAL=$(COM_SPEED_SERIAL) $(USER_CFLAGS) @@ -185,7 +219,7 @@ ifeq ($(ENABLE_SSL),1) AXTLS_FLAGS += -DSSL_DEBUG=1 -DDEBUG_TLS_MEM=1 endif - CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBSMING).a include/ssl/private_key.h + CUSTOM_TARGETS += include/ssl/private_key.h CFLAGS += $(AXTLS_FLAGS) CXXFLAGS += $(AXTLS_FLAGS) endif @@ -237,12 +271,18 @@ ifeq ($(SPI_SIZE), 256K) else ifeq ($(SPI_SIZE), 1M) flashimageoptions += -fs 8m SPIFF_SIZE ?= 524288 #512K + INIT_BIN_ADDR = 0x0fc000 + BLANK_BIN_ADDR = 0x0fe000 else ifeq ($(SPI_SIZE), 2M) flashimageoptions += -fs 16m SPIFF_SIZE ?= 524288 #512K + INIT_BIN_ADDR = 0x1fc000 + BLANK_BIN_ADDR = 0x1fe000 else ifeq ($(SPI_SIZE), 4M) flashimageoptions += -fs 32m SPIFF_SIZE ?= 524288 #512K + INIT_BIN_ADDR = 0x3fc000 + BLANK_BIN_ADDR = 0x3fe000 else flashimageoptions += -fs 4m SPIFF_SIZE ?= 196608 #192K @@ -284,12 +324,6 @@ INCDIR := $(addprefix -I,$(SRC_DIR)) EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) -CUSTOM_TARGETS ?= - -ifeq ($(ENABLE_CUSTOM_PWM), 1) - CUSTOM_TARGETS += $(USER_LIBDIR)/libpwm.a -endif - V ?= $(VERBOSE) ifeq ("$(V)","1") Q := @@ -313,7 +347,7 @@ endef .PHONY: all checkdirs spiff_update spiff_clean clean -all: checkdirs $(TARGET_OUT) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) +all: $(USER_LIBDIR)/lib$(LIBSMING).a checkdirs $(TARGET_OUT) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) spiff_update: spiff_clean $(SPIFF_BIN_OUT) @@ -352,7 +386,7 @@ $(APP_AR): $(OBJ) $(Q) $(AR) cru $@ $^ $(USER_LIBDIR)/lib$(LIBSMING).a: - $(vecho) "Recompiling Sming with SSL support. This may take some time" + $(vecho) "(Re)compiling Sming. Enabled features: $(SMING_FEATURES). This may take some time" $(Q) $(MAKE) -C $(SMING_HOME) clean V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) $(Q) $(MAKE) -C $(SMING_HOME) V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) @@ -362,8 +396,13 @@ include/ssl/private_key.h: $(Q) AXDIR=$(CURRENT_DIR)/include/ssl/ $(THIRD_PARTY_DIR)/axtls-8266/tools/make_certs.sh ifeq ($(ENABLE_CUSTOM_PWM), 1) -$(USER_LIBDIR)/libpwm.a: - $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/libpwm.a ENABLE_CUSTOM_PWM=1 +$(USER_LIBDIR)/libpwm_open.a: + $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/libpwm_open.a ENABLE_CUSTOM_PWM=1 +endif + +ifeq ($(ENABLE_CUSTOM_LWIP), 1) +$(USER_LIBDIR)/liblwip_%.a: + $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/$(notdir $@) ENABLE_CUSTOM_LWIP=1 ENABLE_ESPCONN=$(ENABLE_ESPCONN) endif checkdirs: $(BUILD_DIR) $(FW_BASE) $(CUSTOM_TARGETS) @@ -399,9 +438,9 @@ flash: all $(vecho) "Killing Terminal to free $(COM_PORT)" -$(Q) $(KILL_TERM) ifeq ($(DISABLE_SPIFFS), 1) - $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/0x00000.bin 0x09000 $(FW_BASE)/0x09000.bin + $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) $(basename $(IMAGE_MAIN)) $(FW_BASE)/$(IMAGE_MAIN) $(basename $(IMAGE_SDK)) $(FW_BASE)/$(IMAGE_SDK) else - $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) 0x00000 $(FW_BASE)/0x00000.bin 0x09000 $(FW_BASE)/0x09000.bin $(SPIFF_START_OFFSET) $(SPIFF_BIN_OUT) + $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) $(basename $(IMAGE_MAIN)) $(FW_BASE)/$(IMAGE_MAIN) $(basename $(IMAGE_SDK)) $(FW_BASE)/$(IMAGE_SDK) $(SPIFF_START_OFFSET) $(SPIFF_BIN_OUT) endif $(TERMINAL) @@ -412,7 +451,8 @@ terminal: flashinit: $(vecho) "Flash init data default and blank data." - $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) 0x7c000 $(SDK_BASE)/bin/esp_init_data_default.bin 0x7e000 $(SDK_BASE)/bin/blank.bin 0x4B000 $(SMING_HOME)/compiler/data/blankfs.bin + $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) erase_flash + $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) $(INIT_BIN_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin $(BLANK_BIN_ADDR) $(SDK_BASE)/bin/blank.bin $(SPIFF_START_OFFSET) $(SMING_HOME)/compiler/data/blankfs.bin rebuild: clean all diff --git a/Sming/Makefile-rboot.mk b/Sming/Makefile-rboot.mk index c520ff71e3..d54ea714b7 100644 --- a/Sming/Makefile-rboot.mk +++ b/Sming/Makefile-rboot.mk @@ -12,6 +12,19 @@ RBOOT_BIG_FLASH ?= 1 RBOOT_TWO_ROMS ?= 0 RBOOT_RTC_ENABLED ?= 0 +RBOOT_GPIO_ENABLED ?= 0 + +### ROM Addresses ### +# The parameter below specifies the location of the second rom. +# This parameter is used only when RBOOT_BIG_FLASH = 1 +# BOOT_ROM1_ADDR = 0x200000 + +# The parameter below specifies the location of the GPIO ROM. +# This parameter is used only when RBOOT_GPIO_ENABLED = 1 +# If you use two SPIFFS make sure that this address is minimum +# RBOOT_SPIFFS_1 + SPIFF_SIZE +# BOOT_ROM2_ADDR = 0x310000 + RBOOT_ROM_0 ?= rom0 RBOOT_ROM_1 ?= rom1 RBOOT_SPIFFS_0 ?= 0x100000 @@ -22,6 +35,8 @@ RBOOT_LD_1 ?= rom1.ld ESPTOOL2 ?= esptool2 # path to spiffy SPIFFY ?= $(SMING_HOME)/spiffy/spiffy +INIT_BIN_ADDR = 0x7c000 +BLANK_BIN_ADDR = 0x4b000 # filenames and options for generating rBoot rom images with esptool2 RBOOT_E2_SECTS ?= .text .data .rodata RBOOT_E2_USER_ARGS ?= -quiet -bin -boot2 @@ -139,8 +154,10 @@ TARGET = app THIRD_PARTY_DIR = $(SMING_HOME)/third-party LIBSMING = sming +SMING_FEATURES = none ifeq ($(ENABLE_SSL),1) LIBSMING = smingssl + SMING_FEATURES = SSL endif # which modules (subdirectories) of the project to include in compiling @@ -148,7 +165,13 @@ endif MODULES ?= app # default to app if not set by user MODULES += $(THIRD_PARTY_DIR)/rboot/appcode EXTRA_INCDIR ?= include # default to include if not set by user -EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src + +ENABLE_CUSTOM_LWIP ?= 1 +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LWIP_INCDIR = $(SMING_HOME)/third-party/esp-open-lwip +endif + +EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src USER_LIBDIR = $(SMING_HOME)/compiler/lib/ @@ -194,7 +217,22 @@ else endif # libraries used in this project, mainly provided by the SDK -LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) $(LIBSMING) crypto pwm smartconfig $(EXTRA_LIBS) +LIBLWIP = lwip +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + LIBLWIP = lwip_open + ifeq ($(ENABLE_ESPCONN), 1) + LIBLWIP = lwip_full + endif + CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBLWIP).a +endif + +LIBPWM = pwm +ifeq ($(ENABLE_CUSTOM_PWM), 1) + LIBPWM = pwm_open + CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBPWM).a +endif + +LIBS = microc microgcc hal phy pp net80211 $(LIBLWIP) wpa $(LIBMAIN) $(LIBSMING) crypto $(LIBPWM) smartconfig $(EXTRA_LIBS) # SSL support using axTLS ifeq ($(ENABLE_SSL),1) @@ -205,11 +243,16 @@ ifeq ($(ENABLE_SSL),1) AXTLS_FLAGS += -DSSL_DEBUG=1 -DDEBUG_TLS_MEM=1 endif - CUSTOM_TARGETS += $(USER_LIBDIR)/lib$(LIBSMING).a include/ssl/private_key.h + CUSTOM_TARGETS += include/ssl/private_key.h CFLAGS += $(AXTLS_FLAGS) CXXFLAGS += $(AXTLS_FLAGS) endif +ifeq ($(ENABLE_CUSTOM_LWIP), 1) + EXTRA_INCDIR += third-party/esp-open-lwip/include +endif + + # we will use global WiFi settings from Eclipse Environment Variables, if possible WIFI_SSID ?= "" WIFI_PWD ?= "" @@ -252,12 +295,18 @@ ifeq ($(SPI_SIZE), 256K) else ifeq ($(SPI_SIZE), 1M) flashimageoptions += -fs 8m SPIFF_SIZE ?= 524288 #512K + INIT_BIN_ADDR = 0x0fc000 + BLANK_BIN_ADDR = 0x0fe000 else ifeq ($(SPI_SIZE), 2M) flashimageoptions += -fs 16m SPIFF_SIZE ?= 524288 #512K + INIT_BIN_ADDR = 0x1fc000 + BLANK_BIN_ADDR = 0x1fe000 else ifeq ($(SPI_SIZE), 4M) flashimageoptions += -fs 32m SPIFF_SIZE ?= 524288 #512K + INIT_BIN_ADDR = 0x3fc000 + BLANK_BIN_ADDR = 0x3fe000 else flashimageoptions += -fs 4m SPIFF_SIZE ?= 196608 #192K @@ -311,6 +360,9 @@ export RBOOT_BIG_FLASH export RBOOT_BUILD_BASE export RBOOT_FW_BASE export RBOOT_RTC_ENABLED +export RBOOT_GPIO_ENABLED +export RBOOT_ROM1_ADDR +export RBOOT_ROM2_ADDR export SPI_SIZE export SPI_MODE export SPI_SPEED @@ -330,6 +382,10 @@ ifeq ($(RBOOT_RTC_ENABLED),1) CFLAGS += -DBOOT_RTC_ENABLED endif +ifeq ($(RBOOT_GPIO_ENABLED),1) + CFLAGS += -DBOOT_GPIO_ENABLED +endif + INCDIR := $(addprefix -I,$(SRC_DIR)) EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR)) MODULE_INCDIR := $(addsuffix /include,$(INCDIR)) @@ -357,10 +413,10 @@ endef .PHONY: all checkdirs spiff_update spiff_clean clean -all: checkdirs $(LIBMAIN_DST) $(RBOOT_BIN) $(RBOOT_ROM_0) $(RBOOT_ROM_1) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) +all: $(USER_LIBDIR)/lib$(LIBSMING).a checkdirs $(LIBMAIN_DST) $(RBOOT_BIN) $(RBOOT_ROM_0) $(RBOOT_ROM_1) $(SPIFF_BIN_OUT) $(FW_FILE_1) $(FW_FILE_2) $(RBOOT_BIN): - $(MAKE) -C $(THIRD_PARTY_DIR)/rboot + $(MAKE) -C $(THIRD_PARTY_DIR)/rboot RBOOT_GPIO_ENABLED=$(RBOOT_GPIO_ENABLED) $(LIBMAIN_DST): $(LIBMAIN_SRC) @echo "OC $@" @@ -392,7 +448,7 @@ $(APP_AR): $(OBJ) $(Q) $(AR) cru $@ $^ $(USER_LIBDIR)/lib$(LIBSMING).a: - $(vecho) "Recompiling Sming with SSL support. This may take some time" + $(vecho) "(Re)compiling Sming. Enabled features: $(SMING_FEATURES). This may take some time" $(Q) $(MAKE) -C $(SMING_HOME) clean V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) $(Q) $(MAKE) -C $(SMING_HOME) V=$(V) ENABLE_SSL=$(ENABLE_SSL) SMING_HOME=$(SMING_HOME) @@ -400,6 +456,16 @@ include/ssl/private_key.h: $(vecho) "Generating unique certificate and key. This may take some time" $(Q) mkdir -p $(CURRENT_DIR)/include/ssl/ $(Q) AXDIR=$(CURRENT_DIR)/include/ssl/ $(THIRD_PARTY_DIR)/axtls-8266/tools/make_certs.sh + +ifeq ($(ENABLE_CUSTOM_PWM), 1) +$(USER_LIBDIR)/libpwm_open.a: + $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/libpwm_open.a ENABLE_CUSTOM_PWM=1 +endif + +ifeq ($(ENABLE_CUSTOM_LWIP), 1) +$(USER_LIBDIR)/liblwip_%.a: + $(Q) $(MAKE) -C $(SMING_HOME) compiler/lib/$(notdir $@) ENABLE_CUSTOM_LWIP=1 ENABLE_ESPCONN=$(ENABLE_ESPCONN) +endif checkdirs: $(BUILD_DIR) $(FW_BASE) $(CUSTOM_TARGETS) @@ -448,7 +514,8 @@ terminal: flashinit: $(vecho) "Flash init data default and blank data." - $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) 0x7c000 $(SDK_BASE)/bin/esp_init_data_default.bin 0x7e000 $(SDK_BASE)/bin/blank.bin 0x4B000 $(SMING_HOME)/compiler/data/blankfs.bin + $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) erase_flash + $(ESPTOOL) -p $(COM_PORT) -b $(COM_SPEED_ESPTOOL) write_flash $(flashimageoptions) $(INIT_BIN_ADDR) $(SDK_BASE)/bin/esp_init_data_default.bin $(BLANK_BIN_ADDR) $(SDK_BASE)/bin/blank.bin $(SPIFF_START_OFFSET) $(SMING_HOME)/compiler/data/blankfs.bin rebuild: clean all diff --git a/Sming/Makefile-windows.mk b/Sming/Makefile-windows.mk index e2e49813ec..3bc4257789 100644 --- a/Sming/Makefile-windows.mk +++ b/Sming/Makefile-windows.mk @@ -12,5 +12,5 @@ SDK_TOOLS ?= $(ESP_HOME)/utils ESPTOOL ?= $(SDK_TOOLS)/esptool.exe KILL_TERM ?= taskkill.exe -f -im Terminal.exe || exit 0 GET_FILESIZE ?= stat --printf="%s" -TERMINAL ?= $(SDK_TOOLS)/Terminal.exe $(COM_PORT) $(COM_SPEED_SERIAL) -MEMANALYZER ?= $(SDK_TOOLS)/memanalyzer.exe $(OBJDUMP).exe \ No newline at end of file +TERMINAL ?= $(SDK_TOOLS)/Terminal.exe $(COM_PORT) $(COM_SPEED_SERIAL) $(COM_OPTS) +MEMANALYZER ?= $(SDK_TOOLS)/ESP8266/memanalyzer.exe $(OBJDUMP).exe diff --git a/Sming/Services/SpifFS/spiffs_config.h b/Sming/Services/SpifFS/spiffs_config.h index f6b6729167..a69b15163c 100644 --- a/Sming/Services/SpifFS/spiffs_config.h +++ b/Sming/Services/SpifFS/spiffs_config.h @@ -9,25 +9,38 @@ #define SPIFFS_CONFIG_H_ // ----------- 8< ------------ -// Following includes are for the linux test build of spiffs -// These may/should/must be removed/altered/replaced in your target -//#include "params_test.h" #ifdef __ets__ -#include -#include "../system/flashmem.h" + #include + #include "../system/flashmem.h" #else -#include -#include -#include -#include -#include -#include -typedef signed int s32_t; -typedef unsigned int u32_t; -typedef signed short s16_t; -typedef unsigned short u16_t; -typedef signed char s8_t; -typedef unsigned char u8_t; + #include + #include + #include + #include + #include + #if defined _WIN32 || defined __CYGWIN__ + #if __WORDSIZE == 64 + # ifndef __intptr_t_defined + typedef long int intptr_t; + # define __intptr_t_defined + # endif + typedef unsigned long int uintptr_t; + #else + # ifndef __intptr_t_defined + typedef int intptr_t; + # define __intptr_t_defined + # endif + typedef unsigned int uintptr_t; + #endif + #else + #include + #endif + typedef signed int s32_t; + typedef unsigned int u32_t; + typedef signed short s16_t; + typedef unsigned short u16_t; + typedef signed char s8_t; + typedef unsigned char u8_t; #endif /* __ets__ */ // ----------- >8 ------------ diff --git a/Sming/Services/SpifFS/spiffs_sming.c b/Sming/Services/SpifFS/spiffs_sming.c index d4dff342fa..6eb05e2426 100644 --- a/Sming/Services/SpifFS/spiffs_sming.c +++ b/Sming/Services/SpifFS/spiffs_sming.c @@ -45,13 +45,8 @@ spiffs_config spiffs_get_storage_config() cfg.phys_addr = ( u32_t )flashmem_get_first_free_block_address(); if (cfg.phys_addr == 0) return cfg; - cfg.phys_addr += 0x3000; - cfg.phys_addr &= 0xFFFFC000; // align to 4 sector. - cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr - INTERNAL_FLASH_START_ADDRESS ); - /*cfg.phys_addr = INTERNAL_FLASH_SIZE - SPIFFS_WORK_SIZE + INTERNAL_FLASH_START_ADDRESS; - cfg.phys_addr += 0x3000; - cfg.phys_addr &= 0xFFFFC000; // align to 4 sector. - cfg.phys_size = SPIFFS_WORK_SIZE;*/ + cfg.phys_addr &= 0xFFFFF000; // get the start address of the sector + cfg.phys_size = INTERNAL_FLASH_SIZE - ( ( u32_t )cfg.phys_addr); cfg.phys_erase_block = INTERNAL_FLASH_SECTOR_SIZE; // according to datasheet cfg.log_block_size = INTERNAL_FLASH_SECTOR_SIZE * 2; // Important to make large cfg.log_page_size = LOG_PAGE_SIZE; // as we said @@ -104,7 +99,7 @@ static void spiffs_mount_internal(spiffs_config *cfg) return; } - debugf("fs.start: size:%d Kb, offset:0x%X\n", cfg->phys_size / 1024, cfg->phys_addr - INTERNAL_FLASH_START_ADDRESS); + debugf("fs.start: size:%d Kb, offset:0x%X\n", cfg->phys_size / 1024, cfg->phys_addr); cfg->hal_read_f = api_spiffs_read; cfg->hal_write_f = api_spiffs_write; diff --git a/Sming/Services/Yeelight/YeelightBulb.cpp b/Sming/Services/Yeelight/YeelightBulb.cpp new file mode 100644 index 0000000000..fabd4a5fa1 --- /dev/null +++ b/Sming/Services/Yeelight/YeelightBulb.cpp @@ -0,0 +1,197 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/anakod/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + ****/ + +#include "YeelightBulb.h" +#include "TcpClient.h" +#include + +YeelightBulb::YeelightBulb(IPAddress addr) +{ + lamp = addr; +} + +YeelightBulb::~YeelightBulb() +{ + if (connection != nullptr) + delete connection; + connection = nullptr; +} + +bool YeelightBulb::connect() +{ + if (connection != nullptr) + { + if (connection->isProcessing()) + return true; + + //connection->close(); + delete connection; + } + + connection = new TcpClient(TcpClientDataDelegate(&YeelightBulb::onResponse, this)); + + connection->setTimeOut(USHRT_MAX); // Stay connected forever + bool result = connection->connect(lamp, port); + //if (result) updateState(); + return result; +} + +bool isNumeric(String str) +{ + for (int i = 0; i < str.length(); i++) + { + if (!isDigit(str[i])) + return false; + } + return true; +} + +void YeelightBulb::sendCommand(String method, Vector params) +{ + connect(); + + DynamicJsonBuffer jsonBuffer; + JsonObject& root = jsonBuffer.createObject(); + root["id"] = requestId++; + root["method"] = method; + auto &arr = root.createNestedArray("params"); + for (int i = 0; i < params.count(); i++) + { + if (isNumeric(params[i])) + arr.add(params[i].toInt()); + else + arr.add(params[i]); + } + String request; + root.printTo(request); + request += "\r\n"; + debugf("LED < %s", request.c_str()); + connection->writeString(request); + connection->flush(); +} + +void YeelightBulb::on() +{ + Vector params; + params.add("on"); + sendCommand("set_power", params); + state = eYBS_On; +} + +void YeelightBulb::off() +{ + Vector params; + params.add("off"); + sendCommand("set_power", params); + state = eYBS_Off; +} + +void YeelightBulb::setState(bool isOn) +{ + if (isOn) + on(); + else + off(); +} + +void YeelightBulb::updateState() +{ + propsId = requestId; + Vector params; + params.add("power"); + params.add("bright"); + sendCommand("get_prop", params); +} + +void YeelightBulb::setBrightness(int percent) +{ + ensureOn(); + Vector params; + params.add(String(percent)); + sendCommand("set_bright", params); +} + +void YeelightBulb::setRGB(byte r, byte g, byte b) +{ + ensureOn(); + Vector params; + long val = (long)r*65536 + (long)g*256 + b; + params.add(String(val)); + sendCommand("set_rgb", params); +} + +void YeelightBulb::setHSV(int hue, int sat) +{ + ensureOn(); + Vector params; + params.add(String(hue)); + params.add(String(sat)); + sendCommand("set_hsv", params); +} + +void YeelightBulb::ensureOn() +{ + if (state <= 0) + on(); +} + +void YeelightBulb::parsePower(const String& value) +{ + if (value == "on") + state = eYBS_On; + else if (value == "off") + state = eYBS_Off; + + debugf("LED state: %s", value.c_str()); +} + +bool YeelightBulb::onResponse(TcpClient& client, char* data, int size) +{ + String source(data, size); + debugf("LED > %s", source.c_str()); + + int p = 0; + while (p < source.length()) + { + int p2 = source.indexOf("\r\n", p); + if (p2 == -1) + p2 = source.length(); + String buf = source.substring(p, p2); + p = p2 + 2; + DynamicJsonBuffer jsonBuffer; + JsonObject& root = jsonBuffer.parseObject(buf); + bool parsed = root.success(); + if (parsed) + { + if (root.containsKey("id") && root.containsKey("result")) + { + long id = root["id"]; + if (id == propsId) + { + auto &result = root["result"].asArray(); + String resp = result[0].asString(); + parsePower(resp); + } + } + if (root.containsKey("method") && root.containsKey("params")) + { + String method = root["method"].asString(); + debugf("LED method %s received", method.c_str()); + if (method == "props") + { + auto &result = root["params"].asObject(); + for (JsonObject::iterator it=result.begin(); it!=result.end(); ++it) + { + if (strcmp(it->key, "power") == 0) + parsePower(it->value); + } + } + } + } + } + return true; +} diff --git a/Sming/Services/Yeelight/YeelightBulb.h b/Sming/Services/Yeelight/YeelightBulb.h new file mode 100644 index 0000000000..3e675badbd --- /dev/null +++ b/Sming/Services/Yeelight/YeelightBulb.h @@ -0,0 +1,71 @@ +/**** + * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development. + * Created 2015 by Skurydin Alexey + * http://github.com/anakod/Sming + * All files of the Sming Core are provided under the LGPL v3 license. + ****/ + +#include "../Wiring/WiringFrameworkDependencies.h" +#include "../Wiring/WHashMap.h" +#include "../Wiring/WVector.h" +#include "../Wiring/WString.h" +#include "IPAddress.h" +class TcpClient; + +#ifndef SERVICES_YEELIGHTBULB_H_ +#define SERVICES_YEELIGHTBULB_H_ + +enum YeelightBulbState +{ + eYBS_Unknown = -1, + eYBS_Off = 0, + eYBS_On = 1 +}; + +/** @brief Yeelight wifi bulb controller class + */ +class YeelightBulb +{ +public: + YeelightBulb(IPAddress addr); + ~YeelightBulb(); + + /** @brief Can be skipped. This method will be called automatically from any action method below + */ + bool connect(); + + /** @brief Send any command to the lamp + */ + void sendCommand(String method, Vector params); + + void on(); + void off(); + void setState(bool isOn); + + /** @brief Start async reading of current lamp state + */ + void updateState(); + /** @brief Get current lamp state (should be called only after updateState) + */ + YeelightBulbState currentState() { return state; } + + void setBrightness(int percent); + void setRGB(byte r, byte g, byte b); + void setHSV(int hue, int sat); + +protected: + void ensureOn(); + bool onResponse(TcpClient& client, char *data, int size); + void parsePower(const String& resp); + +private: + IPAddress lamp; + uint16_t port = 55443; + + TcpClient* connection = nullptr; + long requestId = 0; + long propsId; + YeelightBulbState state = eYBS_Unknown; +}; + +#endif /* SERVICES_YEELIGHTBULB_H_ */ diff --git a/Sming/SmingCore/Digital.cpp b/Sming/SmingCore/Digital.cpp index 63faf89c7c..837f6213d9 100644 --- a/Sming/SmingCore/Digital.cpp +++ b/Sming/SmingCore/Digital.cpp @@ -7,52 +7,58 @@ #include "../SmingCore/Digital.h" #include "../Wiring/WiringFrameworkIncludes.h" +#include "espinc/peri.h" + +uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C, 0x20, 0x24, 0x28, 0x2C, 0x30, 0x04, 0x08, 0x0C, 0x10}; void pinMode(uint16_t pin, uint8_t mode) { - if (pin < 16) - { - // Set as GPIO - PIN_FUNC_SELECT((EspDigitalPins[pin].mux), (EspDigitalPins[pin].gpioFunc)); - - // Switch to Input or Output - if (mode == INPUT || mode == INPUT_PULLUP) - GPIO_REG_WRITE(GPIO_ENABLE_W1TC_ADDRESS, (1<> 4) & 0x07); + if(pin == 13 && mode == FUNCTION_4) GPF(pin) |= (1 << GPFPU);//enable pullup on RX + } else if(mode == OUTPUT || mode == OUTPUT_OPEN_DRAIN){ + 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) + if(mode == OUTPUT_OPEN_DRAIN) GPC(pin) |= (1 << GPCD); + GPES = (1 << pin); //Enable + } else if(mode == INPUT || mode == INPUT_PULLUP){ + GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO + GPEC = (1 << pin); //Disable + GPC(pin) = (GPC(pin) & (0xF << GPCI)) | (1 << GPCD); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED) + if(mode == INPUT_PULLUP) { + GPF(pin) |= (1 << GPFPU); // Enable Pullup + } + } else if(mode == WAKEUP_PULLUP || mode == WAKEUP_PULLDOWN){ + GPF(pin) = GPFFS(GPFFS_GPIO(pin));//Set mode to GPIO + GPEC = (1 << pin); //Disable + if(mode == WAKEUP_PULLUP) { + GPF(pin) |= (1 << GPFPU); // Enable Pullup + GPC(pin) = (1 << GPCD) | (4 << GPCI) | (1 << GPCWE); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(LOW) | WAKEUP_ENABLE(ENABLED) + } else { + GPF(pin) |= (1 << GPFPD); // Enable Pulldown + GPC(pin) = (1 << GPCD) | (5 << GPCI) | (1 << GPCWE); //SOURCE(GPIO) | DRIVER(OPEN_DRAIN) | INT_TYPE(HIGH) | WAKEUP_ENABLE(ENABLED) + } + } + } else if(pin == 16){ + GPF16 = GP16FFS(GPFFS_GPIO(pin));//Set mode to GPIO + GPC16 = 0; + if(mode == INPUT || mode == INPUT_PULLDOWN_16){ + if(mode == INPUT_PULLDOWN_16){ + GPF16 |= (1 << GP16FPD);//Enable Pulldown + } + GP16E &= ~1; + } else if(mode == OUTPUT){ + GP16E |= 1; + } + } } //Detect if pin is input diff --git a/Sming/SmingCore/HardwareSerial.cpp b/Sming/SmingCore/HardwareSerial.cpp index 3009c44fd5..3542f0433c 100644 --- a/Sming/SmingCore/HardwareSerial.cpp +++ b/Sming/SmingCore/HardwareSerial.cpp @@ -14,256 +14,237 @@ #include "../SmingCore/Clock.h" #include "../SmingCore/Interrupts.h" -// UartDev is defined and initialized in ROM code. -extern UartDevice UartDev; +HWSerialMemberData HardwareSerial::memberData[NUMBER_UARTS]; +os_event_t *HardwareSerial::serialQueue = nullptr; +bool HardwareSerial::init = false; //set m_printf callback -extern void setMPrintfPrinterCbc(void (*callback)(char)); - -// StreamDataAvailableDelegate HardwareSerial::HWSDelegates[2]; - -HWSerialMemberData HardwareSerial::memberData[NUMBER_UARTS]; +extern void setMPrintfPrinterCbc(void (*callback)(uart_t *, char), uart_t *uart); HardwareSerial::HardwareSerial(const int uartPort) - : uart(uartPort) + : uartNr(uartPort), rxSize(256) { - resetCallback(); - // Start Serial task - serialQueue = (os_event_t *)malloc(sizeof(os_event_t) * SERIAL_QUEUE_LEN); - system_os_task(delegateTask,USER_TASK_PRIO_0,serialQueue,SERIAL_QUEUE_LEN); } -void HardwareSerial::begin(const uint32_t baud/* = 9600*/) +HardwareSerial::~HardwareSerial() { - //TODO: Move to params! - UartDev.baut_rate = (UartBautRate)baud; - UartDev.parity = NONE_BITS; - UartDev.exist_parity = STICK_PARITY_DIS; - UartDev.stop_bits = ONE_STOP_BIT; - UartDev.data_bits = EIGHT_BITS; - - ETS_UART_INTR_ATTACH((void*)uart0_rx_intr_handler, &(UartDev.rcv_buff)); - PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U); - PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD); - - uart_div_modify(uart, UART_CLK_FREQ / (UartDev.baut_rate)); +} - WRITE_PERI_REG(UART_CONF0(uart), UartDev.exist_parity - | UartDev.parity - | (UartDev.stop_bits << UART_STOP_BIT_NUM_S) - | (UartDev.data_bits << UART_BIT_NUM_S)); +void HardwareSerial::begin(const uint32_t baud, SerialConfig config, SerialMode mode, uint8_t txPin) +{ + end(); + uart = uart_init(uartNr, baud, (int) config, (int) mode, txPin, rxSize); + resetCallback(); +} +void HardwareSerial::end() +{ + if(uart_get_debug() == uartNr) { + uart_set_debug(UART_NO); + } - //clear rx and tx fifo,not ready - SET_PERI_REG_MASK(UART_CONF0(uart), UART_RXFIFO_RST | UART_TXFIFO_RST); - CLEAR_PERI_REG_MASK(UART_CONF0(uart), UART_RXFIFO_RST | UART_TXFIFO_RST); + if (uart) { + uart_uninit(uart); + uart = NULL; + } + else if(!init){ + uart_detach(uartNr); + init = true; + } +} - //set rx fifo trigger - WRITE_PERI_REG(UART_CONF1(uart), (UartDev.rcv_buff.TrigLvl & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S); +size_t HardwareSerial::setRxBufferSize(size_t size){ + if(uart) { + rxSize = uart_resize_rx_buffer(uart, size); + } else { + rxSize = size; + } + return rxSize; +} - //clear all interrupt - WRITE_PERI_REG(UART_INT_CLR(uart), 0xffff); - //enable rx_interrupt - SET_PERI_REG_MASK(UART_INT_ENA(uart), UART_RXFIFO_FULL_INT_ENA); +void HardwareSerial::swap(uint8_t tx_pin) +{ + if(!uart) { + return; + } + uart_swap(uart, tx_pin); +} - ETS_UART_INTR_ENABLE(); - delay(10); - Serial.println("\r\n"); // after SPAM :) +void HardwareSerial::setTx(uint8_t tx_pin) +{ + if(!uart) { + return; + } + uart_set_tx(uart, tx_pin); } -size_t HardwareSerial::write(uint8_t oneChar) +void HardwareSerial::pins(uint8_t tx, uint8_t rx) { - //if (oneChar == '\0') return 0; + if(!uart) { + return; + } + uart_set_pins(uart, tx, rx); +} - uart_tx_one_char(oneChar); +bool HardwareSerial::isTxEnabled(void) +{ + return uart && uart_tx_enabled(uart); +} - return 1; +bool HardwareSerial::isRxEnabled(void) +{ + return uart && uart_rx_enabled(uart); } int HardwareSerial::available() { - RcvMsgBuff &rxBuf = UartDev.rcv_buff; - if (rxBuf.pWritePos != rxBuf.pReadPos) - { - if (rxBuf.pWritePos > rxBuf.pReadPos) - return rxBuf.pWritePos - rxBuf.pReadPos; - else - return (((uint32_t)rxBuf.pRcvMsgBuff + RX_BUFF_SIZE) - (uint32_t)UartDev.rcv_buff.pReadPos) + (uint32_t)rxBuf.pWritePos; - } - else - return 0; + int result = static_cast(uart_rx_available(uart)); + return result; } -int HardwareSerial::read() +size_t HardwareSerial::write(uint8_t oneChar) { - if (available() == 0) - return -1; - - noInterrupts(); - RcvMsgBuff &rxBuf = UartDev.rcv_buff; - char res = *(rxBuf.pReadPos); - rxBuf.pReadPos++; + if(!uart || !uart_tx_enabled(uart)) { + return 0; + } - if (rxBuf.pReadPos >= (rxBuf.pRcvMsgBuff + RX_BUFF_SIZE)) - rxBuf.pReadPos = rxBuf.pRcvMsgBuff ; + uart_write_char(uart, oneChar); + return 1; +} - interrupts(); - return res; +int HardwareSerial::read() +{ + return uart_read_char(uart); } int HardwareSerial::readMemoryBlock(char* buf, int max_len) { - RcvMsgBuff &rxBuf = UartDev.rcv_buff; - int num = 0; - - noInterrupts(); - if (rxBuf.pWritePos != rxBuf.pReadPos) { - while ((rxBuf.pWritePos != rxBuf.pReadPos) && (max_len-- > 0)) { - *buf = *rxBuf.pReadPos; // Read data from Buffer - num++; // Increase counter of read bytes - buf++; // Increase Buffer pointer - - // Set pointer to next data word in ring buffer - rxBuf.pReadPos++; - if (rxBuf.pReadPos >= (rxBuf.pRcvMsgBuff + RX_BUFF_SIZE)) - rxBuf.pReadPos = rxBuf.pRcvMsgBuff ; + if (uart !=0 && uart_rx_enabled(uart)) { + int size; + char c; + for(int i=0;irx_buffer->wpos; + if(!lastPos) { + lastPos = uart->rx_buffer->size; + } + uint8_t receivedChar = uart->rx_buffer->buffer[lastPos-1]; + if ((memberData[uart->uart_nr].HWSDelegate) || (memberData[uart->uart_nr].commandExecutor)) { + uint32 serialQueueParameter; + uint16 cc = uart_rx_available(uart); + serialQueueParameter = (cc * 256) + receivedChar; // can be done by bitlogic, avoid casting to ETSParam + serialQueueParameter += (uart->uart_nr << 25); // the left most byte contains the uart_nr. Up to 256 uarts are supported + + if (memberData[uart->uart_nr].HWSDelegate) { + system_os_post(USER_TASK_PRIO_0, SERIAL_SIGNAL_DELEGATE, serialQueueParameter); + } + if (memberData[uart->uart_nr].commandExecutor) { + system_os_post(USER_TASK_PRIO_0, SERIAL_SIGNAL_COMMAND, serialQueueParameter); + } + } +} + +bool HardwareSerial::setCallback(StreamDataReceivedDelegate reqDelegate) { - memberData[uart].HWSDelegate = reqDelegate; - memberData[uart].useRxBuff = useSerialRxBuffer; + if (!uart || !uart_rx_enabled(uart)) { + return false; + } + + uart->callback = callbackHandler; + + memberData[uartNr].HWSDelegate = reqDelegate; + + // Start Serial task + if (!serialQueue) { + serialQueue = (os_event_t *) malloc(sizeof(os_event_t) * SERIAL_QUEUE_LEN); + system_os_task(delegateTask, USER_TASK_PRIO_0, serialQueue, SERIAL_QUEUE_LEN); + } + + return true; } void HardwareSerial::resetCallback() { - memberData[uart].HWSDelegate = nullptr; - memberData[uart].useRxBuff = true; + memberData[uartNr].HWSDelegate = nullptr; + + uart->callback = 0; } void HardwareSerial::commandProcessing(bool reqEnable) { if (reqEnable) { - if (!memberData[uart].commandExecutor) + if (!memberData[uartNr].commandExecutor) { - memberData[uart].commandExecutor = new CommandExecutor(&Serial); + memberData[uartNr].commandExecutor = new CommandExecutor(&Serial); } } else { - delete memberData[uart].commandExecutor; - memberData[uart].commandExecutor = nullptr; + delete memberData[uartNr].commandExecutor; + memberData[uartNr].commandExecutor = nullptr; } } - -void HardwareSerial::uart0_rx_intr_handler(void *para) -{ - /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents - * uart1 and uart0 respectively - */ - RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para; - uint8 RcvChar; - - if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART_ID_0)) & UART_RXFIFO_FULL_INT_ST)) - return; - - WRITE_PERI_REG(UART_INT_CLR(UART_ID_0), UART_RXFIFO_FULL_INT_CLR); - - while (READ_PERI_REG(UART_STATUS(UART_ID_0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) - { - RcvChar = READ_PERI_REG(UART_FIFO(UART_ID_0)) & 0xFF; - - /* you can add your handle code below.*/ - if (memberData[UART_ID_0].useRxBuff) - { - *(pRxBuff->pWritePos) = RcvChar; - - // insert here for get one command line from uart - if (RcvChar == '\n' ) - pRxBuff->BuffState = WRITE_OVER; - - pRxBuff->pWritePos++; - - if (pRxBuff->pWritePos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) - { - // overflow ...we may need more error handle here. - pRxBuff->pWritePos = pRxBuff->pRcvMsgBuff; - } - - if (pRxBuff->pWritePos == pRxBuff->pReadPos) - { // Prevent readbuffer overflow - if (pRxBuff->pReadPos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE)) - { - pRxBuff->pReadPos = pRxBuff->pRcvMsgBuff ; - } else { - pRxBuff->pReadPos++; - } - } - } - - if ((memberData[UART_ID_0].HWSDelegate) || (memberData[UART_ID_0].commandExecutor)) - { - uint32 serialQueueParameter; - uint16 cc; - cc = (pRxBuff->pWritePos < pRxBuff->pReadPos) ? ((pRxBuff->pWritePos + RX_BUFF_SIZE) - pRxBuff->pReadPos) - : (pRxBuff->pWritePos - pRxBuff->pReadPos); - serialQueueParameter = (cc * 256) + RcvChar; // can be done by bitlogic, avoid casting to ETSParam - - if (memberData[UART_ID_0].HWSDelegate) - { - system_os_post(USER_TASK_PRIO_0, SERIAL_SIGNAL_DELEGATE, serialQueueParameter); - } - if (memberData[UART_ID_0].commandExecutor) - { - system_os_post(USER_TASK_PRIO_0, SERIAL_SIGNAL_COMMAND, serialQueueParameter); - } - } - } -} - void HardwareSerial::delegateTask (os_event_t *inputEvent) { + int uartNr = inputEvent->par >> 25; // the uart_nr is in the last byte + inputEvent->par = inputEvent->par & 0x0FFF; // clear the last bit uint8 rcvChar = inputEvent->par % 256; // can be done by bitlogic, avoid casting from ETSParam uint16 charCount = inputEvent->par / 256 ; @@ -271,17 +252,15 @@ void HardwareSerial::delegateTask (os_event_t *inputEvent) { case SERIAL_SIGNAL_DELEGATE: - if (memberData[UART_ID_0].HWSDelegate) //retest for thread safety - { - memberData[UART_ID_0].HWSDelegate(Serial, rcvChar, charCount ); + if (memberData[uartNr].HWSDelegate) { + memberData[uartNr].HWSDelegate(Serial, rcvChar, charCount ); } break; case SERIAL_SIGNAL_COMMAND: - if (memberData[UART_ID_0].commandExecutor) //retest for thread safety - { - memberData[UART_ID_0].commandExecutor->executorReceive(rcvChar); + if (memberData[uartNr].commandExecutor) { + memberData[uartNr].commandExecutor->executorReceive(rcvChar); } break; @@ -290,7 +269,16 @@ void HardwareSerial::delegateTask (os_event_t *inputEvent) } } +int HardwareSerial::baudRate(void) +{ + // Null pointer on _uart is checked by SDK + return uart_get_baudrate(uart); +} +HardwareSerial::operator bool() const +{ + return uart != 0; +} HardwareSerial Serial(UART_ID_0); diff --git a/Sming/SmingCore/HardwareSerial.h b/Sming/SmingCore/HardwareSerial.h index e2e358f524..a6c9f03c3e 100644 --- a/Sming/SmingCore/HardwareSerial.h +++ b/Sming/SmingCore/HardwareSerial.h @@ -41,10 +41,42 @@ class CommandExecutor; typedef struct { StreamDataReceivedDelegate HWSDelegate; ///< Delegate callback handler - bool useRxBuff; ///< True to use receiver buffer CommandExecutor* commandExecutor = nullptr; ///< Pointer to command executor (Default: none) } HWSerialMemberData; +enum SerialConfig { + SERIAL_5N1 = UART_5N1, + SERIAL_6N1 = UART_6N1, + SERIAL_7N1 = UART_7N1, + SERIAL_8N1 = UART_8N1, + SERIAL_5N2 = UART_5N2, + SERIAL_6N2 = UART_6N2, + SERIAL_7N2 = UART_7N2, + SERIAL_8N2 = UART_8N2, + SERIAL_5E1 = UART_5E1, + SERIAL_6E1 = UART_6E1, + SERIAL_7E1 = UART_7E1, + SERIAL_8E1 = UART_8E1, + SERIAL_5E2 = UART_5E2, + SERIAL_6E2 = UART_6E2, + SERIAL_7E2 = UART_7E2, + SERIAL_8E2 = UART_8E2, + SERIAL_5O1 = UART_5O1, + SERIAL_6O1 = UART_6O1, + SERIAL_7O1 = UART_7O1, + SERIAL_8O1 = UART_8O1, + SERIAL_5O2 = UART_5O2, + SERIAL_6O2 = UART_6O2, + SERIAL_7O2 = UART_7O2, + SERIAL_8O2 = UART_8O2, +}; + +enum SerialMode { + SERIAL_FULL = UART_FULL, + SERIAL_RX_ONLY = UART_RX_ONLY, + SERIAL_TX_ONLY = UART_TX_ONLY +}; + /// Hardware serial class class HardwareSerial : public Stream { @@ -54,12 +86,88 @@ class HardwareSerial : public Stream * @note A global instance of UART 0 is already defined as Serial */ HardwareSerial(const int uartPort); - ~HardwareSerial() {} + ~HardwareSerial(); /** @brief Initialise the serial port * @param baud BAUD rate of the serial port (Default: 9600) */ - void begin(const uint32_t baud = 9600); + void begin(const uint32_t baud = 9600) { + begin(baud, SERIAL_8N1, SERIAL_FULL, 1); + } + + /** + * @brief Initialise and set its configuration. + * @param SerialConfig can be 5, 6, 7, 8 data bits, odd (O), + * even (E), and no (N) parity, and 1 or 2 stop bits. + * To set the desired mode, call Serial.begin(baudrate, SERIAL_8N1), + * Serial.begin(baudrate, SERIAL_6E2), etc. + */ + void begin(const uint32_t baud, SerialConfig config) + { + begin(baud, config, SERIAL_FULL, 1); + } + + /** + * @brief Initialise, set its configuration and mode. + * @param SerialConfig can be 5, 6, 7, 8 data bits, odd (O), + * even (E), and no (N) parity, and 1 or 2 stop bits. + * To set the desired mode, call Serial.begin(baudrate, SERIAL_8N1), + * Serial.begin(baudrate, SERIAL_6E2), etc. + * @param SerialMode specifies if the UART supports receiving (RX), transmitting (TX) or both (FULL) operations + */ + void begin(const uint32_t baud, SerialConfig config, SerialMode mode) + { + begin(baud, config, mode, 1); + } + + void begin(const uint32_t baud, SerialConfig config, SerialMode mode, uint8_t txPin); + + /* + * @brief De-inits the current UART if it is already used + */ + void end(); + + /* + * @brief Sets receiving buffer size + * @param size_t requested size + * @retval size_t actual size + */ + size_t setRxBufferSize(size_t size); + + /* + * @brief Toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX + * @note UART0 uses pins GPIO1 (TX) and GPIO3 (RX). It may be swapped to GPIO15 (TX) and GPIO13 (RX) by calling .swap() after .begin. C + * @note Calling swap again maps UART0 back to GPIO1 and GPIO3. + */ + void swap() + { + swap(1); + } + + /* + * @brief Toggle between use of GPIO13/GPIO15 or GPIO3/GPIO(1/2) as RX and TX + * @param uint8_t Pin number. + */ + void swap(uint8_t tx_pin); + + /* + * @brief Toggle between use of GPIO1 and GPIO2 as TX on UART 0. + * @note: UART 1 can't be used if GPIO2 is used with UART 0! + * @note: If UART1 is not used and UART0 is not swapped - TX for UART0 can be mapped to GPIO2 by calling .setTx(2) after + * .begin or directly with .begin(baud, config, mode, 2). + * + */ + void setTx(uint8_t tx_pin); + + /* + * @brief Sets the transmission and receiving PINS + * @param uint8_t tx Transmission pin number + * @param uint8_t rx Receiving pin number + * @note UART 0 possible options are (1, 3), (2, 3) or (15, 13) + * @note UART 1 allows only TX on 2 if UART 0 is not (2, 3) + */ + void pins(uint8_t tx, uint8_t rx); + /** @brief Get quantity characters available from serial input * @retval int Quantity of characters in receive buffer @@ -87,8 +195,6 @@ class HardwareSerial : public Stream /** @brief Clear the serial port receive buffer * @note All received data is removed from the serial port buffer - * @warning This function is not implemented!!! - * @todo Implement Serial::flush() */ void flush(); @@ -100,8 +206,7 @@ class HardwareSerial : public Stream using Stream::write; - //void printf(const char *fmt, ...); - /** @brief Configure serial port for system debug output + /** @brief Configure serial port for system debug output and redirect output from debugf * @param enabled True to enable this port for system debug output * @note If enabled, port will issue system debug messages */ @@ -116,37 +221,67 @@ class HardwareSerial : public Stream /** @brief Set handler for received data * @param reqCallback Function to handle received data - * @param useSerialRxBuffer True to use the built-in serial receive buffer + * @retval bool Returns true if the callback was set correctly */ - void setCallback(StreamDataReceivedDelegate reqCallback, bool useSerialRxBuffer = true); + bool setCallback(StreamDataReceivedDelegate reqCallback); /** @brief Remove handler for received data */ void resetCallback(); - /** @brief Interrupt handler for UART0 receive events - * @todo Should HardwareSerial::uart0_rx_intr_handler be private? - */ - static void IRAM_ATTR uart0_rx_intr_handler(void *para); + /** + * @brief Checks if the current UART can transmit(print) information + * @retval bool true if transmitting is allowed + */ + bool isTxEnabled(void); - /** @brief Trigger task for input event - * @param inputEvent The event to use for trigger - * @todo Should HardwareSerial::delgateTask be private? + /** + * @brief Checks if the current UART can receive information + * @retval bool true if receiving is allowed */ - static void delegateTask (os_event_t *inputEvent); + bool isRxEnabled(void); + + /** + * @brief Get the current baud rate + * @retval int baud rate + */ + int baudRate(void); + + /** + * @brief Operator that returns true if the uart structure is set + */ + operator bool() const; private: - int uart; + int uartNr; static HWSerialMemberData memberData[NUMBER_UARTS]; - os_event_t * serialQueue; + uart_t* uart = nullptr; + size_t rxSize; + + static os_event_t *serialQueue; + + static bool init; + + /** @brief Interrupt handler for UART0 receive events + * @param uart_t* pointer to UART structure + */ + static void IRAM_ATTR callbackHandler(uart_t *arg); + + /** @brief Trigger task for input event + * @param inputEvent The event to use for trigger + */ + static void delegateTask (os_event_t *inputEvent); }; /** @brief Global instance of serial port UART0 - * @note Use Serial.function to access serial functions + * @note Use Serial.function to access serial functions * @note Example: * @code Serial.begin(115200); - @endcode + * @endcode + * @note Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX). + * @note Serial may be swapped to GPIO15 (TX) and GPIO13 (RX) by calling Serial.swap() after Serial.begin. + * @note Calling swap again maps UART0 back to GPIO1 and GPIO3. */ extern HardwareSerial Serial; diff --git a/Sming/SmingCore/Network/HttpClient.h b/Sming/SmingCore/Network/HttpClient.h index a29aa5c3db..20207f49d9 100644 --- a/Sming/SmingCore/Network/HttpClient.h +++ b/Sming/SmingCore/Network/HttpClient.h @@ -61,11 +61,11 @@ class HttpClient: protected TcpClient void reset(); // Reset current status, data and etc. +#ifdef ENABLE_SSL using TcpClient::addSslOptions; using TcpClient::setSslFingerprint; using TcpClient::setSslClientKeyCert; using TcpClient::freeSslClientKeyCert; -#ifdef ENABLE_SSL using TcpClient::getSsl; #endif diff --git a/Sming/SmingCore/Network/MqttClient.h b/Sming/SmingCore/Network/MqttClient.h index 795e99ab00..b07a28e34f 100644 --- a/Sming/SmingCore/Network/MqttClient.h +++ b/Sming/SmingCore/Network/MqttClient.h @@ -49,11 +49,11 @@ class MqttClient: protected TcpClient bool subscribe(String topic); bool unsubscribe(String topic); +#ifdef ENABLE_SSL using TcpClient::addSslOptions; using TcpClient::setSslFingerprint; using TcpClient::setSslClientKeyCert; using TcpClient::freeSslClientKeyCert; -#ifdef ENABLE_SSL using TcpClient::getSsl; #endif diff --git a/Sming/SmingCore/Network/NetUtils.h b/Sming/SmingCore/Network/NetUtils.h index 302fb1bdec..32108f0027 100644 --- a/Sming/SmingCore/Network/NetUtils.h +++ b/Sming/SmingCore/Network/NetUtils.h @@ -31,7 +31,7 @@ class NetUtils static bool FixNetworkRouting(); // Debug - void debugPrintTcpList(); + static void debugPrintTcpList(); private: static bool ipClientRoutingFixed; diff --git a/Sming/SmingCore/Network/TcpConnection.cpp b/Sming/SmingCore/Network/TcpConnection.cpp index 768271ca09..b31e13b91b 100644 --- a/Sming/SmingCore/Network/TcpConnection.cpp +++ b/Sming/SmingCore/Network/TcpConnection.cpp @@ -19,7 +19,7 @@ TcpConnection::TcpConnection(bool autoDestruct) : autoSelfDestruct(autoDestruct), sleep(0), canSend(true), timeOut(70) { - initialize(tcp_new()); + } TcpConnection::TcpConnection(tcp_pcb* connection, bool autoDestruct) : autoSelfDestruct(autoDestruct), sleep(0), canSend(true), timeOut(70) @@ -32,10 +32,12 @@ TcpConnection::~TcpConnection() autoSelfDestruct = false; close(); +#ifdef ENABLE_SSL if(sslFingerprint) { delete[] sslFingerprint; } freeSslClientKeyCert(); +#endif debugf("~TCP connection"); } @@ -47,9 +49,9 @@ bool TcpConnection::connect(String server, int port, boolean useSsl /* = false * ip_addr_t addr; this->useSsl = useSsl; +#ifdef ENABLE_SSL this->sslOptions |= sslOptions; -#ifdef ENABLE_SSL if(ssl_ext == NULL) { ssl_ext = ssl_ext_new(); ssl_ext->host_name = (char *)malloc(server.length() + 1); @@ -80,9 +82,13 @@ bool TcpConnection::connect(String server, int port, boolean useSsl /* = false * bool TcpConnection::connect(IPAddress addr, uint16_t port, boolean useSsl /* = false */, uint32_t sslOptions /* = 0 */) { + if (tcp == NULL) + initialize(tcp_new()); this->useSsl = useSsl; +#ifdef ENABLE_SSL this->sslOptions |= sslOptions; +#endif return internalTcpConnect(addr, port); } @@ -347,7 +353,7 @@ void TcpConnection::closeTcpConnection(tcp_pcb *tpcb) void TcpConnection::flush() { - if (tcp->state == ESTABLISHED) + if (tcp && tcp->state == ESTABLISHED) { //debugf("TCP flush()"); tcp_output(tcp); @@ -630,6 +636,7 @@ void TcpConnection::staticDnsResponse(const char *name, ip_addr_t *ipaddr, void delete dlook; } +#ifdef ENABLE_SSL void TcpConnection::addSslOptions(uint32_t sslOptions) { this->sslOptions |= sslOptions; } @@ -697,7 +704,6 @@ void TcpConnection::freeSslClientKeyCert() { clientKeyCert.certificateLength = 0; } -#ifdef ENABLE_SSL SSL* TcpConnection::getSsl() { return ssl; } diff --git a/Sming/SmingCore/Network/TcpConnection.h b/Sming/SmingCore/Network/TcpConnection.h index a2c800f034..b091e431ff 100644 --- a/Sming/SmingCore/Network/TcpConnection.h +++ b/Sming/SmingCore/Network/TcpConnection.h @@ -70,6 +70,7 @@ class TcpConnection IPAddress getRemoteIp() { return (tcp == NULL) ? INADDR_NONE : IPAddress(tcp->remote_ip);}; uint16_t getRemotePort() { return (tcp == NULL) ? 0 : tcp->remote_port; }; +#ifdef ENABLE_SSL void addSslOptions(uint32_t sslOptions); /** @@ -101,7 +102,6 @@ class TcpConnection */ void freeSslClientKeyCert(); -#ifdef ENABLE_SSL SSL* getSsl(); #endif @@ -128,7 +128,7 @@ class TcpConnection inline void checkSelfFree() { if (tcp == NULL && autoSelfDestruct) delete this; } protected: - tcp_pcb *tcp; + tcp_pcb *tcp = NULL; uint16_t sleep; uint16_t timeOut; bool canSend; @@ -137,13 +137,13 @@ class TcpConnection SSL *ssl = nullptr; SSLCTX *sslContext = nullptr; SSL_EXTENSIONS *ssl_ext=NULL; -#endif - boolean useSsl = false; uint8_t *sslFingerprint=null; boolean sslConnected = false; uint32_t sslOptions=0; SSLKeyCertPair clientKeyCert; boolean freeClientKeyCert = false; +#endif + boolean useSsl = false; }; #endif /* _SMING_CORE_TCPCONNECTION_H_ */ diff --git a/Sming/SmingCore/Network/TcpServer.cpp b/Sming/SmingCore/Network/TcpServer.cpp index fc766bd6e1..72c8529e79 100644 --- a/Sming/SmingCore/Network/TcpServer.cpp +++ b/Sming/SmingCore/Network/TcpServer.cpp @@ -85,7 +85,7 @@ void TcpServer::setTimeOut(uint16_t waitTimeOut) bool TcpServer::listen(int port) { if (tcp == NULL) - tcp = tcp_new(); + initialize(tcp_new()); err_t res = tcp_bind(tcp, IP_ADDR_ANY, port); if (res != ERR_OK) return res; diff --git a/Sming/SmingCore/Network/WebSocket.cpp b/Sming/SmingCore/Network/WebSocket.cpp index 6780580f59..913a4d875f 100644 --- a/Sming/SmingCore/Network/WebSocket.cpp +++ b/Sming/SmingCore/Network/WebSocket.cpp @@ -75,3 +75,13 @@ void WebSocket::close() { connection->close(); } + +void WebSocket::setUserData(void* userData) +{ + this->userData = userData; +} + +void* WebSocket::getUserData() +{ + return userData; +} diff --git a/Sming/SmingCore/Network/WebSocket.h b/Sming/SmingCore/Network/WebSocket.h index feb4f374cd..b30caecb6b 100644 --- a/Sming/SmingCore/Network/WebSocket.h +++ b/Sming/SmingCore/Network/WebSocket.h @@ -22,18 +22,62 @@ class WebSocket { friend class HttpServer; public: + /** @brief Object class constructor + * @param conn Pointer to HttpServer connection object that this webSocket will use + */ WebSocket(HttpServerConnection* conn); - ~WebSocket(); + /** @brief Virtual object class destructor + */ + virtual ~WebSocket(); + + /** @brief Send data to other peer + * @param message Pointer to buffer to send + * @param length Length of buffer to send + * @param type Frametype of the message to be sent. Default is text frame. + */ virtual void send(const char* message, int length, wsFrameType type = WS_TEXT_FRAME); + + /** @brief Send a string to other peer + * @param message String object holding the message to send + */ void sendString(const String& message); + + /** @brief Send binary data to other peer + * @param data Pointer to buffer to send + * @param size Length of buffer to send + */ void sendBinary(const uint8_t* data, int size); + + /** @brief Enable command processing + */ void enableCommand(); + + /** @brief Close webSocket connection + */ void close(); + + /** @brief Set TCP connection timeout + * @param waitTimeOut TCP timeout + */ void setTimeOut(uint16_t waitTimeOut) { if(connection) connection->setTimeOut(waitTimeOut); }; + /** @brief Test if two sockets are the same + * @param other The other webSocket + * @return true if the two webSockets are defining the same connection + */ bool operator==(const WebSocket &other) const { return this->connection == other.connection;}; + /** @brief Store user data pointer for this socket(connection) + * @param userData Pointer to user defined data + */ + void setUserData(void* userData); + + /** @brief Get user data pointer for this socket(connection) + * @return Pointer to user defined data + */ + void *getUserData(); + protected: bool initialize(HttpRequest &request, HttpResponse &response); bool is(HttpServerConnection* conn) { return connection == conn; }; @@ -41,6 +85,7 @@ class WebSocket private: HttpServerConnection* connection; CommandExecutor* commandExecutor = nullptr; + void* userData = nullptr; }; #endif /* SMINGCORE_NETWORK_WEBSOCKET_H_ */ diff --git a/Sming/SmingCore/Network/WebsocketClient.cpp b/Sming/SmingCore/Network/WebsocketClient.cpp index b35ef4f377..da2040f2eb 100644 --- a/Sming/SmingCore/Network/WebsocketClient.cpp +++ b/Sming/SmingCore/Network/WebsocketClient.cpp @@ -45,21 +45,18 @@ bool WebsocketClient::connect(String url, uint32_t sslOptions /* = 0 */) debugf("Connecting to Server"); unsigned char keyStart[17]; char b64Key[25]; + memset(b64Key, 0, sizeof(b64Key)); _mode = wsMode::Connecting; // Server Connected / WS Upgrade request sent - randomSeed(analogRead(0)); - for (int i = 0; i < 16; ++i) { - keyStart[i] = (char) random(1, 256); + keyStart[i] = 1 + os_random()%255; } base64_encode(16, (const unsigned char*) keyStart, 24, (char*) b64Key); - for (int i = 0; i < 24; ++i) - { - _key[i] = b64Key[i]; - } + _key.setString(b64Key, 24); + String protocol = "chat"; sendString("GET "); if (_uri.Path != "") @@ -103,17 +100,39 @@ void WebsocketClient::onError(err_t err) bool WebsocketClient::_verifyKey(char* buf, int size) { - String dd = String(buf); - uint8_t s = dd.indexOf("Sec-WebSocket-Accept: "); - uint8_t t = dd.indexOf("\r\n", s); - String serverKey = dd.substring(s + 22, t); - String hash = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; - unsigned char data[20]; - char secure[20 * 4]; - sha1(data, hash.c_str(), hash.length()); - base64_encode(20, data, 20 * 4, secure); - // if the keys match, good to go - return serverKey.equals(String(secure)); //b64Result + const char* serverHashedKey = strstri(buf, "sec-websocket-accept: "); + char* endKey = NULL; + unsigned char hashedKey[20]; + char base64HashedKey[20 * 4]; + String keyToHash = _key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; + + if(!serverHashedKey) + { + debugf("wscli cannot find key"); + return false; + } + + serverHashedKey += sizeof("sec-websocket-accept: ") - 1; + endKey = strstr(serverHashedKey, "\r\n"); + + if(!endKey || endKey - buf > size) + { + debugf("wscli cannot find key reason:%s", endKey ? "out of bounds":"NULL"); + return false; + } + + *endKey = 0; + + sha1(hashedKey, keyToHash.c_str(), keyToHash.length()); + base64_encode(sizeof(hashedKey), hashedKey, sizeof(base64HashedKey), base64HashedKey); + + if(strstr(serverHashedKey, base64HashedKey) != serverHashedKey) + { + debugf("wscli key mismatch: %s | %s", serverHashedKey, base64HashedKey); + return false; + } + + return true; } void WebsocketClient::onFinished(TcpClientState finishState) diff --git a/Sming/SmingCore/Network/WebsocketClient.h b/Sming/SmingCore/Network/WebsocketClient.h index 93e104aec6..b29416a89a 100644 --- a/Sming/SmingCore/Network/WebsocketClient.h +++ b/Sming/SmingCore/Network/WebsocketClient.h @@ -104,11 +104,11 @@ class WebsocketClient: protected TcpClient * @retval Returnt websocket client mode */ +#ifdef ENABLE_SSL using TcpClient::addSslOptions; using TcpClient::setSslFingerprint; using TcpClient::setSslClientKeyCert; using TcpClient::freeSslClientKeyCert; -#ifdef ENABLE_SSL using TcpClient::getSsl; #endif diff --git a/Sming/SmingCore/Network/WebsocketFrame.cpp b/Sming/SmingCore/Network/WebsocketFrame.cpp index 3b9f051019..2497787992 100644 --- a/Sming/SmingCore/Network/WebsocketFrame.cpp +++ b/Sming/SmingCore/Network/WebsocketFrame.cpp @@ -118,7 +118,7 @@ uint8_t WebsocketFrameClass::encodeFrame(WSFrameType opcode, uint8_t * payload, //we work on copy of original data so we can mask it without affecting original for (uint8_t x = 0; x < sizeof(maskKey); x++) { - maskKey[x] = random(0xFF); + maskKey[x] = (char) os_random(); *_header = maskKey[x]; _header++; } diff --git a/Sming/SmingCore/Network/rBootHttpUpdate.cpp b/Sming/SmingCore/Network/rBootHttpUpdate.cpp index 7352b8f5d7..baebc1d7f1 100644 --- a/Sming/SmingCore/Network/rBootHttpUpdate.cpp +++ b/Sming/SmingCore/Network/rBootHttpUpdate.cpp @@ -45,15 +45,9 @@ void rBootHttpUpdate::setDelegate(otaUpdateDelegate reqUpdateDelegate) { void rBootHttpUpdate::updateFailed() { timer.stop(); - items.clear(); debugf("\r\nFirmware download failed.."); - if (updateDelegate) updateDelegate(false); -} - -void rBootHttpUpdate::onItemDownloadCompleted(HttpClient& client, bool successful) { - if(successful) { - rboot_write_end(&rBootWriteStatus); - } + if (updateDelegate) updateDelegate(*this, false); + items.clear(); } void rBootHttpUpdate::onTimer() { @@ -61,6 +55,12 @@ void rBootHttpUpdate::onTimer() { if (TcpClient::isProcessing()) return; // Will wait if (TcpClient::getConnectionState() == eTCS_Successful) { + + // always call writeEnd() + if (!writeEnd()) { + debugf("final checks failed!"); + writeError = 1; + } if (!isSuccessful()) { updateFailed(); @@ -85,16 +85,17 @@ void rBootHttpUpdate::onTimer() { rBootHttpUpdateItem &it = items[currentItem]; debugf("Download file:\r\n (%d) %s -> %X", currentItem, it.url.c_str(), it.targetOffset); - rBootWriteStatus = rboot_write_init(items[currentItem].targetOffset); - startDownload(URL(it.url), eHCM_UserDefined, HttpClientCompletedDelegate(&rBootHttpUpdate::onItemDownloadCompleted, this)); + writeInit(); + startDownload(URL(it.url), eHCM_UserDefined, NULL); } + void rBootHttpUpdate::writeRawData(pbuf* buf, int startPos) { pbuf *cur = buf; while (cur != NULL && cur->len > 0 && !writeError) { uint8* ptr = (uint8*) cur->payload + startPos; int len = cur->len - startPos; - writeError = !rboot_write_flash(&rBootWriteStatus, ptr, len); + writeError = !writeFlash(ptr, len); if (writeError) { debugf("Write Error!"); } @@ -104,12 +105,24 @@ void rBootHttpUpdate::writeRawData(pbuf* buf, int startPos) { } } +void rBootHttpUpdate::writeInit() { + rBootWriteStatus = rboot_write_init( items[currentItem].targetOffset ); +} + +bool rBootHttpUpdate::writeFlash(const u8 *data, u16 size) { + return rboot_write_flash(&rBootWriteStatus, (u8 *) data, size ); +} + +bool rBootHttpUpdate::writeEnd() { + return rboot_write_end(&rBootWriteStatus); +} + void rBootHttpUpdate::applyUpdate() { timer.stop(); - items.clear(); if (romSlot == NO_ROM_SWITCH) { debugf("Firmware updated."); - if (updateDelegate) updateDelegate(true); + if (updateDelegate) updateDelegate(*this, true); + items.clear(); } else { // set to boot new rom and then reboot debugf("Firmware updated, rebooting to rom %d...\r\n", romSlot); @@ -118,3 +131,7 @@ void rBootHttpUpdate::applyUpdate() { } return; } + +rBootHttpUpdateItem rBootHttpUpdate::getItem(unsigned int index) { + return items.elementAt(index); +} diff --git a/Sming/SmingCore/Network/rBootHttpUpdate.h b/Sming/SmingCore/Network/rBootHttpUpdate.h index d07ef00786..77f599b48e 100644 --- a/Sming/SmingCore/Network/rBootHttpUpdate.h +++ b/Sming/SmingCore/Network/rBootHttpUpdate.h @@ -15,8 +15,10 @@ #define NO_ROM_SWITCH 0xff +class rBootHttpUpdate; + //typedef void (*otaCallback)(bool result); -typedef Delegate otaUpdateDelegate; +typedef Delegate otaUpdateDelegate; struct rBootHttpUpdateItem { String url; @@ -24,7 +26,7 @@ struct rBootHttpUpdateItem { int size; }; -class rBootHttpUpdate: private HttpClient { +class rBootHttpUpdate: protected HttpClient { public: rBootHttpUpdate(); @@ -35,11 +37,20 @@ class rBootHttpUpdate: private HttpClient { void setCallback(otaUpdateDelegate reqUpdateDelegate); void setDelegate(otaUpdateDelegate reqUpdateDelegate); + + // Expose request and response header information + using HttpClient::setRequestHeader; + using HttpClient::hasRequestHeader; + using HttpClient::getResponseHeader; + + // Allow reading items + rBootHttpUpdateItem getItem(unsigned int index); + +#ifdef ENABLE_SSL using HttpClient::addSslOptions; using HttpClient::setSslFingerprint; using HttpClient::setSslClientKeyCert; using HttpClient::freeSslClientKeyCert; -#ifdef ENABLE_SSL using HttpClient::getSsl; #endif @@ -48,7 +59,6 @@ class rBootHttpUpdate: private HttpClient { virtual void writeRawData(pbuf* buf, int startPos); void applyUpdate(); void updateFailed(); - void onItemDownloadCompleted(HttpClient& client, bool successful); protected: Vector items; @@ -57,6 +67,10 @@ class rBootHttpUpdate: private HttpClient { rboot_write_status rBootWriteStatus; uint8 romSlot; otaUpdateDelegate updateDelegate; + + virtual void writeInit(); + virtual bool writeFlash(const u8 *data, u16 size); + virtual bool writeEnd(); }; #endif /* SMINGCORE_NETWORK_RBOOTHTTPUPDATE_H_ */ diff --git a/Sming/SmingCore/Platform/Station.cpp b/Sming/SmingCore/Platform/Station.cpp index ac8d1676c9..8c0e97ec9d 100644 --- a/Sming/SmingCore/Platform/Station.cpp +++ b/Sming/SmingCore/Platform/Station.cpp @@ -100,14 +100,14 @@ bool StationClass::config(String ssid, String password, bool autoConnectOnStartu return true; } -void StationClass::connect() +bool StationClass::connect() { - wifi_station_connect(); + return wifi_station_connect(); } -void StationClass::disconnect() +bool StationClass::disconnect() { - wifi_station_disconnect(); + return wifi_station_disconnect(); } bool StationClass::isConnected() diff --git a/Sming/SmingCore/Platform/Station.h b/Sming/SmingCore/Platform/Station.h index ab3cb72649..2fc639a7c1 100644 --- a/Sming/SmingCore/Platform/Station.h +++ b/Sming/SmingCore/Platform/Station.h @@ -104,11 +104,11 @@ class StationClass : protected ISystemReadyHandler /** @brief Connect WiFi station to network */ - void connect(); + bool connect(); /** @brief Disconnect WiFi station from network */ - void disconnect(); + bool disconnect(); /** @brief Get WiFi station connectoin status * @retval bool True if connected. diff --git a/Sming/SmingCore/SmingCore.h b/Sming/SmingCore/SmingCore.h index 633e2fa8b0..6b83a14375 100644 --- a/Sming/SmingCore/SmingCore.h +++ b/Sming/SmingCore/SmingCore.h @@ -55,5 +55,6 @@ #include "../Services/DateTime/DateTime.h" #include "../Services/libemqtt/libemqtt.h" #include "../Services/FATFS/ff.h" +#include "../Services/Yeelight/YeelightBulb.h" #endif diff --git a/Sming/Wiring/WConstants.h b/Sming/Wiring/WConstants.h index 3631cc9560..1b431d8398 100644 --- a/Sming/Wiring/WConstants.h +++ b/Sming/Wiring/WConstants.h @@ -40,10 +40,20 @@ #define HIGH 0x1 //#define HIGH 0xFF -#define INPUT 0x0 -#define OUTPUT 0x1 -#define INPUT_PULLUP 0x2 //defined in Arduino > 100 -//#define OUTPUT 0xFF +//GPIO FUNCTIONS +#define INPUT 0x00 +#define INPUT_PULLUP 0x02 +#define INPUT_PULLDOWN_16 0x04 // PULLDOWN only possible for pin16 +#define OUTPUT 0x01 +#define OUTPUT_OPEN_DRAIN 0x03 +#define WAKEUP_PULLUP 0x05 +#define WAKEUP_PULLDOWN 0x07 +#define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi +#define FUNCTION_0 0x08 +#define FUNCTION_1 0x18 +#define FUNCTION_2 0x28 +#define FUNCTION_3 0x38 +#define FUNCTION_4 0x48 #define CHANGE 32 // to avoid conflict with HIGH value #define FALLING 2 diff --git a/Sming/appinit/user_main.cpp b/Sming/appinit/user_main.cpp index f96670e05d..8e57fe8eec 100644 --- a/Sming/appinit/user_main.cpp +++ b/Sming/appinit/user_main.cpp @@ -12,7 +12,7 @@ extern void init(); extern "C" void __attribute__((weak)) user_init(void) { system_timer_reinit(); - uart_div_modify(UART_ID_0, UART_CLK_FREQ / 115200); + uart_div_modify(UART_ID_0, UART_CLK_FREQ / SERIAL_BAUD_RATE); cpp_core_initialize(); System.initialize(); #ifdef SMING_RELEASE @@ -28,6 +28,7 @@ extern "C" void __attribute__((weak)) user_init(void) // For compatibility with SDK v1.1 extern "C" void __attribute__((weak)) user_rf_pre_init(void) { + uart_div_modify(UART_ID_0, UART_CLK_FREQ / SERIAL_BAUD_RATE); // RTC startup fix, author pvvx volatile uint32 * ptr_reg_rtc_ram = (volatile uint32 *)0x60001000; if((ptr_reg_rtc_ram[24] >> 16) > 4) { @@ -35,3 +36,35 @@ extern "C" void __attribute__((weak)) user_rf_pre_init(void) ptr_reg_rtc_ram[30] &= 0; } } + +extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_set(void) +{ + enum flash_size_map size_map = system_get_flash_size_map(); + uint32 rf_cal_sec = 0; + + switch (size_map) { + case FLASH_SIZE_4M_MAP_256_256: + rf_cal_sec = 128 - 5; + break; + + case FLASH_SIZE_8M_MAP_512_512: + rf_cal_sec = 256 - 5; + break; + + case FLASH_SIZE_16M_MAP_512_512: + case FLASH_SIZE_16M_MAP_1024_1024: + rf_cal_sec = 512 - 5; + break; + + case FLASH_SIZE_32M_MAP_512_512: + case FLASH_SIZE_32M_MAP_1024_1024: + rf_cal_sec = 1024 - 5; + break; + + default: + rf_cal_sec = 0; + break; + } + + return rf_cal_sec; +} diff --git a/Sming/compiler/ld/eagle.app.v6.cpp.ld b/Sming/compiler/ld/eagle.app.v6.cpp.ld index b5ec29af45..541b3133fe 100644 --- a/Sming/compiler/ld/eagle.app.v6.cpp.ld +++ b/Sming/compiler/ld/eagle.app.v6.cpp.ld @@ -5,7 +5,7 @@ MEMORY dport0_0_seg : org = 0x3FF00000, len = 0x10 dram0_0_seg : org = 0x3FFE8000, len = 0x14000 iram1_0_seg : org = 0x40100000, len = 0x8000 - irom0_0_seg : org = 0x40209000, len = (1M - 0x9000) + irom0_0_seg : org = 0x4020a000, len = (1M - 0x0a000) } PHDRS diff --git a/Sming/include/user_config.h b/Sming/include/user_config.h index be60de4ff1..d498e0d580 100644 --- a/Sming/include/user_config.h +++ b/Sming/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/Sming/system/flashmem.c b/Sming/system/flashmem.c index 49fa7e2d23..8a7a6495fd 100644 --- a/Sming/system/flashmem.c +++ b/Sming/system/flashmem.c @@ -20,7 +20,6 @@ uint32_t flashmem_write( const void *from, uint32_t toaddr, uint32_t size ) { rest = toaddr & blkmask; temp = toaddr & ~blkmask; // this is the actual aligned address - // c_memcpy( tmpdata, ( const void* )temp, blksize ); flashmem_read_internal( tmpdata, temp, blksize ); for( i = rest; size && ( i < blksize ); i ++, size --, pfrom ++ ) tmpdata[ i ] = *pfrom; @@ -43,8 +42,7 @@ uint32_t flashmem_write( const void *from, uint32_t toaddr, uint32_t size ) // And the final part of a block if needed if( rest ) { - // c_memcpy( tmpdata, ( const void* )toaddr, blksize ); - flashmem_read_internal( tmpdata, toaddr, blksize ); + flashmem_read_internal( tmpdata, toaddr, blksize ); for( i = 0; size && ( i < rest ); i ++, size --, pfrom ++ ) tmpdata[ i ] = *pfrom; flashmem_write_internal( tmpdata, toaddr, blksize ); @@ -155,14 +153,13 @@ uint16_t flashmem_get_size_sectors() // Return the sector number, as well as the start and end address of the sector uint32_t flashmem_find_sector( uint32_t address, uint32_t *pstart, uint32_t *pend ) { - address -= INTERNAL_FLASH_START_ADDRESS; // All the sectors in the flash have the same size, so just align the address uint32_t sect_id = address / INTERNAL_FLASH_SECTOR_SIZE; if( pstart ) - *pstart = sect_id * INTERNAL_FLASH_SECTOR_SIZE + INTERNAL_FLASH_START_ADDRESS; + *pstart = sect_id * INTERNAL_FLASH_SECTOR_SIZE; if( pend ) - *pend = ( sect_id + 1 ) * INTERNAL_FLASH_SECTOR_SIZE + INTERNAL_FLASH_START_ADDRESS - 1; + *pend = ( sect_id + 1 ) * INTERNAL_FLASH_SECTOR_SIZE - 1; return sect_id; } @@ -175,7 +172,6 @@ uint32_t flashmem_get_sector_of_address( uint32_t addr ) uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t size ) { - toaddr -= INTERNAL_FLASH_START_ADDRESS; SpiFlashOpResult r; const uint32_t blkmask = INTERNAL_FLASH_WRITE_UNIT_SIZE - 1; uint32_t *apbuf = NULL; @@ -192,21 +188,20 @@ uint32_t flashmem_write_internal( const void *from, uint32_t toaddr, uint32_t si if(SPI_FLASH_RESULT_OK == r) return size; else{ - SYSTEM_ERROR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr+INTERNAL_FLASH_START_ADDRESS ); + SYSTEM_ERROR( "ERROR in flash_write: r=%d at %08X\n", ( int )r, ( unsigned )toaddr ); return 0; } } uint32_t flashmem_read_internal( void *to, uint32_t fromaddr, uint32_t size ) { - fromaddr -= INTERNAL_FLASH_START_ADDRESS; SpiFlashOpResult r; WRITE_PERI_REG(0x60000914, 0x73); r = spi_flash_read(fromaddr, (uint32 *)to, size); if(SPI_FLASH_RESULT_OK == r) return size; else{ - SYSTEM_ERROR( "ERROR in flash_read: r=%d at %08X\n", ( int )r, ( unsigned )fromaddr+INTERNAL_FLASH_START_ADDRESS ); + SYSTEM_ERROR( "ERROR in flash_read: r=%d at %08X\n", ( int )r, ( unsigned )fromaddr ); return 0; } } diff --git a/Sming/system/include/esp_systemapi.h b/Sming/system/include/esp_systemapi.h index aa8b26b9b3..e9b868977d 100644 --- a/Sming/system/include/esp_systemapi.h +++ b/Sming/system/include/esp_systemapi.h @@ -19,6 +19,7 @@ #include #include "m_printf.h" +#include "stringutil.h" #define __ESP8266_EX__ // System definition ESP8266 SOC diff --git a/Sming/system/include/espinc/uart.h b/Sming/system/include/espinc/uart.h index ed03285438..7e9526c82d 100644 --- a/Sming/system/include/espinc/uart.h +++ b/Sming/system/include/espinc/uart.h @@ -1,96 +1,140 @@ -#ifndef UART_APP_H -#define UART_APP_H - -#include "../espinc/uart_register.h" - -#define RX_BUFF_SIZE 0x100 -#define TX_BUFF_SIZE 100 - -typedef enum { - FIVE_BITS = 0x0, - SIX_BITS = 0x1, - SEVEN_BITS = 0x2, - EIGHT_BITS = 0x3 -} UartBitsNum4Char; - -typedef enum { - ONE_STOP_BIT = 0, - ONE_HALF_STOP_BIT = BIT2, - TWO_STOP_BIT = BIT2 -} UartStopBitsNum; - -typedef enum { - NONE_BITS = 0, - ODD_BITS = 0, - EVEN_BITS = BIT4 -} UartParityMode; - -typedef enum { - STICK_PARITY_DIS = 0, - STICK_PARITY_EN = BIT3 | BIT5 -} UartExistParity; - -typedef enum { - BIT_RATE_9600 = 9600, - BIT_RATE_19200 = 19200, - BIT_RATE_38400 = 38400, - BIT_RATE_57600 = 57600, - BIT_RATE_74880 = 74880, - BIT_RATE_115200 = 115200, - BIT_RATE_230400 = 230400, - BIT_RATE_460800 = 460800, - BIT_RATE_921600 = 921600 -} UartBautRate; - -typedef enum { - NONE_CTRL, - HARDWARE_CTRL, - XON_XOFF_CTRL -} UartFlowCtrl; - -typedef enum { - EMPTY, - UNDER_WRITE, - WRITE_OVER -} RcvMsgBuffState; - -typedef struct { - uint32 RcvBuffSize; - uint8 *pRcvMsgBuff; - uint8 *pWritePos; - uint8 *pReadPos; - uint8 TrigLvl; //JLU: may need to pad - RcvMsgBuffState BuffState; -} RcvMsgBuff; - -typedef struct { - uint32 TrxBuffSize; - uint8 *pTrxBuff; -} TrxMsgBuff; - -typedef enum { - BAUD_RATE_DET, - WAIT_SYNC_FRM, - SRCH_MSG_HEAD, - RCV_MSG_BODY, - RCV_ESC_CHAR, -} RcvMsgState; - -typedef struct { - UartBautRate baut_rate; - UartBitsNum4Char data_bits; - UartExistParity exist_parity; - UartParityMode parity; // chip size in byte - UartStopBitsNum stop_bits; - UartFlowCtrl flow_ctrl; - RcvMsgBuff rcv_buff; - TrxMsgBuff trx_buff; - RcvMsgState rcv_state; - int received; - int buff_uart_no; //indicate which uart use tx/rx buffer -} UartDevice; - -void uart_init(UartBautRate uart0_br, UartBautRate uart1_br); +/* + uart.h - UART HAL + Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ +#ifndef ESP_UART_H +#define ESP_UART_H + +#include +#include + +#if defined (__cplusplus) +extern "C" { +#endif + +#define UART0 0 +#define UART1 1 +#define UART_NO -1 + +// Options for `config` argument of uart_init +#define UART_NB_BIT_MASK 0B00001100 +#define UART_NB_BIT_5 0B00000000 +#define UART_NB_BIT_6 0B00000100 +#define UART_NB_BIT_7 0B00001000 +#define UART_NB_BIT_8 0B00001100 + +#define UART_PARITY_MASK 0B00000011 +#define UART_PARITY_NONE 0B00000000 +#define UART_PARITY_EVEN 0B00000010 +#define UART_PARITY_ODD 0B00000011 + +#define UART_NB_STOP_BIT_MASK 0B00110000 +#define UART_NB_STOP_BIT_0 0B00000000 +#define UART_NB_STOP_BIT_1 0B00010000 +#define UART_NB_STOP_BIT_15 0B00100000 +#define UART_NB_STOP_BIT_2 0B00110000 + +#define UART_5N1 ( UART_NB_BIT_5 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) +#define UART_6N1 ( UART_NB_BIT_6 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) +#define UART_7N1 ( UART_NB_BIT_7 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) +#define UART_8N1 ( UART_NB_BIT_8 | UART_PARITY_NONE | UART_NB_STOP_BIT_1 ) +#define UART_5N2 ( UART_NB_BIT_5 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) +#define UART_6N2 ( UART_NB_BIT_6 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) +#define UART_7N2 ( UART_NB_BIT_7 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) +#define UART_8N2 ( UART_NB_BIT_8 | UART_PARITY_NONE | UART_NB_STOP_BIT_2 ) +#define UART_5E1 ( UART_NB_BIT_5 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) +#define UART_6E1 ( UART_NB_BIT_6 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) +#define UART_7E1 ( UART_NB_BIT_7 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) +#define UART_8E1 ( UART_NB_BIT_8 | UART_PARITY_EVEN | UART_NB_STOP_BIT_1 ) +#define UART_5E2 ( UART_NB_BIT_5 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) +#define UART_6E2 ( UART_NB_BIT_6 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) +#define UART_7E2 ( UART_NB_BIT_7 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) +#define UART_8E2 ( UART_NB_BIT_8 | UART_PARITY_EVEN | UART_NB_STOP_BIT_2 ) +#define UART_5O1 ( UART_NB_BIT_5 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) +#define UART_6O1 ( UART_NB_BIT_6 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) +#define UART_7O1 ( UART_NB_BIT_7 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) +#define UART_8O1 ( UART_NB_BIT_8 | UART_PARITY_ODD | UART_NB_STOP_BIT_1 ) +#define UART_5O2 ( UART_NB_BIT_5 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) +#define UART_6O2 ( UART_NB_BIT_6 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) +#define UART_7O2 ( UART_NB_BIT_7 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) +#define UART_8O2 ( UART_NB_BIT_8 | UART_PARITY_ODD | UART_NB_STOP_BIT_2 ) + +// Options for `mode` argument of uart_init +#define UART_FULL 0 +#define UART_RX_ONLY 1 +#define UART_TX_ONLY 2 + +#define UART_TX_FIFO_SIZE 0x80 + +struct uart_rx_buffer_ { + size_t size; + size_t rpos; + size_t wpos; + uint8_t * buffer; +}; + +struct uart_; + +struct uart_ { + int uart_nr; + int baud_rate; + bool rx_enabled; + bool tx_enabled; + uint8_t rx_pin; + uint8_t tx_pin; + struct uart_rx_buffer_ * rx_buffer; + void (*callback)(struct uart_* arg); +}; + +typedef struct uart_ uart_t; + +uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size); +void uart_uninit(uart_t* uart); + +void uart_swap(uart_t* uart, int tx_pin); +void uart_set_tx(uart_t* uart, int tx_pin); +void uart_set_pins(uart_t* uart, int tx, int rx); +bool uart_tx_enabled(uart_t* uart); +bool uart_rx_enabled(uart_t* uart); + +void uart_set_baudrate(uart_t* uart, int baud_rate); +int uart_get_baudrate(uart_t* uart); + +size_t uart_resize_rx_buffer(uart_t* uart, size_t new_size); + +void uart_write_char(uart_t* uart, char c); +void uart_write(uart_t* uart, const char* buf, size_t size); +int uart_read_char(uart_t* uart); +int uart_peek_char(uart_t* uart); +size_t uart_rx_available(uart_t* uart); +size_t uart_tx_free(uart_t* uart); +void uart_wait_tx_empty(uart_t* uart); +void uart_flush(uart_t* uart); + +void uart_set_debug(int uart_nr); +int uart_get_debug(); +void uart_detach(int uart_nr); + + +#if defined (__cplusplus) +} // extern "C" #endif +#endif // ESP_UART_H diff --git a/Sming/system/include/stringutil.h b/Sming/system/include/stringutil.h new file mode 100644 index 0000000000..6f4478da6a --- /dev/null +++ b/Sming/system/include/stringutil.h @@ -0,0 +1,28 @@ +/* + * StringUtil.h + * + * Contains utility functions for working with char strings. + * + * Created on: 26.01.2017 + * Author: (github.com/)ADiea + */ + +#ifndef INCLUDE_STRINGUTIL_H_ +#define INCLUDE_STRINGUTIL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + /** Return pointer to occurence of substring in string. Case insensitive. + * \param[in] pString string to work with + * \param[in] pToken string to locate + * \return pointer to first occurence in of pToken in pString or NULL if not found + */ +const char* strstri(const char* pString, const char* pToken); + +#ifdef __cplusplus +} +#endif + +#endif //INCLUDE_STRINGUTIL_H_ diff --git a/Sming/system/m_printf.cpp b/Sming/system/m_printf.cpp index 58ada9d24c..4273697e54 100644 --- a/Sming/system/m_printf.cpp +++ b/Sming/system/m_printf.cpp @@ -13,12 +13,19 @@ Descr: embedded very simple version of printf with float support #define OVERFLOW_GUARD 24 -void (*cbc_printchar)(char ch) = uart_tx_one_char; +static void defaultPrintChar(uart_t *uart, char c) { + return uart_tx_one_char(c); +} + +void (*cbc_printchar)(uart_t *, char) = defaultPrintChar; +uart_t *cbc_printchar_uart = NULL; #define SIGN (1<<1) /* Unsigned/signed long */ #define is_digit(c) ((c) >= '0' && (c) <= '9') +#define MIN(a, b) ( (a) < (b) ? (a) : (b) ) + static int skip_atoi(const char **s) { int i = 0; @@ -27,15 +34,16 @@ static int skip_atoi(const char **s) return i; } -void setMPrintfPrinterCbc(void (*callback)(char)) +void setMPrintfPrinterCbc(void (*callback)(uart_t *, char), uart_t *uart) { cbc_printchar = callback; + cbc_printchar_uart = uart; } void m_putc(char c) { if (cbc_printchar) - cbc_printchar(c); + cbc_printchar(cbc_printchar_uart, c); } /** @@ -75,7 +83,7 @@ int m_vprintf ( const char * format, va_list arg ) p = buf; while (p && n < sizeof(buf) && *p) { - cbc_printchar(*p); + cbc_printchar(cbc_printchar_uart, *p); n++; p++; } @@ -148,11 +156,14 @@ int m_vsnprintf(char *buf, size_t maxLen, const char *fmt, va_list args) width = 0; pad = ' '; base = 10; + bool minus = 0; do { + if ('-' == *fmt) minus = 1, fmt++; + //skip width and flags data - not supported - while ('+' == *fmt || '-' == *fmt || '#' == *fmt || '*' == *fmt || 'l' == *fmt) + while ('+' == *fmt || '#' == *fmt || '*' == *fmt || 'l' == *fmt) fmt++; if (is_digit(*fmt)) { @@ -179,20 +190,22 @@ int m_vsnprintf(char *buf, size_t maxLen, const char *fmt, va_list args) *str++ = (unsigned char) va_arg(args, int); continue; - case 's': + case 's': { s = va_arg(args, char *); - if (!s) - { - s = ""; - } - else - { - while (*s && (maxLen - (uint32_t)(str - buf) > OVERFLOW_GUARD)) - *str++ = *s++; - } + if (!s) s = "(null)"; + size_t len = strlen(s); + len = MIN( len, precision ); + len = MIN( len, maxLen - size_t(str - buf) - OVERFLOW_GUARD); + width = MIN( width, maxLen - size_t(str - buf) - OVERFLOW_GUARD); + + int padding = width - len; + while (!minus && padding-- > 0) *str++ = ' '; + while (len--) *str++ = *s++; + while (minus && padding-- > 0) *str++ = ' '; continue; + } case 'p': s = ultoa((unsigned long) va_arg(args, void *), tempNum, 16); diff --git a/Sming/system/stringutil.cpp b/Sming/system/stringutil.cpp new file mode 100644 index 0000000000..a75c2f4463 --- /dev/null +++ b/Sming/system/stringutil.cpp @@ -0,0 +1,48 @@ +/* + * StringUtil.cpp + * + * Contains utility functions for working with char strings. + * + * Created on: 26.01.2017 + * Author: (github.com/)ADiea + */ + +#include "stringutil.h" +#include +#include +#include + +const char* strstri(const char* pString, const char* pToken) +{ + if(!pString || !pToken || !*pToken) + return NULL; + int matchIndex = 0; + + while(*pString) + { + if(tolower(*pString) == tolower(pToken[matchIndex])) + { + //If we reached the end of pToken, return the match + if(pToken[matchIndex + 1] == 0) + { + return pString - matchIndex; + } + else + { + ++matchIndex; + } + ++pString; + } + else + { + //If we were in the middle of a matching process, + // recheck current pString character with + // the first pToken character else increase pString + if(matchIndex) + matchIndex = 0; + else + ++pString; + } + } + return NULL; +} diff --git a/Sming/system/uart.cpp b/Sming/system/uart.cpp new file mode 100644 index 0000000000..87e95f0903 --- /dev/null +++ b/Sming/system/uart.cpp @@ -0,0 +1,520 @@ +/* + uart.cpp - esp8266 UART HAL + + Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + */ + + +/** + * UART GPIOs + * + * UART0 TX: 1 or 2 + * UART0 RX: 3 + * + * UART0 SWAP TX: 15 + * UART0 SWAP RX: 13 + * + * + * UART1 TX: 7 (NC) or 2 + * UART1 RX: 8 (NC) + * + * UART1 SWAP TX: 11 (NC) + * UART1 SWAP RX: 6 (NC) + * + * NC = Not Connected to Module Pads --> No Access + * + */ +#include "Arduino.h" +#include "esp_systemapi.h" +#include "espinc/uart.h" +#include "espinc/peri.h" +#include + +static int s_uart_debug_nr = UART0; + +size_t uart_resize_rx_buffer(uart_t* uart, size_t new_size) +{ + if(uart == NULL || !uart->rx_enabled) { + return 0; + } + if(uart->rx_buffer->size == new_size) { + return uart->rx_buffer->size; + } + uint8_t * new_buf = (uint8_t*)malloc(new_size); + if(!new_buf) { + return uart->rx_buffer->size; + } + size_t new_wpos = 0; + ETS_UART_INTR_DISABLE(); + while(uart_rx_available(uart) && new_wpos < new_size) { + new_buf[new_wpos++] = uart_read_char(uart); + } + uint8_t * old_buf = uart->rx_buffer->buffer; + uart->rx_buffer->rpos = 0; + uart->rx_buffer->wpos = new_wpos; + uart->rx_buffer->size = new_size; + uart->rx_buffer->buffer = new_buf; + free(old_buf); + ETS_UART_INTR_ENABLE(); + return uart->rx_buffer->size; +} + +int uart_peek_char(uart_t* uart) +{ + if(uart == NULL || !uart->rx_enabled) { + return -1; + } + if (!uart_rx_available(uart)) { + return -1; + } + return uart->rx_buffer->buffer[uart->rx_buffer->rpos]; +} + +int uart_read_char(uart_t* uart) +{ + int data = uart_peek_char(uart); + if(data != -1) { + uart->rx_buffer->rpos = (uart->rx_buffer->rpos + 1) % uart->rx_buffer->size; + } + return data; +} + +size_t uart_rx_available(uart_t* uart) +{ + if(uart == NULL || !uart->rx_enabled) { + return 0; + } + if(uart->rx_buffer->wpos < uart->rx_buffer->rpos) { + return (uart->rx_buffer->wpos + uart->rx_buffer->size) - uart->rx_buffer->rpos; + } + return uart->rx_buffer->wpos - uart->rx_buffer->rpos; +} + + +void IRAM_ATTR uart_isr(void * arg) +{ + uart_t* uart = (uart_t*)arg; + if(uart == NULL || !uart->rx_enabled) { + USIC(uart->uart_nr) = USIS(uart->uart_nr); + ETS_UART_INTR_DISABLE(); + return; + } + if(USIS(uart->uart_nr) & ((1 << UIFF) | (1 << UITO))){ + while((USS(uart->uart_nr) >> USRXC) & 0x7F){ + uint8_t data = USF(uart->uart_nr); + size_t nextPos = (uart->rx_buffer->wpos + 1) % uart->rx_buffer->size; + if(nextPos != uart->rx_buffer->rpos) { + uart->rx_buffer->buffer[uart->rx_buffer->wpos] = data; + uart->rx_buffer->wpos = nextPos; + } + } + } + USIC(uart->uart_nr) = USIS(uart->uart_nr); + if(uart->callback) { + uart->callback(uart); + } +} + +void uart_start_isr(uart_t* uart) +{ + if(uart == NULL || !uart->rx_enabled) { + return; + } + USC1(uart->uart_nr) = (127 << UCFFT) | (0x02 << UCTOT) | (1 <uart_nr) = 0xffff; + USIE(uart->uart_nr) = (1 << UIFF) | (1 << UIFR) | (1 << UITO); +// ETS_UART_INTR_ATTACH(uart_isr, (void *)uart); + ETS_UART_INTR_ATTACH((void *)uart_isr, (void *)uart); + ETS_UART_INTR_ENABLE(); +} + +void uart_stop_isr(uart_t* uart) +{ + if(uart == NULL || !uart->rx_enabled) { + return; + } + ETS_UART_INTR_DISABLE(); + USC1(uart->uart_nr) = 0; + USIC(uart->uart_nr) = 0xffff; + USIE(uart->uart_nr) = 0; + ETS_UART_INTR_ATTACH(NULL, NULL); +} + + +void uart_write_char(uart_t* uart, char c) +{ + if(uart == NULL || !uart->tx_enabled) { + return; + } + while((USS(uart->uart_nr) >> USTXC) >= 0x7f); + USF(uart->uart_nr) = c; +} + +void uart_write(uart_t* uart, const char* buf, size_t size) +{ + if(uart == NULL || !uart->tx_enabled) { + return; + } + while(size--) { + uart_write_char(uart, *buf++); + } +} + +size_t uart_tx_free(uart_t* uart) +{ + if(uart == NULL || !uart->tx_enabled) { + return 0; + } + return UART_TX_FIFO_SIZE - ((USS(uart->uart_nr) >> USTXC) & 0xff); +} + +void uart_wait_tx_empty(uart_t* uart) +{ + if(uart == NULL || !uart->tx_enabled) { + return; + } + while(((USS(uart->uart_nr) >> USTXC) & 0xff) > 0) { + delay(0); + } +} + +void uart_flush(uart_t* uart) +{ + if(uart == NULL) { + return; + } + + uint32_t tmp = 0x00000000; + if(uart->rx_enabled) { + tmp |= (1 << UCRXRST); + ETS_UART_INTR_DISABLE(); + uart->rx_buffer->rpos = 0; + uart->rx_buffer->wpos = 0; + ETS_UART_INTR_ENABLE(); + } + + if(uart->tx_enabled) { + tmp |= (1 << UCTXRST); + } + + USC0(uart->uart_nr) |= (tmp); + USC0(uart->uart_nr) &= ~(tmp); +} + +void uart_set_baudrate(uart_t* uart, int baud_rate) +{ + if(uart == NULL) { + return; + } + uart->baud_rate = baud_rate; + USD(uart->uart_nr) = (ESP8266_CLOCK / uart->baud_rate); +} + +int uart_get_baudrate(uart_t* uart) +{ + if(uart == NULL) { + return 0; + } + return uart->baud_rate; +} + +uart_t* uart_init(int uart_nr, int baudrate, int config, int mode, int tx_pin, size_t rx_size) +{ + uart_t* uart = (uart_t*) malloc(sizeof(uart_t)); + if(uart == NULL) { + return NULL; + } + + uart->uart_nr = uart_nr; + + switch(uart->uart_nr) { + case UART0: + ETS_UART_INTR_DISABLE(); + ETS_UART_INTR_ATTACH(NULL, NULL); + uart->rx_enabled = (mode != UART_TX_ONLY); + uart->tx_enabled = (mode != UART_RX_ONLY); + uart->rx_pin = (uart->rx_enabled)?3:255; + if(uart->rx_enabled) { + struct uart_rx_buffer_ * rx_buffer = (struct uart_rx_buffer_ *)malloc(sizeof(struct uart_rx_buffer_)); + if(rx_buffer == NULL) { + free(uart); + return NULL; + } + rx_buffer->size = rx_size;//var this + rx_buffer->rpos = 0; + rx_buffer->wpos = 0; + rx_buffer->buffer = (uint8_t *)malloc(rx_buffer->size); + if(rx_buffer->buffer == NULL) { + free(rx_buffer); + free(uart); + return NULL; + } + uart->rx_buffer = rx_buffer; + pinMode(uart->rx_pin, SPECIAL); + } + if(uart->tx_enabled) { + if (tx_pin == 2) { + uart->tx_pin = 2; + pinMode(uart->tx_pin, FUNCTION_4); + } else { + uart->tx_pin = 1; + pinMode(uart->tx_pin, FUNCTION_0); + } + } else { + uart->tx_pin = 255; + } + IOSWAP &= ~(1 << IOSWAPU0); + break; + case UART1: + // Note: uart_interrupt_handler does not support RX on UART 1. + uart->rx_enabled = false; + uart->tx_enabled = (mode != UART_RX_ONLY); + uart->rx_pin = 255; + uart->tx_pin = (uart->tx_enabled)?2:255; // GPIO7 as TX not possible! See GPIO pins used by UART + if(uart->tx_enabled) { + pinMode(uart->tx_pin, SPECIAL); + } + break; + case UART_NO: + default: + // big fail! + free(uart); + return NULL; + } + + uart_set_baudrate(uart, baudrate); + USC0(uart->uart_nr) = config; + uart_flush(uart); + USC1(uart->uart_nr) = 0; + USIC(uart->uart_nr) = 0xffff; + USIE(uart->uart_nr) = 0; + if(uart->uart_nr == UART0 && uart->rx_enabled) { + uart_start_isr(uart); + } + + return uart; +} + +void uart_uninit(uart_t* uart) +{ + if(uart == NULL) { + return; + } + + switch(uart->rx_pin) { + case 3: + pinMode(3, INPUT); + break; + case 13: + pinMode(13, INPUT); + break; + } + + switch(uart->tx_pin) { + case 1: + pinMode(1, INPUT); + break; + case 2: + pinMode(2, INPUT); + break; + case 15: + pinMode(15, INPUT); + break; + } + + if(uart->rx_enabled){ + free(uart->rx_buffer->buffer); + free(uart->rx_buffer); + uart_stop_isr(uart); + } + free(uart); +} + +void uart_swap(uart_t* uart, int tx_pin) +{ + if(uart == NULL) { + return; + } + switch(uart->uart_nr) { + case UART0: + if(((uart->tx_pin == 1 || uart->tx_pin == 2) && uart->tx_enabled) || (uart->rx_pin == 3 && uart->rx_enabled)) { + if(uart->tx_enabled) { //TX + pinMode(uart->tx_pin, INPUT); + uart->tx_pin = 15; + } + if(uart->rx_enabled) { //RX + pinMode(uart->rx_pin, INPUT); + uart->rx_pin = 13; + } + if(uart->tx_enabled) { + pinMode(uart->tx_pin, FUNCTION_4); //TX + } + if(uart->rx_enabled) { + pinMode(uart->rx_pin, FUNCTION_4); //RX + } + IOSWAP |= (1 << IOSWAPU0); + } else { + if(uart->tx_enabled) { //TX + pinMode(uart->tx_pin, INPUT); + uart->tx_pin = (tx_pin == 2)?2:1; + } + if(uart->rx_enabled) { //RX + pinMode(uart->rx_pin, INPUT); + uart->rx_pin = 3; + } + if(uart->tx_enabled) { + pinMode(uart->tx_pin, (tx_pin == 2)?FUNCTION_4:SPECIAL); //TX + } + if(uart->rx_enabled) { + pinMode(3, SPECIAL); //RX + } + IOSWAP &= ~(1 << IOSWAPU0); + } + + break; + case UART1: + // Currently no swap possible! See GPIO pins used by UART + break; + default: + break; + } +} + +void uart_set_tx(uart_t* uart, int tx_pin) +{ + if(uart == NULL) { + return; + } + switch(uart->uart_nr) { + case UART0: + if(uart->tx_enabled) { + if (uart->tx_pin == 1 && tx_pin == 2) { + pinMode(uart->tx_pin, INPUT); + uart->tx_pin = 2; + pinMode(uart->tx_pin, FUNCTION_4); + } else if (uart->tx_pin == 2 && tx_pin != 2) { + pinMode(uart->tx_pin, INPUT); + uart->tx_pin = 1; + pinMode(uart->tx_pin, SPECIAL); + } + } + + break; + case UART1: + // GPIO7 as TX not possible! See GPIO pins used by UART + break; + default: + break; + } +} + +void uart_set_pins(uart_t* uart, int tx, int rx) +{ + if(uart == NULL) { + return; + } + + if(uart->uart_nr == UART0) { // Only UART0 allows pin changes + if(uart->tx_enabled && uart->tx_pin != tx) { + if( rx == 13 && tx == 15) { + uart_swap(uart, 15); + } else if (rx == 3 && (tx == 1 || tx == 2)) { + if (uart->rx_pin != rx) { + uart_swap(uart, tx); + } else { + uart_set_tx(uart, tx); + } + } + } + if(uart->rx_enabled && uart->rx_pin != rx && rx == 13 && tx == 15) { + uart_swap(uart, 15); + } + } +} + + +bool uart_tx_enabled(uart_t* uart) +{ + if(uart == NULL) { + return false; + } + return uart->tx_enabled; +} + +bool uart_rx_enabled(uart_t* uart) +{ + if(uart == NULL) { + return false; + } + return uart->rx_enabled; +} + + +static void uart_ignore_char(char c) +{ +} + +static void uart0_write_char(char c) +{ + while(((USS(0) >> USTXC) & 0xff) >= 0x7F) { + delay(0); + } + USF(0) = c; +} + +static void uart1_write_char(char c) +{ + while(((USS(1) >> USTXC) & 0xff) >= 0x7F) { + delay(0); + } + USF(1) = c; +} + +void uart_set_debug(int uart_nr) +{ + s_uart_debug_nr = uart_nr; + switch(s_uart_debug_nr) { + case UART0: + system_set_os_print(1); + ets_install_putc1((void *) &uart0_write_char); + break; + case UART1: + system_set_os_print(1); + ets_install_putc1((void *) &uart1_write_char); + break; + case UART_NO: + default: + system_set_os_print(0); + ets_install_putc1((void *) &uart_ignore_char); + break; + } +} + +int uart_get_debug() +{ + return s_uart_debug_nr; +} + +void uart_detach(int uart_nr) { + ETS_UART_INTR_DISABLE(); + USC1(uart_nr) = 0; + USIC(uart_nr) = 0xffff; + USIE(uart_nr) = 0; + ETS_UART_INTR_ATTACH(NULL, NULL); +} diff --git a/Sming/third-party/.patches/axtls-8266.patch b/Sming/third-party/.patches/axtls-8266.patch index 8e47eb009e..0652531733 100644 --- a/Sming/third-party/.patches/axtls-8266.patch +++ b/Sming/third-party/.patches/axtls-8266.patch @@ -368,3 +368,94 @@ index dc577e7..3113355 100644 xxd -i axTLS.key_1024 | sed -e \ - "s/axTLS_key_1024/default_private_key/" > $AXDIR/../ssl/private_key.h + "s/axTLS_key_1024/default_private_key/" > $AXDIR/private_key.h +diff --git a/replacements/time.c b/replacements/time.c +index 4972119..f6f44f8 100644 +--- a/replacements/time.c ++++ b/replacements/time.c +@@ -24,17 +24,19 @@ extern uint64_t system_mktime(uint32_t year, uint32_t mon, uint32_t day, uint32_ + + static int errno_var = 0; + +-int* __errno(void) { ++#define WEAK_ATTR __attribute__((weak)) ++ ++int* WEAK_ATTR __errno(void) { + // DEBUGV("__errno is called last error: %d (not current)\n", errno_var); + return &errno_var; + } + +-unsigned long millis(void) ++unsigned long WEAK_ATTR millis(void) + { + return system_get_time() / 1000UL; + } + +-unsigned long micros(void) ++unsigned long WEAK_ATTR micros(void) + { + return system_get_time(); + } +@@ -79,7 +81,7 @@ static void setServer(int id, const char* name_or_ip) + } + } + +-void configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) ++void WEAK_ATTR configTime(int timezone, int daylightOffset_sec, const char* server1, const char* server2, const char* server3) + { + sntp_stop(); + +@@ -93,7 +95,7 @@ void configTime(int timezone, int daylightOffset_sec, const char* server1, const + sntp_init(); + } + +-int clock_gettime(clockid_t unused, struct timespec *tp) ++int WEAK_ATTR clock_gettime(clockid_t unused, struct timespec *tp) + { + tp->tv_sec = millis() / 1000; + tp->tv_nsec = micros() * 1000; +@@ -101,14 +103,14 @@ int clock_gettime(clockid_t unused, struct timespec *tp) + } + + // seconds since 1970 +-time_t mktime(struct tm *t) ++time_t WEAK_ATTR mktime(struct tm *t) + { + // system_mktime expects month in range 1..12 + #define START_MONTH 1 + return DIFF1900TO1970 + system_mktime(t->tm_year, t->tm_mon + START_MONTH, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); + } + +-time_t time(time_t * t) ++time_t WEAK_ATTR time(time_t * t) + { + time_t seconds = sntp_get_current_timestamp(); + if (t) +@@ -118,24 +120,24 @@ time_t time(time_t * t) + return seconds; + } + +-char* asctime(const struct tm *t) ++char* WEAK_ATTR asctime(const struct tm *t) + { + return sntp_asctime(t); + } + +-struct tm* localtime(const time_t *clock) ++struct tm* WEAK_ATTR localtime(const time_t *clock) + { + return sntp_localtime(clock); + } + +-char* ctime(const time_t *t) ++char* WEAK_ATTR ctime(const time_t *t) + { + struct tm* p_tm = localtime(t); + char* result = asctime(p_tm); + return result; + } + +-int gettimeofday(struct timeval *tp, void *tzp) ++int WEAK_ATTR gettimeofday(struct timeval *tp, void *tzp) + { + if (tp) + { diff --git a/Sming/third-party/.patches/esp-open-lwip.patch b/Sming/third-party/.patches/esp-open-lwip.patch new file mode 100644 index 0000000000..ab86dfe056 --- /dev/null +++ b/Sming/third-party/.patches/esp-open-lwip.patch @@ -0,0 +1,146 @@ +diff --git a/include/user_config.h b/include/user_config.h +index e69de29..3a85c8c 100644 +--- a/include/user_config.h ++++ b/include/user_config.h +@@ -0,0 +1,39 @@ ++#ifndef _USER_CONFIG_LWIP_ ++#define _USER_CONFIG_LWIP_ ++ ++#ifdef __cplusplus ++extern "C" { ++#endif ++ ++typedef signed short sint16_t; ++ ++void *ets_bzero(void *block, size_t size); ++bool ets_post(uint32_t prio, ETSSignal sig, ETSParam par); ++void ets_task(ETSTask task, uint32_t prio, ETSEvent * queue, uint8 qlen); ++ ++void system_pp_recycle_rx_pkt(void *eb); ++ ++#ifndef MEMLEAK_DEBUG ++ extern void *pvPortMalloc( size_t xWantedSize ); ++ extern void vPortFree( void *pv ); ++ extern void *pvPortZalloc(size_t size); ++#else ++ extern void *pvPortMalloc(size_t xWantedSize, const char *file, uint32 line); ++ extern void *pvPortZalloc(size_t xWantedSize, const char *file, uint32 line); ++ extern void vPortFree(void *ptr, const char *file, uint32 line); ++ ++ extern void pvPortFree(void *ptr); ++ extern void *vPortMalloc(size_t xWantedSize); ++#endif /*MEMLEAK_DEBUG*/ ++ ++ ++ extern void *pvPortCalloc(unsigned int n, unsigned int count); ++ extern void *pvPortRealloc(void * p, size_t size); ++ extern size_t xPortGetFreeHeapSize(void); ++// extern void prvHeapInit(void) ICACHE_FLASH_ATTR ; ++ ++#ifdef __cplusplus ++} ++#endif ++ ++#endif /*_USER_CONFIG_LWIP_*/ +diff --git a/Makefile.open b/Makefile.open +index 1bc584f..0bfc424 100644 +--- a/Makefile.open ++++ b/Makefile.open +@@ -1,8 +1,10 @@ +-CC = xtensa-lx106-elf-gcc +-AR = xtensa-lx106-elf-ar ++CC = $(ESP_HOME)/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc ++AR = $(ESP_HOME)/xtensa-lx106-elf/bin/xtensa-lx106-elf-ar + DEFS = -DLWIP_OPEN_SRC -DPBUF_RSV_FOR_WLAN -DEBUF_LWIP -DICACHE_FLASH + COPT = -Os +-CFLAGS = $(DEFS) $(COPT) -Iinclude -Wl,-EL -mlongcalls -mtext-section-literals $(CFLAGS_EXTRA) ++ ++CFLAGS = $(DEFS) $(COPT) -Iinclude -I$(SDK_BASE)/include -Wl,-EL -mlongcalls -mtext-section-literals $(CFLAGS_EXTRA) ++ + # Install prefix of esp-open-sdk toolchain + PREFIX = ~/toolchain/xtensa-lx106-elf + +@@ -36,14 +38,26 @@ lwip/core/ipv4/ip.o \ + lwip/core/ipv4/ip_frag.o \ + lwip/netif/etharp.o \ + \ +-lwip/app/dhcpserver.o \ +-\ +-espconn_dummy.o \ ++lwip/app/dhcpserver.o + +-LIB = liblwip_open.a + +-all: $(LIB) ++ifneq ($(ENABLE_ESPCONN),1) ++ OBJS += espconn_dummy.o ++else ++ OBJS += lwip/app/espconn.o \ ++lwip/app/espconn_tcp.o \ ++lwip/app/espconn_udp.o \ ++lwip/app/espconn_mdns.o \ ++lwip/core/mdns.o + ++endif ++ ++LIB = $(USER_LIBDIR)liblwip_open.a ++ifeq ($(ENABLE_ESPCONN),1) ++ LIB = $(USER_LIBDIR)liblwip_full.a ++endif ++ ++all: $(LIB) + + $(LIB): $(OBJS) + $(AR) rcs $@ $^ +diff --git a/include/arch/cc.h b/include/arch/cc.h +index ff03b30..932c73d 100644 +--- a/include/arch/cc.h ++++ b/include/arch/cc.h +@@ -38,8 +38,25 @@ + #include "c_types.h" + #include "ets_sys.h" + #include "osapi.h" ++#include ++ + #define EFAULT 14 + ++//Extra symbols to avoid implicit declaration warnings ++extern void *ets_memset(void *s, int c, size_t n); ++extern void ets_memcpy(void*, const void*, uint32); ++ ++extern size_t ets_strlen(const char *s); ++extern int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); ++extern int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); ++extern void ets_timer_arm_new(ETSTimer *ptimer, uint32_t milliseconds, bool repeat_flag, int isMstimer); ++extern void ets_timer_disarm(ETSTimer *a); ++extern void ets_timer_setfn(ETSTimer *t, ETSTimerFunc *pfunction, void *parg); ++extern uint32 r_rand(void); ++extern int ets_memcmp(const void *s1, const void *s2, size_t n); ++ ++struct netif * eagle_lwip_getif(uint8 index); ++ + //#define LWIP_PROVIDE_ERRNO + + #if (1) +@@ -56,6 +73,7 @@ typedef signed short s16_t; + typedef unsigned long u32_t; + typedef signed long s32_t; + typedef unsigned long mem_ptr_t; ++typedef signed short sint16_t; + + #define S16_F "d" + #define U16_F "d" + +diff --git a/include/lwipopts.h b/include/lwipopts.h +index eaa8dd6..6a08192 100644 +--- a/include/lwipopts.h ++++ b/include/lwipopts.h +@@ -953,7 +953,7 @@ + * an upper limit on the MSS advertised by the remote host. + */ + #ifndef TCP_MSS +-#define TCP_MSS 1460 ++#define TCP_MSS 1390 + #endif + #endif + diff --git a/Sming/third-party/.patches/rboot.patch b/Sming/third-party/.patches/rboot.patch new file mode 100644 index 0000000000..5c062ad9d6 --- /dev/null +++ b/Sming/third-party/.patches/rboot.patch @@ -0,0 +1,47 @@ +diff --git a/Makefile b/Makefile +index ca234de..08b0fba 100644 +--- a/Makefile ++++ b/Makefile +@@ -55,6 +55,12 @@ endif + ifeq ($(RBOOT_IROM_CHKSUM),1) + CFLAGS += -DBOOT_IROM_CHKSUM + endif ++ifneq ($(RBOOT_ROM1_ADDR),) ++ CFLAGS += -DBOOT_ROM1_ADDR=$(RBOOT_ROM1_ADDR) ++endif ++ifneq ($(RBOOT_ROM2_ADDR),) ++ CFLAGS += -DBOOT_ROM2_ADDR=$(RBOOT_ROM2_ADDR) ++endif + ifneq ($(RBOOT_EXTRA_INCDIR),) + CFLAGS += $(addprefix -I,$(RBOOT_EXTRA_INCDIR)) + endif +diff --git a/rboot.c b/rboot.c +index 6e10a2f..7ac60a8 100644 +--- a/rboot.c ++++ b/rboot.c +@@ -250,7 +250,25 @@ static uint8 calc_chksum(uint8 *start, uint8 *end) { + static uint8 default_config(rboot_config *romconf, uint32 flashsize) { + romconf->count = 2; + romconf->roms[0] = SECTOR_SIZE * (BOOT_CONFIG_SECTOR + 1); ++ ++#ifdef BOOT_ROM1_ADDR ++ romconf->roms[1] = BOOT_ROM1_ADDR; ++#else + romconf->roms[1] = (flashsize / 2) + (SECTOR_SIZE * (BOOT_CONFIG_SECTOR + 1)); ++#endif ++ ++#if defined(BOOT_BIG_FLASH) && defined(BOOT_GPIO_ENABLED) ++ if(flashsize > 0x200000) { ++ romconf->count += 1; ++#ifdef BOOT_ROM2_ADDR ++ romconf->roms[2] = BOOT_ROM2_ADDR; ++#else ++ romconf->roms[2] = 0x310000; ++#endif ++ romconf->gpio_rom = 2; ++ } ++#endif ++ + #ifdef BOOT_GPIO_ENABLED + romconf->mode = MODE_GPIO_ROM; + #endif diff --git a/Sming/third-party/esp-open-lwip b/Sming/third-party/esp-open-lwip new file mode 160000 index 0000000000..b9a23a6e9e --- /dev/null +++ b/Sming/third-party/esp-open-lwip @@ -0,0 +1 @@ +Subproject commit b9a23a6e9ef88d995ae74014e71a6a4227f61d62 diff --git a/samples/Accelerometer_MMA7455/include/user_config.h b/samples/Accelerometer_MMA7455/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Accelerometer_MMA7455/include/user_config.h +++ b/samples/Accelerometer_MMA7455/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Arducam/include/user_config.h b/samples/Arducam/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Arducam/include/user_config.h +++ b/samples/Arducam/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_APA102/include/user_config.h b/samples/Basic_APA102/include/user_config.h index 85f8955e18..85737379ca 100644 --- a/samples/Basic_APA102/include/user_config.h +++ b/samples/Basic_APA102/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_AirUpdate/include/user_config.h b/samples/Basic_AirUpdate/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_AirUpdate/include/user_config.h +++ b/samples/Basic_AirUpdate/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Blink/include/user_config.h b/samples/Basic_Blink/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Blink/include/user_config.h +++ b/samples/Basic_Blink/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Capsense/include/user_config.h b/samples/Basic_Capsense/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Capsense/include/user_config.h +++ b/samples/Basic_Capsense/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Delegates/include/user_config.h b/samples/Basic_Delegates/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Delegates/include/user_config.h +++ b/samples/Basic_Delegates/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_HwPWM/include/user_config.h b/samples/Basic_HwPWM/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_HwPWM/include/user_config.h +++ b/samples/Basic_HwPWM/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Interrupts/include/user_config.h b/samples/Basic_Interrupts/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Interrupts/include/user_config.h +++ b/samples/Basic_Interrupts/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Neopixel/include/user_config.h b/samples/Basic_Neopixel/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Neopixel/include/user_config.h +++ b/samples/Basic_Neopixel/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_PWM/include/user_config.h b/samples/Basic_PWM/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_PWM/include/user_config.h +++ b/samples/Basic_PWM/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_ProgMem/include/user_config.h b/samples/Basic_ProgMem/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_ProgMem/include/user_config.h +++ b/samples/Basic_ProgMem/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_ScannerI2C/app/application.cpp b/samples/Basic_ScannerI2C/app/application.cpp index 49a91b0c2a..889e24d298 100644 --- a/samples/Basic_ScannerI2C/app/application.cpp +++ b/samples/Basic_ScannerI2C/app/application.cpp @@ -81,6 +81,8 @@ void init() WDT.enable(false); // First (but not the best) option: fully disable watch dog timer + // Default I2C pins (SCL:0 , SDA: 2) + // You can change pins: //Wire.pins(12, 14); // SCL, SDA diff --git a/samples/Basic_ScannerI2C/include/user_config.h b/samples/Basic_ScannerI2C/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_ScannerI2C/include/user_config.h +++ b/samples/Basic_ScannerI2C/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Serial/app/application.cpp b/samples/Basic_Serial/app/application.cpp index 3e0ded5d52..476c68bcbb 100644 --- a/samples/Basic_Serial/app/application.cpp +++ b/samples/Basic_Serial/app/application.cpp @@ -73,6 +73,45 @@ void init() { Serial.begin(SERIAL_BAUD_RATE); // 115200 by default + debugf("\n(DEBUG) message printed on UART0"); + + /* + * Notice: The line below disables the debugf output on all UARTs. + */ + Serial.systemDebugOutput(false); + + debugf("(DEBUG) don't print me at all"); + + /* + * The debugf output is redirected to UART0 + * together with the system debug messages. + */ + Serial.systemDebugOutput(true); + delay(200); + + debugf("(DEBUG) print me again on UART0"); + + /** + * Serial1 uses UART1, TX pin is GPIO2. + * UART1 can not be used to receive data because normally + * it's RX pin is occupied for flash chip connection. + * + * If you have a spare serial to USB converter do the following to see the + * messages printed on UART1: + * - connect converter GND to esp8266 GND + * - connect converter RX to esp8266 GPIO2 + */ + HardwareSerial Serial1(UART1); + Serial1.begin(SERIAL_BAUD_RATE); + + /* + * The line below redirect debug output to UART1 + */ + Serial1.systemDebugOutput(true); + Serial1.printf("====Debug Information=====\n"); + + debugf("(DEBUG) message printed on UART1"); // You should see the debug message in UART1 only. + procTimer.initializeMs(2000, sayHello).start(); testPrintf(); @@ -81,6 +120,8 @@ void init() // * Option 1 // Set Serial Callback to global routine: // Serial.setCallback(onDataCallback); + // If you want to test local echo set the following callback + // Serial.setCallback(echoCallback); // * Option 2 // Instantiate hwsDelegateDemo which includes Serial Delegate class diff --git a/samples/Basic_Serial/include/SerialReadingDelegateDemo.h b/samples/Basic_Serial/include/SerialReadingDelegateDemo.h index 4440e1e7a9..f6b11e73d5 100644 --- a/samples/Basic_Serial/include/SerialReadingDelegateDemo.h +++ b/samples/Basic_Serial/include/SerialReadingDelegateDemo.h @@ -4,6 +4,12 @@ //*** Example of global callback routine void onDataCallback(Stream& stream, char arrivedChar, unsigned short availableCharsCount) { + Serial.printf("Char: %d, Count: %d\n", (uint8_t)arrivedChar, availableCharsCount); +} + +void echoCallback(Stream& stream, char arrivedChar, unsigned short availableCharsCount) +{ + stream.write(arrivedChar); } //*** Example of class callback processing diff --git a/samples/Basic_Serial/include/user_config.h b/samples/Basic_Serial/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Serial/include/user_config.h +++ b/samples/Basic_Serial/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Servo/include/user_config.h b/samples/Basic_Servo/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_Servo/include/user_config.h +++ b/samples/Basic_Servo/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_SmartConfig/Makefile-user.mk b/samples/Basic_SmartConfig/Makefile-user.mk index bd088ca354..3622c2d308 100644 --- a/samples/Basic_SmartConfig/Makefile-user.mk +++ b/samples/Basic_SmartConfig/Makefile-user.mk @@ -37,3 +37,5 @@ DISABLE_SPIFFS = 1 # SPIFF_FILES = files +# If you use custom LWIP compilation make sure to enable espconn because libsmartconfig uses it +ENABLE_ESPCONN = 1 diff --git a/samples/Basic_SmartConfig/include/user_config.h b/samples/Basic_SmartConfig/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_SmartConfig/include/user_config.h +++ b/samples/Basic_SmartConfig/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_Ssl/include/user_config.h b/samples/Basic_Ssl/include/user_config.h index b8346549aa..ae46bf06b9 100644 --- a/samples/Basic_Ssl/include/user_config.h +++ b/samples/Basic_Ssl/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_WebSkeletonApp/include/user_config.h b/samples/Basic_WebSkeletonApp/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_WebSkeletonApp/include/user_config.h +++ b/samples/Basic_WebSkeletonApp/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_WiFi/include/user_config.h b/samples/Basic_WiFi/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_WiFi/include/user_config.h +++ b/samples/Basic_WiFi/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Basic_rBoot/app/application.cpp b/samples/Basic_rBoot/app/application.cpp index cf8c09b764..46b03d4565 100644 --- a/samples/Basic_rBoot/app/application.cpp +++ b/samples/Basic_rBoot/app/application.cpp @@ -14,7 +14,7 @@ rBootHttpUpdate* otaUpdater = 0; -void OtaUpdate_CallBack(bool result) { +void OtaUpdate_CallBack(rBootHttpUpdate& client, bool result) { Serial.println("In callback..."); if(result == true) { @@ -98,7 +98,6 @@ void ShowInfo() { } void serialCallBack(Stream& stream, char arrivedChar, unsigned short availableCharsCount) { - if (arrivedChar == '\n') { char str[availableCharsCount]; @@ -108,7 +107,7 @@ void serialCallBack(Stream& stream, char arrivedChar, unsigned short availableCh str[i] = '\0'; } } - + if (!strcmp(str, "connect")) { // connect to wifi WifiStation.config(WIFI_SSID, WIFI_PWD); @@ -168,19 +167,19 @@ void init() { #ifndef DISABLE_SPIFFS if (slot == 0) { #ifdef RBOOT_SPIFFS_0 - debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE); - spiffs_mount_manual(RBOOT_SPIFFS_0 + 0x40200000, SPIFF_SIZE); + debugf("trying to mount spiffs at 0x%08x, length %d", RBOOT_SPIFFS_0, SPIFF_SIZE); + spiffs_mount_manual(RBOOT_SPIFFS_0, SPIFF_SIZE); #else - debugf("trying to mount spiffs at %x, length %d", 0x40300000, SPIFF_SIZE); - spiffs_mount_manual(0x40300000, SPIFF_SIZE); + debugf("trying to mount spiffs at 0x%08x, length %d", 0x100000, SPIFF_SIZE); + spiffs_mount_manual(0x100000, SPIFF_SIZE); #endif } else { #ifdef RBOOT_SPIFFS_1 - debugf("trying to mount spiffs at %x, length %d", RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE); - spiffs_mount_manual(RBOOT_SPIFFS_1 + 0x40200000, SPIFF_SIZE); + debugf("trying to mount spiffs at 0x%08x, length %d", RBOOT_SPIFFS_1, SPIFF_SIZE); + spiffs_mount_manual(RBOOT_SPIFFS_1, SPIFF_SIZE); #else - debugf("trying to mount spiffs at %x, length %d", 0x40500000, SPIFF_SIZE); - spiffs_mount_manual(0x40500000, SPIFF_SIZE); + debugf("trying to mount spiffs at 0x%08x, length %d", 0x300000, SPIFF_SIZE); + spiffs_mount_manual(0x300000, SPIFF_SIZE); #endif } #else diff --git a/samples/Basic_rBoot/include/user_config.h b/samples/Basic_rBoot/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Basic_rBoot/include/user_config.h +++ b/samples/Basic_rBoot/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/CommandProcessing_Debug/include/user_config.h b/samples/CommandProcessing_Debug/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/CommandProcessing_Debug/include/user_config.h +++ b/samples/CommandProcessing_Debug/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Compass_HMC5883L/include/user_config.h b/samples/Compass_HMC5883L/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Compass_HMC5883L/include/user_config.h +++ b/samples/Compass_HMC5883L/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/DNSCaptivePortal/include/user_config.h b/samples/DNSCaptivePortal/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/DNSCaptivePortal/include/user_config.h +++ b/samples/DNSCaptivePortal/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/DS3232RTC_NTP_Setter/include/user_config.h b/samples/DS3232RTC_NTP_Setter/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/DS3232RTC_NTP_Setter/include/user_config.h +++ b/samples/DS3232RTC_NTP_Setter/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Echo_Ssl/include/user_config.h b/samples/Echo_Ssl/include/user_config.h index b8346549aa..ae46bf06b9 100644 --- a/samples/Echo_Ssl/include/user_config.h +++ b/samples/Echo_Ssl/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/FtpServer_Files/include/user_config.h b/samples/FtpServer_Files/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/FtpServer_Files/include/user_config.h +++ b/samples/FtpServer_Files/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Gesture_APDS-9960/include/user_config.h b/samples/Gesture_APDS-9960/include/user_config.h index 856588396f..09f6417156 100644 --- a/samples/Gesture_APDS-9960/include/user_config.h +++ b/samples/Gesture_APDS-9960/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/HttpClient_Instapush/include/user_config.h b/samples/HttpClient_Instapush/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/HttpClient_Instapush/include/user_config.h +++ b/samples/HttpClient_Instapush/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/HttpClient_ThingSpeak/include/user_config.h b/samples/HttpClient_ThingSpeak/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/HttpClient_ThingSpeak/include/user_config.h +++ b/samples/HttpClient_ThingSpeak/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/HttpServer_AJAX/include/user_config.h b/samples/HttpServer_AJAX/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/HttpServer_AJAX/include/user_config.h +++ b/samples/HttpServer_AJAX/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/HttpServer_Bootstrap/include/user_config.h b/samples/HttpServer_Bootstrap/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/HttpServer_Bootstrap/include/user_config.h +++ b/samples/HttpServer_Bootstrap/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/HttpServer_ConfigNetwork/include/user_config.h b/samples/HttpServer_ConfigNetwork/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/HttpServer_ConfigNetwork/include/user_config.h +++ b/samples/HttpServer_ConfigNetwork/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/HttpServer_WebSockets/app/CUserData.cpp b/samples/HttpServer_WebSockets/app/CUserData.cpp new file mode 100644 index 0000000000..a1cf987df7 --- /dev/null +++ b/samples/HttpServer_WebSockets/app/CUserData.cpp @@ -0,0 +1,61 @@ +#include "CUserData.h" + +//Simplified container modelling a user session +CUserData::CUserData(const char* uName, const char* uData):userName(uName), userData(uData) +{ + +} +CUserData::~CUserData() +{ + logOut(); +} + +void CUserData::addSession(WebSocket& connection) +{ + activeWebSockets.addElement(&connection); + connection.setUserData((void*)this); +} + +void CUserData::removeSession(WebSocket& connection) +{ + for(int i=0; i < activeWebSockets.count(); i++) + { + if(connection == *(activeWebSockets[i])) + { + activeWebSockets[i]->setUserData(nullptr); + activeWebSockets.remove(i); + Serial.println("Removed user session"); + return; + } + } +} + +void CUserData::printMessage(WebSocket& connection,const String &msg) +{ + int i=0; + for(; i < activeWebSockets.count(); i++) + { + if(connection == *(activeWebSockets[i])) + { + break; + } + } + + if(i < activeWebSockets.count()) + { + Serial.print("Received msg on connection "); + Serial.print(i); + Serial.print(" :"); + Serial.print(msg); + } +} + +void CUserData::logOut() +{ + for(int i=0; i < activeWebSockets.count(); i++) + { + activeWebSockets[i]->setUserData(nullptr); + } + + activeWebSockets.removeAllElements(); +} diff --git a/samples/HttpServer_WebSockets/app/application.cpp b/samples/HttpServer_WebSockets/app/application.cpp index 11f6dac7ed..47673c0fe5 100644 --- a/samples/HttpServer_WebSockets/app/application.cpp +++ b/samples/HttpServer_WebSockets/app/application.cpp @@ -1,5 +1,6 @@ #include #include +#include "CUserData.h" // If you want, you can define WiFi settings globally in Eclipse Environment Variables #ifndef WIFI_SSID @@ -10,6 +11,8 @@ HttpServer server; int totalActiveSockets = 0; +CUserData userGeorge("George", "I like SMING"); + void onIndex(HttpRequest &request, HttpResponse &response) { TemplateFileStream *tmpl = new TemplateFileStream("index.html"); @@ -37,6 +40,8 @@ void wsConnected(WebSocket& socket) { totalActiveSockets++; + //Use a global instance and add this new connection. Normally + userGeorge.addSession(socket); // Notify everybody about new connection WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++) @@ -48,6 +53,13 @@ void wsMessageReceived(WebSocket& socket, const String& message) Serial.printf("WebSocket message received:\r\n%s\r\n", message.c_str()); String response = "Echo: " + message; socket.sendString(response); + + //Normally you would use dynamic cast but just be careful not to convert to wrong object type! + CUserData *user = (CUserData*) socket.getUserData(); + if(user) + { + user->printMessage(socket, message); + } } void wsBinaryReceived(WebSocket& socket, uint8_t* data, size_t size) @@ -59,6 +71,13 @@ void wsDisconnected(WebSocket& socket) { totalActiveSockets--; + //Normally you would use dynamic cast but just be careful not to convert to wrong object type! + CUserData *user = (CUserData*) socket.getUserData(); + if(user) + { + user->removeSession(socket); + } + // Notify everybody about lost connection WebSocketsList &clients = server.getActiveWebSockets(); for (int i = 0; i < clients.count(); i++) diff --git a/samples/HttpServer_WebSockets/include/CUserData.h b/samples/HttpServer_WebSockets/include/CUserData.h new file mode 100644 index 0000000000..d5ff82cd72 --- /dev/null +++ b/samples/HttpServer_WebSockets/include/CUserData.h @@ -0,0 +1,23 @@ +#ifndef C_USER_DATA_H_SAMPLE +#define C_USER_DATA_H_SAMPLE + +#include +#include + +//Simplified container modelling a user session +class CUserData +{ +public: + CUserData(const char* uName, const char* uData); + ~CUserData(); + void addSession(WebSocket& connection); + void removeSession(WebSocket& connection); + void printMessage(WebSocket& connection,const String &msg); + void logOut(); +private: + String userName; + String userData; + Vector activeWebSockets; +}; + +#endif /*C_USER_DATA_H_SAMPLE*/ diff --git a/samples/HttpServer_WebSockets/include/user_config.h b/samples/HttpServer_WebSockets/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/HttpServer_WebSockets/include/user_config.h +++ b/samples/HttpServer_WebSockets/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Humidity_AM2321/.cproject b/samples/Humidity_AM2321/.cproject new file mode 100644 index 0000000000..67c056d24e --- /dev/null +++ b/samples/Humidity_AM2321/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Humidity_AM2321/.project b/samples/Humidity_AM2321/.project new file mode 100644 index 0000000000..c499df7d4f --- /dev/null +++ b/samples/Humidity_AM2321/.project @@ -0,0 +1,28 @@ + + + Humidity_AM2321 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/Humidity_AM2321/Makefile b/samples/Humidity_AM2321/Makefile new file mode 100644 index 0000000000..16d76cd676 --- /dev/null +++ b/samples/Humidity_AM2321/Makefile @@ -0,0 +1,24 @@ +##################################################################### +#### Please don't change this file. Use Makefile-user.mk instead #### +##################################################################### +# Including user Makefile. +# Should be used to set project-specific parameters +include ./Makefile-user.mk + +# Important parameters check. +# We need to make sure SMING_HOME and ESP_HOME variables are set. +# You can use Makefile-user.mk in each project or use enviromental variables to set it globally. + +ifndef SMING_HOME +$(error SMING_HOME is not set. Please configure it in Makefile-user.mk) +endif +ifndef ESP_HOME +$(error ESP_HOME is not set. Please configure it in Makefile-user.mk) +endif + +# Include main Sming Makefile +ifeq ($(RBOOT_ENABLED), 1) +include $(SMING_HOME)/Makefile-rboot.mk +else +include $(SMING_HOME)/Makefile-project.mk +endif diff --git a/samples/Humidity_AM2321/Makefile-user.mk b/samples/Humidity_AM2321/Makefile-user.mk new file mode 100644 index 0000000000..bd088ca354 --- /dev/null +++ b/samples/Humidity_AM2321/Makefile-user.mk @@ -0,0 +1,39 @@ +## Local build configuration +## Parameters configured here will override default and ENV values. +## Uncomment and change examples: + +## Add your source directories here separated by space +# MODULES = app +# EXTRA_INCDIR = include + +## ESP_HOME sets the path where ESP tools and SDK are located. +## Windows: +# ESP_HOME = c:/Espressif + +## MacOS / Linux: +# ESP_HOME = /opt/esp-open-sdk + +## SMING_HOME sets the path where Sming framework is located. +## Windows: +# SMING_HOME = c:/tools/sming/Sming + +## MacOS / Linux +# SMING_HOME = /opt/sming/Sming + +## COM port parameter is reqruied to flash firmware correctly. +## Windows: +# COM_PORT = COM3 + +## MacOS / Linux: +# COM_PORT = /dev/tty.usbserial + +## Com port speed +# COM_SPEED = 115200 + +## Configure flash parameters (for ESP12-E and other new boards): +# SPI_MODE = dio + +## SPIFFS options +DISABLE_SPIFFS = 1 +# SPIFF_FILES = files + diff --git a/samples/Humidity_AM2321/app/application.cpp b/samples/Humidity_AM2321/app/application.cpp new file mode 100644 index 0000000000..fa72a08f9a --- /dev/null +++ b/samples/Humidity_AM2321/app/application.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "Libraries/AM2321/AM2321.h" + +AM2321 am2321; + +Timer procTimer; +bool state = true; + +void read() +{ + Serial.print(am2321.read()); + Serial.print(","); + Serial.print(am2321.temperature / 10.0); + Serial.print(","); + Serial.println(am2321.humidity / 10.0); +} + +void init() +{ + Serial.begin(SERIAL_BAUD_RATE); // 115200 by default + Serial.systemDebugOutput(true); // Enable/disable debug output + + // Default I2C pins (SCL:0 , SDA: 2) + + // You can change pins: + //Wire.pins(12, 14); // SCL, SDA + + am2321.begin(); // REQUIRED. Call it after choosing I2C pins. + Serial.println(am2321.uid()); + + procTimer.initializeMs(3000, read).start(); +} diff --git a/samples/Humidity_AM2321/include/user_config.h b/samples/Humidity_AM2321/include/user_config.h new file mode 100644 index 0000000000..09825be2b5 --- /dev/null +++ b/samples/Humidity_AM2321/include/user_config.h @@ -0,0 +1,45 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + // UART config + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL + + // ESP SDK config + #define LWIP_OPEN_SRC + #define USE_US_TIMER + + // Default types + #define __CORRECT_ISO_CPP_STDLIB_H_PROTO + #include + #include + + // Override c_types.h include and remove buggy espconn + #define _C_TYPES_H_ + #define _NO_ESPCON_ + + // Updated, compatible version of c_types.h + // Just removed types declared in + #include + + // System API declarations + #include + + // C++ Support + #include + // Extended string conversion for compatibility + #include + // Network base API + #include + + // Beta boards + #define BOARD_ESP01 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/samples/Humidity_DHT22/include/user_config.h b/samples/Humidity_DHT22/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Humidity_DHT22/include/user_config.h +++ b/samples/Humidity_DHT22/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Humidity_SI7021/include/user_config.h b/samples/Humidity_SI7021/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Humidity_SI7021/include/user_config.h +++ b/samples/Humidity_SI7021/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/IR_lib/include/user_config.h b/samples/IR_lib/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/IR_lib/include/user_config.h +++ b/samples/IR_lib/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/LED_WS2812/include/user_config.h b/samples/LED_WS2812/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/LED_WS2812/include/user_config.h +++ b/samples/LED_WS2812/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/LED_YeelightBulb/.cproject b/samples/LED_YeelightBulb/.cproject new file mode 100644 index 0000000000..67c056d24e --- /dev/null +++ b/samples/LED_YeelightBulb/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/LED_YeelightBulb/.project b/samples/LED_YeelightBulb/.project new file mode 100644 index 0000000000..be1925a270 --- /dev/null +++ b/samples/LED_YeelightBulb/.project @@ -0,0 +1,28 @@ + + + LED_YeelightBulb + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/LED_YeelightBulb/Makefile b/samples/LED_YeelightBulb/Makefile new file mode 100644 index 0000000000..16d76cd676 --- /dev/null +++ b/samples/LED_YeelightBulb/Makefile @@ -0,0 +1,24 @@ +##################################################################### +#### Please don't change this file. Use Makefile-user.mk instead #### +##################################################################### +# Including user Makefile. +# Should be used to set project-specific parameters +include ./Makefile-user.mk + +# Important parameters check. +# We need to make sure SMING_HOME and ESP_HOME variables are set. +# You can use Makefile-user.mk in each project or use enviromental variables to set it globally. + +ifndef SMING_HOME +$(error SMING_HOME is not set. Please configure it in Makefile-user.mk) +endif +ifndef ESP_HOME +$(error ESP_HOME is not set. Please configure it in Makefile-user.mk) +endif + +# Include main Sming Makefile +ifeq ($(RBOOT_ENABLED), 1) +include $(SMING_HOME)/Makefile-rboot.mk +else +include $(SMING_HOME)/Makefile-project.mk +endif diff --git a/samples/LED_YeelightBulb/Makefile-user.mk b/samples/LED_YeelightBulb/Makefile-user.mk new file mode 100644 index 0000000000..bd088ca354 --- /dev/null +++ b/samples/LED_YeelightBulb/Makefile-user.mk @@ -0,0 +1,39 @@ +## Local build configuration +## Parameters configured here will override default and ENV values. +## Uncomment and change examples: + +## Add your source directories here separated by space +# MODULES = app +# EXTRA_INCDIR = include + +## ESP_HOME sets the path where ESP tools and SDK are located. +## Windows: +# ESP_HOME = c:/Espressif + +## MacOS / Linux: +# ESP_HOME = /opt/esp-open-sdk + +## SMING_HOME sets the path where Sming framework is located. +## Windows: +# SMING_HOME = c:/tools/sming/Sming + +## MacOS / Linux +# SMING_HOME = /opt/sming/Sming + +## COM port parameter is reqruied to flash firmware correctly. +## Windows: +# COM_PORT = COM3 + +## MacOS / Linux: +# COM_PORT = /dev/tty.usbserial + +## Com port speed +# COM_SPEED = 115200 + +## Configure flash parameters (for ESP12-E and other new boards): +# SPI_MODE = dio + +## SPIFFS options +DISABLE_SPIFFS = 1 +# SPIFF_FILES = files + diff --git a/samples/LED_YeelightBulb/app/application.cpp b/samples/LED_YeelightBulb/app/application.cpp new file mode 100644 index 0000000000..c3d27fb491 --- /dev/null +++ b/samples/LED_YeelightBulb/app/application.cpp @@ -0,0 +1,48 @@ +#include +#include + +// If you want, you can define WiFi settings globally in Eclipse Environment Variables +#ifndef WIFI_SSID + #define WIFI_SSID "PleaseEnterSSID" // Put you SSID and Password here + #define WIFI_PWD "PleaseEnterPass" +#endif + + +// Enter your bulb IP here: +YeelightBulb bulb(IPAddress("192.168.1.100")); + +Timer procTimer; +bool state = false; + +void blink() +{ + state = !state; + + if (state) + { + int h = random(0, 360); + bulb.setHSV(h, 40); // Set color: [HS]V + } + bulb.setState(state); +} + +// Will be called when WiFi station was connected to AP +void connectOk() +{ + debugf("I'm CONNECTED"); + + // Connection to Yeelight Bulb will be established on any first action: + bulb.updateState(); // Read actual bulb state + procTimer.initializeMs(5000, blink).start(); +} + +void init() +{ + Serial.begin(SERIAL_BAUD_RATE); // 115200 by default + + // Station - WiFi client + WifiStation.enable(true); + WifiStation.config(WIFI_SSID, WIFI_PWD); // Put you SSID and Password here + + WifiStation.waitConnection(connectOk); +} diff --git a/samples/LED_YeelightBulb/include/user_config.h b/samples/LED_YeelightBulb/include/user_config.h new file mode 100644 index 0000000000..1c6ac36703 --- /dev/null +++ b/samples/LED_YeelightBulb/include/user_config.h @@ -0,0 +1,45 @@ +#ifndef __USER_CONFIG_H__ +#define __USER_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + // UART config + #define SERIAL_BAUD_RATE 115200 + + // ESP SDK config + #define LWIP_OPEN_SRC + #define USE_US_TIMER + + // Default types + #define __CORRECT_ISO_CPP_STDLIB_H_PROTO + #include + #include + + // Override c_types.h include and remove buggy espconn + #define _C_TYPES_H_ + #define _NO_ESPCON_ + + // Updated, compatible version of c_types.h + // Just removed types declared in + #include + + // System API declarations + #include + + // C++ Support + #include + // Extended string conversion for compatibility + #include + // Network base API + #include + + // Beta boards + #define BOARD_ESP01 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/samples/Light_BH1750/include/user_config.h b/samples/Light_BH1750/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Light_BH1750/include/user_config.h +++ b/samples/Light_BH1750/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/LiquidCrystal_44780/include/user_config.h b/samples/LiquidCrystal_44780/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/LiquidCrystal_44780/include/user_config.h +++ b/samples/LiquidCrystal_44780/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/MeteoControl/include/user_config.h b/samples/MeteoControl/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/MeteoControl/include/user_config.h +++ b/samples/MeteoControl/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/MeteoControl_mqtt/include/user_config.h b/samples/MeteoControl_mqtt/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/MeteoControl_mqtt/include/user_config.h +++ b/samples/MeteoControl_mqtt/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/MqttClient_Hello/include/user_config.h b/samples/MqttClient_Hello/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/MqttClient_Hello/include/user_config.h +++ b/samples/MqttClient_Hello/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/PortExpander_MCP23017/include/user_config.h b/samples/PortExpander_MCP23017/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/PortExpander_MCP23017/include/user_config.h +++ b/samples/PortExpander_MCP23017/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/PortExpander_MCP23S17/include/user_config.h b/samples/PortExpander_MCP23S17/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/PortExpander_MCP23S17/include/user_config.h +++ b/samples/PortExpander_MCP23S17/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Pressure_BMP180/include/user_config.h b/samples/Pressure_BMP180/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Pressure_BMP180/include/user_config.h +++ b/samples/Pressure_BMP180/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Radio_RCSwitch/include/user_config.h b/samples/Radio_RCSwitch/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Radio_RCSwitch/include/user_config.h +++ b/samples/Radio_RCSwitch/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Radio_nRF24L01/include/user_config.h b/samples/Radio_nRF24L01/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Radio_nRF24L01/include/user_config.h +++ b/samples/Radio_nRF24L01/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Radio_si4432/include/user_config.h b/samples/Radio_si4432/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Radio_si4432/include/user_config.h +++ b/samples/Radio_si4432/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/SDCard/include/user_config.h b/samples/SDCard/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/SDCard/include/user_config.h +++ b/samples/SDCard/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/ScreenLCD_5110/include/user_config.h b/samples/ScreenLCD_5110/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/ScreenLCD_5110/include/user_config.h +++ b/samples/ScreenLCD_5110/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/ScreenOLED_SSD1306/include/user_config.h b/samples/ScreenOLED_SSD1306/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/ScreenOLED_SSD1306/include/user_config.h +++ b/samples/ScreenOLED_SSD1306/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/ScreenTFT_ILI9163C/include/user_config.h b/samples/ScreenTFT_ILI9163C/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/ScreenTFT_ILI9163C/include/user_config.h +++ b/samples/ScreenTFT_ILI9163C/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/ScreenTFT_ILI9340-ILI9341/include/user_config.h b/samples/ScreenTFT_ILI9340-ILI9341/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/ScreenTFT_ILI9340-ILI9341/include/user_config.h +++ b/samples/ScreenTFT_ILI9340-ILI9341/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/ScreenTFT_ST7735/include/user_config.h b/samples/ScreenTFT_ST7735/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/ScreenTFT_ST7735/include/user_config.h +++ b/samples/ScreenTFT_ST7735/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/SystemClock_NTP/include/user_config.h b/samples/SystemClock_NTP/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/SystemClock_NTP/include/user_config.h +++ b/samples/SystemClock_NTP/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/TcpClient_NarodMon/app/application.cpp b/samples/TcpClient_NarodMon/app/application.cpp index adb0ce5510..0348e48f7f 100644 --- a/samples/TcpClient_NarodMon/app/application.cpp +++ b/samples/TcpClient_NarodMon/app/application.cpp @@ -51,6 +51,7 @@ bool nmOnReceive(TcpClient& client, char *buf, int size) // debug msg debugf("nmOnReceive"); debugf("%s", buf); + return true; } // Создаем объект narodMon класса TcpClient diff --git a/samples/TcpClient_NarodMon/include/user_config.h b/samples/TcpClient_NarodMon/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/TcpClient_NarodMon/include/user_config.h +++ b/samples/TcpClient_NarodMon/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Telnet_TCPServer_TCPClient/include/user_config.h b/samples/Telnet_TCPServer_TCPClient/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Telnet_TCPServer_TCPClient/include/user_config.h +++ b/samples/Telnet_TCPServer_TCPClient/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Temperature_DS1820/include/user_config.h b/samples/Temperature_DS1820/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Temperature_DS1820/include/user_config.h +++ b/samples/Temperature_DS1820/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/UdpServer_Echo/include/user_config.h b/samples/UdpServer_Echo/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/UdpServer_Echo/include/user_config.h +++ b/samples/UdpServer_Echo/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/UdpServer_mDNS/Makefile-user.mk b/samples/UdpServer_mDNS/Makefile-user.mk index bd088ca354..faa1d5cdf4 100644 --- a/samples/UdpServer_mDNS/Makefile-user.mk +++ b/samples/UdpServer_mDNS/Makefile-user.mk @@ -37,3 +37,5 @@ DISABLE_SPIFFS = 1 # SPIFF_FILES = files +# If you use custom LWIP compilation make sure to enable espconn because this sample uses espconn_mdns_* functions +ENABLE_ESPCONN = 1 diff --git a/samples/UdpServer_mDNS/include/user_config.h b/samples/UdpServer_mDNS/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/UdpServer_mDNS/include/user_config.h +++ b/samples/UdpServer_mDNS/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Ultrasonic_HCSR04/include/user_config.h b/samples/Ultrasonic_HCSR04/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Ultrasonic_HCSR04/include/user_config.h +++ b/samples/Ultrasonic_HCSR04/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC diff --git a/samples/Websocket_Client/include/user_config.h b/samples/Websocket_Client/include/user_config.h index 1c6ac36703..09825be2b5 100644 --- a/samples/Websocket_Client/include/user_config.h +++ b/samples/Websocket_Client/include/user_config.h @@ -6,7 +6,7 @@ extern "C" { #endif // UART config - #define SERIAL_BAUD_RATE 115200 + #define SERIAL_BAUD_RATE COM_SPEED_SERIAL // ESP SDK config #define LWIP_OPEN_SRC