forked from SmingHub/Sming
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upstream_develop' into Astro
* 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
Showing
193 changed files
with
8,716 additions
and
10,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ language.settings.xml | |
.settings | ||
nbproject | ||
.*.swp | ||
Sming.wiki |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
Oops, something went wrong.