Skip to content

Commit

Permalink
Merge branch 'upstream_develop' into Astro
Browse files Browse the repository at this point in the history
* upstream_develop: (43 commits)
  Added crash handler. Fixed/improved debugging information. (SmingHub#826)
  Enabled the SPIFFS. Fixed the HttpServer_Bootstrap example. (SmingHub#827)
  Added onDelivery callback for messages with QoS 1 or 2. (SmingHub#617)
  Backported changes from SmingRTOS. (SmingHub#825)
  Add FAST GPIO for CS pin and change pin numbering to start from 0 in MCP23S17 Lib (SmingHub#823)
  Fix issue SmingHub#709. Keep SPI_WR_BYTE_ORDER, SPI_RD_BYTE_ORDER, and SPI_CK_OUT_EDGE when upddating the SPI_USER reg (SmingHub#710)
  Fix stability and performance of websocket server (SmingHub#824)
  Fixed the SSL support for MQTT.
  Fixed Echo_Ssl sample.
  Feature/websocket client ssl (SmingHub#819)
  The latest spiffs is loaded as third-party module. (SmingHub#816)
  More efficient way to analyze errors. (SmingHub#821)
  Websocket client implementation for Sming (SmingHub#809)
  Simplified the compilation of custom PWM and Basic_HwPWM sample. (SmingHub#818)
  Removed test that is randomly braking on MacOS X travis machines.
  Adds / updates API documentation for: DateTime, Clock, Debug, NtpCient, RTC, SystemClock, some non-Sming (ESP) functions. (SmingHub#812)
  Fix/remove gdbstub (SmingHub#811)
  Fixes/freebsd (SmingHub#810)
  Proper timeout handling for Websockets (SmingHub#806)
  Added information about the SSL support. Fixed small typos.
  ...

# Conflicts:
#	Sming/Makefile-project.mk
#	Sming/SmingCore/Network/HttpServer.cpp
  • Loading branch information
johndoe8967 committed Dec 10, 2016
2 parents a28b7d6 + 138bb3a commit 24d1a33
Show file tree
Hide file tree
Showing 193 changed files with 8,716 additions and 10,446 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ language.settings.xml
.settings
nbproject
.*.swp
Sming.wiki
22 changes: 22 additions & 0 deletions .gitmodules
@@ -0,0 +1,22 @@
[submodule "Sming/rboot"]
path = Sming/third-party/rboot
url = https://github.com/raburton/rboot.git
ignore = dirty
[submodule "Sming.wiki"]
path = docs/wiki
url = https://github.com/SmingHub/Sming.wiki.git
[submodule "Sming/third-party/esp-gdbstub"]
path = Sming/third-party/esp-gdbstub
url = https://github.com/espressif/esp-gdbstub.git
ignore = dirty
[submodule "Sming/pwm"]
path = Sming/third-party/pwm
url = https://github.com/StefanBruens/ESP8266_new_pwm.git
ignore = dirty
[submodule "third-party/axtls-8266"]
path = Sming/third-party/axtls-8266
url = https://github.com/igrr/axtls-8266.git
ignore = dirty
[submodule "Sming/third-party/spiffs"]
path = Sming/third-party/spiffs
url = https://github.com/pellepl/spiffs.git
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -9,6 +9,8 @@ env:
matrix:
- SDK_VERSION=1.4.0
- SDK_VERSION=1.5.0
git:
submodules: false
addons:
apt:
sources:
Expand All @@ -33,3 +35,7 @@ script:
- 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 ENABLE_GDB=1
- make Basic_Debug
68 changes: 68 additions & 0 deletions AddingExternalSource.md
@@ -0,0 +1,68 @@
This document describes the recommended way to add source code from other `git` repositories.

Introduction
============
In Sming we have source code from other repositories [rboot](https://github.com/raburton/rboot), [esp-gdbstub](https://github.com/espressif/esp-gdbstub), [spiffs](https://github.com/pellepl/spiffs), etc..

Having local copies of those modules brings some disadvantages with it

1. We cannot easily update the local copy from the original source code.
2. We cannot easily send improvements to those projects once we make local changes in our local copy.

Therefore we started using `git submodules`. For the sake of brevity `git submodules` will be called `submodules` in this document. Submodules allow us to fetch the source code from the respective repositories and eliminate the disadvantages that local copies have. In addition, if we need local modifications than we can keep a <submodule>.patch file and apply it after fetching the submodule code. This decreased our efforts and allowed us to use the latest versions of those third-party projects.

Adding External Sources
=======================

# Fetching Source Code

## Without git repository
If the source code does not have a publicly accessible git repository then the source code needs to be copied locally. It should reside in a folder inside the `Sming/third-party/` folder.
All local changes need to be applied directly to the local copy.

## With git repository
In the cases where a library or dependent component has a public git repository we should add it in the following way.
First we need to add the external repository as submodule. For example if we want to use the [pwm](https://github.com/StefanBruens/ESP8266_new_pwm we) submodule we can do the following
```
cd <Sming-root-folder>/
git submodule add https://github.com/StefanBruens/ESP8266_new_pwm.git Sming/third-party/pwm
```

The command above instructs `git` to register the repository `https://github.com/StefanBruens/ESP8266_new_pwm.git` as a submodule that will be present in our local source code in the folder `Sming/third-party/pwm`. All submodules should be pointing to a directory that is sub-directory of the `Sming/third-party` folder. This way every developer can use the existing mechanism to fetch and link these modules to the rest of the project.

# Applying Patches
If the module needs local modifications to work with our project then we should add all needed changes in a patch file. For example for the `pwm` module all changes should be saved in `Sming/third-party/.patches/pwm.patch`. If the module that we patch is called `esp-gdbstub` then the patch file should be `Sming/third-party/.patches/esp-gdbstub.patch`. Please, use this naming for consistency.

# Link external sources in Sming
Once we are ready with the submodules we need to instruct Sming that a new source code is present and how to use it. Most of the changes should be done in the <Sming-root-folder>/Sming/Makefile.
First we have to modify the `THIRD_PARTY_DATA` variable in the Makefile. For example if the variable has the following data

`THIRD_PARTY_DATA = third-party/rboot/Makefile`

we should add an existing file from the new submodule. In the case of the `pwm` submodule an existing file in it is `pwm.c`. After modification our Makefile should have a line like that one

`THIRD_PARTY_DATA = third-party/rboot/Makefile third-party/pwm/pwm.c`

# Add external source to include path
If the new module has own header files that should be part of the project you can add them to the `EXTRA_INCDIR`. Here is an example with the include paths that `rboot` brings

`EXTRA_INCDIR += third-party/rboot third-party/rboot/appcode`

# Add external source to source code path
If the new module brings also source code that needs to be compiled than you can add it by modifying the `MODULES` variable. Here is an example with `esp-gdbstub`:

`MODULES += third-party/esp-gdbstub`

Take a look at the Makefile to see examples of including the submodules only when a switch is enabled (search for ENABLE_GDB).

Generating Patch Files
======================
It can happen that an external source code that is coming from another git repository and is present as a submodule needs some changes before it can start working for Sming. Those changes
must be stored in a separate patch file.
The recommended way to generate a patch file is to get the source code of the submodule, make changes to the file(s) in the submodule until it is ready for use and finally generate a patch file using the following commands:

```
cd <Sming-root-folder>/third-party/<module-name>
git diff --no-ext-diff > <Sming-root-folder>/third-party/.patches/<module-name>.patch
```

29 changes: 24 additions & 5 deletions Readme.md
Expand Up @@ -11,30 +11,39 @@ Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native develo
## Summary
* Fast & user friendly development
* Work with GPIO in Arduino style
* High effective in perfomance and memory usage (this is native firmware!)
* High effective in performance and memory usage (this is native firmware!)
* Compatible with standard Arduino libraries - use any popular hardware in few lines of code
* rBoot OTA firmware updating
* Built-in file system: [spiffs](https://github.com/pellepl/spiffs)
* Built-in powerfull network and wireless modules
* Built-in powerful network and wireless modules
* Built-in JSON library: [ArduinoJson](https://github.com/bblanchon/ArduinoJson)
* HTTP, AJAX, WebSockets support
* MQTT protocol based on [libemqtt] (https://github.com/menudoproblema/libemqtt)
* Networking based on LWIP stack
* Simple and powerfull hardware API wrappers
* Based on Espressif NONOS SDK 1.4.0 & 1.5.0
* Simple and powerful hardware API wrappers
* SSL support based on [axTLS 2.0+] (https://github.com/igrr/axtls-8266) with [Lwirax] (https://github.com/attachix/lwirax/)
* Based on Espressif NONOS SDK. Tested with versions 1.4 and 1.5.

## Latest Release
- [Sming V2.1.0](https://github.com/SmingHub/Sming/releases/tag/2.1.0)
- [Sming V2.1.5](https://github.com/SmingHub/Sming/releases/tag/2.1.5)

## Getting started
- [Windows](https://github.com/SmingHub/Sming/wiki/Windows-Quickstart)
- [Linux](https://github.com/SmingHub/Sming/wiki/Linux-Quickstart)
- [MacOS](https://github.com/SmingHub/Sming/wiki/MacOS-Quickstart)
- [Docker](https://github.com/SmingHub/Sming/wiki/Docker-Quickstart)


## Additional needed software
- Spiffy : Source included in Sming repository
- [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.


You can find more information about compilation and flashing process by reading esp8266.com forum discussion thread.

## Examples
Expand Down Expand Up @@ -149,3 +158,13 @@ void onFile(HttpRequest &request, HttpResponse &response)
response.sendFile(file);
}
```
### Documentation
A complete documentation can be created by running the command below. This requires `doxygen` to be installed on your system.
```
cd $SMING_HOME
make docs
```
The newly generated documentation will be located under Sming/docs/api
168 changes: 168 additions & 0 deletions Sming/Libraries/APA102/apa102.cpp
@@ -0,0 +1,168 @@
/****
* 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.
* APA102 library by HappyCodingRobot@github.com
****/
#include <SmingCore.h>
// APA102 LED class
#include <SPI.h>
#include <SPISoft.h>
#include "apa102.h"


#define LED_PREAMBLE (uint8_t)0xE0 // LED frame preamble
#define LED_PREAMBLELONG (uint32_t)0xE0000000 // LED frame preamble
#define brOfs 0
#define bOfs 1
#define gOfs 2
#define rOfs 3



/* APA102 class for hardware & software SPI */

APA102::APA102(uint16_t n) : numLEDs(n), brightness(0), LEDbuffer(NULL), pSPI(SPI) {
if (LEDbuffer = (uint8_t *) malloc(numLEDs * 4)) {
clear();
}
}

APA102::APA102(uint16_t n, SPIBase & spiRef) : numLEDs(n), brightness(0), LEDbuffer(NULL), pSPI(spiRef) {
if (LEDbuffer = (uint8_t *) malloc(numLEDs * 4)) {
clear();
}
}

APA102::~APA102() {
if (LEDbuffer) free(LEDbuffer);
}


void APA102::begin(void) {
pSPI.begin();
}

void APA102::begin(SPISettings & mySettings) {
pSPI.begin();
SPI_APA_Settings = mySettings;
}

void APA102::end() {
pSPI.end();
}



void APA102::show(void) {
uint32_t *buf = (uint32_t*) LEDbuffer;
uint32_t elem;
pSPI.beginTransaction(SPI_APA_Settings);
sendStart();
for (uint16_t i = 0; i < numLEDs; i++) {
elem = buf[i];
pSPI.transfer((uint8_t*)&elem, 4);
}
sendStop();
pSPI.endTransaction();
}

void APA102::show(int16_t SPos) {
uint32_t *buf = (uint32_t*) LEDbuffer;
uint32_t elem;
pSPI.beginTransaction(SPI_APA_Settings);
int sp = numLEDs - (SPos % numLEDs);
sendStart();
for (int i = 0; i < numLEDs; i++) {
elem = buf[(i + sp) % numLEDs];
pSPI.transfer((uint8_t*)&elem, 4);
}
sendStop();
pSPI.endTransaction();
}

void APA102::clear(void) {
for (uint16_t i = 0; i < numLEDs; i++) {
LEDbuffer[i * 4] = LED_PREAMBLE;
LEDbuffer[i * 4 + bOfs] = 0;
LEDbuffer[i * 4 + gOfs] = 0;
LEDbuffer[i * 4 + rOfs] = 0;
}
}

void APA102::setPixel(uint16_t n, uint8_t r, uint8_t g, uint8_t b) {
if (n < numLEDs) {
LEDbuffer[n * 4] = LED_PREAMBLE | brightness;
LEDbuffer[n * 4 + bOfs] = b;
LEDbuffer[n * 4 + gOfs] = g;
LEDbuffer[n * 4 + rOfs] = r;
}
}

void APA102::setPixel(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t br) {
if (n < numLEDs) {
LEDbuffer[n * 4] = LED_PREAMBLE | (br < 32 ? br : 31);
LEDbuffer[n * 4 + bOfs] = b;
LEDbuffer[n * 4 + gOfs] = g;
LEDbuffer[n * 4 + rOfs] = r;
}
}

void APA102::setPixel(uint16_t n, col_t* p) {
if (n < numLEDs) {
LEDbuffer[n * 4] = LED_PREAMBLE | brightness;
LEDbuffer[n * 4 + bOfs] = p->b;
LEDbuffer[n * 4 + gOfs] = p->g;
LEDbuffer[n * 4 + rOfs] = p->r;
}
}

void APA102::setAllPixel(uint8_t r, uint8_t g, uint8_t b) {
for (uint16_t i = 0; i < numLEDs; i++) {
LEDbuffer[i * 4] = LED_PREAMBLE | brightness;
LEDbuffer[i * 4 + bOfs] = b;
LEDbuffer[i * 4 + gOfs] = g;
LEDbuffer[i * 4 + rOfs] = r;
}
}

void APA102::setAllPixel(col_t* p) {
for (uint16_t i = 0; i < numLEDs; i++) {
LEDbuffer[i * 4] = LED_PREAMBLE | brightness;
LEDbuffer[i * 4 + bOfs] = p->b;
LEDbuffer[i * 4 + gOfs] = p->g;
LEDbuffer[i * 4 + rOfs] = p->r;
}
}

void APA102::setBrightness(uint8_t br) {
brightness = (br < 32 ? br : 31);
}

uint8_t APA102::getBrightness(void) {
return brightness;
}

/* direct write functions */

inline void APA102::sendStart(void) {
uint8_t startFrame[] = {0x00, 0x00, 0x00, 0x00};
pSPI.transfer(startFrame, sizeof (startFrame));
}

inline void APA102::sendStop(void) {
uint8_t stopFrame[] = {0xff, 0xff, 0xff, 0xff};
pSPI.transfer(stopFrame, sizeof (stopFrame));
}

void APA102::directWrite(uint8_t r, uint8_t g, uint8_t b, uint8_t br) {
uint8_t pix[4];
pSPI.beginTransaction(SPI_APA_Settings);
pix[0] = 0xE0 | (br < 32 ? br : 31);
pix[bOfs] = b;
pix[gOfs] = g;
pix[rOfs] = r;
pSPI.transfer(pix, sizeof (pix));
}

0 comments on commit 24d1a33

Please sign in to comment.