Skip to content

Commit 1399cf6

Browse files
authored
Migrate to PlatformIO #18
2 parents bcb8f1c + 35b906b commit 1399cf6

File tree

15 files changed

+943
-682
lines changed

15 files changed

+943
-682
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: awawa-dev

.github/workflows/push-master.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: HyperSerialEsp8266 CI Build
2+
3+
on: [push]
4+
5+
jobs:
6+
7+
######################
8+
#### PlatformIO ######
9+
######################
10+
11+
PlatformIO:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Cache pip
16+
uses: actions/cache@v3
17+
with:
18+
path: ~/.cache/pip
19+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
20+
restore-keys: |
21+
${{ runner.os }}-pip-
22+
- name: Cache PlatformIO
23+
uses: actions/cache@v3
24+
with:
25+
path: ~/.platformio
26+
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
27+
- name: Set up Python
28+
uses: actions/setup-python@v4
29+
with:
30+
python-version: 3.x
31+
- name: Install PlatformIO
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install --upgrade platformio
35+
- name: Run PlatformIO
36+
run: pio run
37+
- uses: actions/upload-artifact@v3
38+
name: Upload artifacts (commit)
39+
if: (startsWith(github.event.ref, 'refs/tags') != true)
40+
with:
41+
path: |
42+
.pio/build/*.bin
43+
44+
- uses: actions/upload-artifact@v3
45+
name: Upload artifacts (release)
46+
if: startsWith(github.ref, 'refs/tags/')
47+
with:
48+
name: firmware-release
49+
path: |
50+
.pio/build/*.bin
51+
52+
################################
53+
###### Publish Releases ########
54+
################################
55+
56+
publish:
57+
name: Publish Releases
58+
if: startsWith(github.event.ref, 'refs/tags')
59+
needs: [PlatformIO]
60+
runs-on: ubuntu-latest
61+
steps:
62+
# generate environment variables
63+
- name: Generate environment variables from version and tag
64+
run: |
65+
echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
66+
echo "preRelease=false" >> $GITHUB_ENV
67+
68+
# If version contains alpha or beta, mark draft release as pre-release
69+
- name: Mark release as pre-release
70+
if: contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta')
71+
run: echo "preRelease=true" >> $GITHUB_ENV
72+
73+
- uses: actions/download-artifact@v3
74+
with:
75+
name: firmware-release
76+
77+
# create draft release and upload artifacts
78+
- name: Create draft release
79+
uses: softprops/action-gh-release@v1
80+
with:
81+
name: HyperSerialEsp8266 ${{ env.VERSION }}
82+
tag_name: ${{ env.TAG }}
83+
files: |
84+
*.bin
85+
draft: true
86+
prerelease: ${{ env.preRelease }}
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

.vscode/extensions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
],
7+
"unwantedRecommendations": [
8+
"ms-vscode.cpptools-extension-pack"
9+
]
10+
}

README.md

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ Statistics are sent to serial port monitor when there is no data incoming. You c
4242

4343
# Flashing
4444

45-
For **RGBW LED strip** like RGBW SK6812 NEUTRAL white choose: *HyperSerialEsp8266.ino.d1_mini_SK6812_NEUTRAL_WHITE_FIRSTLED_xxxxxx.bin*
45+
Recommend to use [esphome-flasher](https://github.com/esphome/esphome-flasher/releases)
46+
47+
For **RGBW LED strip** like RGBW SK6812 NEUTRAL white choose: *firmware_SK6812_RGBW_NEUTRAL.bin*
4648

47-
For **RGBW LED strip** like RGBW SK6812 COLD white choose: *HyperSerialEsp8266.ino.d1_mini_SK6812_COLD_WHITE_FIRSTLED_xxxxxx.bin*
49+
For **RGBW LED strip** like RGBW SK6812 COLD white choose: *firmware_SK6812_RGBW_COLD.bin*
4850

49-
For **RGB LED strip** like WS8212b or RGB SK6812 variant choose: *HyperSerialEsp8266.ino.d1_mini_WS821x_FIRSTLED_xxxxxx.bin*
51+
For **RGB LED strip** like WS8212b or RGB SK6812 variant choose: *firmware_WS281x_RGB.bin*
5052

51-
For **SPI driven RGB LED strip** APA102: *HyperSerialEsp8266.ino.d1_mini_APA102_FIRSTLED_xxxxxx.bin*, WS8201: *HyperSerialEsp8266.ino.d1_mini_WS8201_rbg_FIRSTLED_xxxxxx.bin*
53+
For **SPI driven RGB LED strip** APA102: *firmware_SPI_APA102_SK9822_HD107.bin*, WS8201: *firmware_SPI_WS2801.bin*
5254

53-
If the first LED in the strip should be enabled or set to black is your choice.
55+
If you want to disable your first LED because it's used as a sacrificial level shifter, please use [HyperHDR v19](https://github.com/awawa-dev/HyperHDR/pull/379)
56+
5457
For the RGBW firmware the white channel is automatically calculated and R,G,B channels are corrected.
5558

5659
Using esphome-flasher:
@@ -73,28 +76,10 @@ RGBW (250 leds, 100Hz)
7376

7477
# Compiling
7578

76-
Compile the sketch using Arduino IDE. You need:
77-
- https://github.com/esp8266/Arduino/ (boards for ESP8266, release uses: d1 mini)
78-
- Makuna/NeoPixelBus (install from Arduino IDE: manage libraries)
79-
80-
**Options (first lines of the sketch):**
81-
82-
For RGB strip like WS8212b delete it or comment it with '//', leave it for RGBW SK6812:
83-
*#define THIS_IS_RGBW*
84-
85-
For RGBW cold white LED strip version if above declaration is defined, delete it or comment it with '//' for RGBW neutral:
86-
*#define COLD_WHITE*
79+
Currently we use PlatformIO to compile the project. Install [Visual Studio Code](https://code.visualstudio.com/) and add [PlatformIO plugin](https://platformio.org/).
80+
This environment will take care of everything and compile the firmware for you.
8781

88-
SPI: for APA102/SK9822/HD107 delete it or comment it with '//', leave it for WS2801:
89-
*#define is_WS2801*
90-
91-
Skip first led in the strip, that is used as level shifter:
92-
*bool skipFirstLed = true;*
93-
94-
Serial port speed:
95-
*int serialSpeed = 2000000;*
96-
97-
Don't change LED's count as it is dynamic.
82+
But there is also an alternative and an easier way. Just fork the project and enable its Github Action. Use the online editor to make changes to the ```platformio.ini``` file, for example, and save it. Github Action will compile new firmware automatically in the Artifacts archive. It has never been so easy!
9883

9984
# Pinout
10085

extra_script.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Import("env")
2+
from pathlib import Path
3+
import shutil
4+
5+
6+
def post_program_action(source, target, env):
7+
program_path = target[0].get_abspath()
8+
path = Path(program_path)
9+
shutil.copy(program_path, path.parent.parent.absolute())
10+
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", post_program_action)
11+
12+
env.Replace(PROGNAME="firmware_%s" % env.GetProjectOption("custom_prog_version"))
13+

include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

include/calibration.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* calibration.h
2+
*
3+
* MIT License
4+
*
5+
* Copyright (c) 2022 awawa-dev
6+
*
7+
* https://github.com/awawa-dev/HyperSerialEsp8266
8+
*
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in all
17+
* copies or substantial portions of the Software.
18+
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
* SOFTWARE.
26+
*/
27+
28+
#ifndef CALIBRATION_H
29+
#define CALIBRATION_H
30+
31+
#include <stdint.h>
32+
#include <algorithm>
33+
34+
#define ROUND_DIVIDE(numer, denom) (((numer) + (denom) / 2) / (denom))
35+
36+
struct {
37+
uint8_t white[256];
38+
uint8_t red[256];
39+
uint8_t green[256];
40+
uint8_t blue[256];
41+
} channelCorrection;
42+
43+
struct {
44+
uint8_t gain = 0xFF;
45+
#ifdef COLD_WHITE
46+
uint8_t red = 0xA0; // adjust red -> white in 0-0xFF range
47+
uint8_t green = 0xA0; // adjust green -> white in 0-0xFF range
48+
uint8_t blue = 0xA0; // adjust blue -> white in 0-0xFF range
49+
#else
50+
uint8_t red = 0xB0; // adjust red -> white in 0-0xFF range
51+
uint8_t green = 0xB0; // adjust green -> white in 0-0xFF range
52+
uint8_t blue = 0x70; // adjust blue -> white in 0-0xFF range
53+
#endif
54+
55+
void setParams(uint8_t _gain, uint8_t _red, uint8_t _green, uint8_t _blue)
56+
{
57+
gain = _gain;
58+
red = _red;
59+
green = _green;
60+
blue = _blue;
61+
}
62+
63+
void prepareCalibration()
64+
{
65+
// prepare LUT calibration table, cold white is much better than "neutral" white
66+
for (uint32_t i = 0; i < 256; i++)
67+
{
68+
// color calibration
69+
uint32_t _gain = uint32_t(gain) * i; // adjust gain
70+
uint32_t _red = red * i; // adjust red
71+
uint32_t _green = green * i; // adjust green
72+
uint32_t _blue = blue * i; // adjust blue
73+
74+
channelCorrection.white[i] = (uint8_t)std::min(ROUND_DIVIDE(_gain, 0xFF), (uint32_t)0xFF);
75+
channelCorrection.red[i] = (uint8_t)std::min(ROUND_DIVIDE(_red, 0xFF), (uint32_t)0xFF);
76+
channelCorrection.green[i] = (uint8_t)std::min(ROUND_DIVIDE(_green,0xFF), (uint32_t)0xFF);
77+
channelCorrection.blue[i] = (uint8_t)std::min(ROUND_DIVIDE(_blue, 0xFF), (uint32_t)0xFF);
78+
}
79+
}
80+
} calibrationConfig;
81+
#endif
82+

lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

0 commit comments

Comments
 (0)