forked from SmingHub/Sming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '3b432d58d3445004ec0a8d02001c288a31abcfdf' into upstream…
…_develop * commit '3b432d58d3445004ec0a8d02001c288a31abcfdf': (33 commits) "Reload" the makefile when a newly fetched source code from submodule needs to be compiled inside Sming. Ignore modified content in submodules. Fix small issues in Makefile. Feature/custom pwm (SmingHub#808) Initial version of the restructuring. (SmingHub#793) Getting ready for v 2.1.5. (SmingHub#804) Feature/bmp for screentft (SmingHub#805) Specify commit to checkout for esp-open-sdk (SmingHub#801) Documentation reorganization. (SmingHub#802) Removed redundant `extern`s. Fixed the esp-gdbstub header file. (SmingHub#798) Feature/docker (SmingHub#796) Added documentation generation. Small fixes to the HardwarePWM documentation. Adds Command Delegate doc Add more API docs. Remove timestamp from API docs to avoid committing every file every time. Small fixes to the PR. mprintf: reduce include overhead\nproper declare symbols with C linkage\nfix crash when size is smaller than arg_size for %d %u\n fix padding for %d and %f\nfix buffer overflow for %d %f\n add vsnprintf equivalent \n add putch equivalent fix ArduinoJson overloading String define Added SI7021 support. Initial check-in for Sming APA102 LED library & basic example APA102 class enhanced to work with hardware SPI and software SPI, Example enhanced Changed to work with the new SPI implementation by harry-boe Mention tested versions. SDK version 2.0 is not tested yet. Related to SmingHub#786. Fixed issue with final bytes < 4 not being written on the flash memory during rboot OTA update. ...
- Loading branch information
Showing
116 changed files
with
2,987 additions
and
2,796 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,15 @@ | ||
[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 |
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,56 @@ | ||
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). |
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 [email protected] | ||
****/ | ||
#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)); | ||
} | ||
|
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,72 @@ | ||
/**** | ||
* 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 [email protected] | ||
****/ | ||
|
||
#ifndef _APA102_H_ | ||
#define _APA102_H_ | ||
|
||
#include <SPIBase.h> | ||
#include <SPISettings.h> | ||
|
||
typedef struct { | ||
//uint8_t br; | ||
uint8_t r; | ||
uint8_t g; | ||
uint8_t b; | ||
} col_t; | ||
|
||
|
||
class APA102 { | ||
public: | ||
APA102(uint16_t n); | ||
APA102(uint16_t n, SPIBase & spiRef); | ||
~APA102(void); | ||
|
||
void begin(void); | ||
void begin(SPISettings & mySettings); | ||
void end(void); | ||
|
||
/* send data buffer to LEDs, including start & stop sequences */ | ||
void show(void); | ||
void show(int16_t SPos); | ||
|
||
/* clear data buffer */ | ||
void clear(void); | ||
|
||
/* set pixel color */ | ||
void setPixel(uint16_t n, uint8_t r, uint8_t g, uint8_t b); | ||
void setPixel(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t br); | ||
void setPixel(uint16_t n, col_t* p); | ||
void setAllPixel(uint8_t r, uint8_t g, uint8_t b); | ||
//void LEDsetAllPixel(uint8_t r, uint8_t g, uint8_t b, uint8_t br); | ||
void setAllPixel(col_t*); | ||
|
||
/* set global LED brightness level */ | ||
void setBrightness(uint8_t); | ||
/* get global LED brightness level */ | ||
uint8_t getBrightness(void); | ||
|
||
|
||
/* send start sequence */ | ||
void sendStart(void); | ||
/* send stop sequence */ | ||
void sendStop(void); | ||
/* direct write single LED data */ | ||
void directWrite(uint8_t r, uint8_t g, uint8_t b, uint8_t br); | ||
|
||
protected: | ||
uint16_t numLEDs; | ||
uint8_t *LEDbuffer; | ||
uint8_t brightness; // global brightness 0..31 -> 0..100% | ||
|
||
SPISettings SPI_APA_Settings = SPISettings(4000000, MSBFIRST, SPI_MODE3); | ||
SPIBase & pSPI; | ||
|
||
private: | ||
}; | ||
|
||
#endif /* _APA102_H_ */ |
Oops, something went wrong.