Skip to content

Commit

Permalink
Migrate to PlatformIO #18
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev authored Nov 8, 2022
2 parents bcb8f1c + 35b906b commit 1399cf6
Show file tree
Hide file tree
Showing 15 changed files with 943 additions and 682 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: awawa-dev
88 changes: 88 additions & 0 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: HyperSerialEsp8266 CI Build

on: [push]

jobs:

######################
#### PlatformIO ######
######################

PlatformIO:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: pio run
- uses: actions/upload-artifact@v3
name: Upload artifacts (commit)
if: (startsWith(github.event.ref, 'refs/tags') != true)
with:
path: |
.pio/build/*.bin
- uses: actions/upload-artifact@v3
name: Upload artifacts (release)
if: startsWith(github.ref, 'refs/tags/')
with:
name: firmware-release
path: |
.pio/build/*.bin
################################
###### Publish Releases ########
################################

publish:
name: Publish Releases
if: startsWith(github.event.ref, 'refs/tags')
needs: [PlatformIO]
runs-on: ubuntu-latest
steps:
# generate environment variables
- name: Generate environment variables from version and tag
run: |
echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo "preRelease=false" >> $GITHUB_ENV
# If version contains alpha or beta, mark draft release as pre-release
- name: Mark release as pre-release
if: contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta')
run: echo "preRelease=true" >> $GITHUB_ENV

- uses: actions/download-artifact@v3
with:
name: firmware-release

# create draft release and upload artifacts
- name: Create draft release
uses: softprops/action-gh-release@v1
with:
name: HyperSerialEsp8266 ${{ env.VERSION }}
tag_name: ${{ env.TAG }}
files: |
*.bin
draft: true
prerelease: ${{ env.preRelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
10 changes: 10 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
37 changes: 11 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ Statistics are sent to serial port monitor when there is no data incoming. You c

# Flashing

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

For **RGBW LED strip** like RGBW SK6812 NEUTRAL white choose: *firmware_SK6812_RGBW_NEUTRAL.bin*

For **RGBW LED strip** like RGBW SK6812 COLD white choose: *HyperSerialEsp8266.ino.d1_mini_SK6812_COLD_WHITE_FIRSTLED_xxxxxx.bin*
For **RGBW LED strip** like RGBW SK6812 COLD white choose: *firmware_SK6812_RGBW_COLD.bin*

For **RGB LED strip** like WS8212b or RGB SK6812 variant choose: *HyperSerialEsp8266.ino.d1_mini_WS821x_FIRSTLED_xxxxxx.bin*
For **RGB LED strip** like WS8212b or RGB SK6812 variant choose: *firmware_WS281x_RGB.bin*

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*
For **SPI driven RGB LED strip** APA102: *firmware_SPI_APA102_SK9822_HD107.bin*, WS8201: *firmware_SPI_WS2801.bin*

If the first LED in the strip should be enabled or set to black is your choice.
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)

For the RGBW firmware the white channel is automatically calculated and R,G,B channels are corrected.

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

# Compiling

Compile the sketch using Arduino IDE. You need:
- https://github.com/esp8266/Arduino/ (boards for ESP8266, release uses: d1 mini)
- Makuna/NeoPixelBus (install from Arduino IDE: manage libraries)

**Options (first lines of the sketch):**

For RGB strip like WS8212b delete it or comment it with '//', leave it for RGBW SK6812:
*#define THIS_IS_RGBW*

For RGBW cold white LED strip version if above declaration is defined, delete it or comment it with '//' for RGBW neutral:
*#define COLD_WHITE*
Currently we use PlatformIO to compile the project. Install [Visual Studio Code](https://code.visualstudio.com/) and add [PlatformIO plugin](https://platformio.org/).
This environment will take care of everything and compile the firmware for you.

SPI: for APA102/SK9822/HD107 delete it or comment it with '//', leave it for WS2801:
*#define is_WS2801*

Skip first led in the strip, that is used as level shifter:
*bool skipFirstLed = true;*

Serial port speed:
*int serialSpeed = 2000000;*

Don't change LED's count as it is dynamic.
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!

# Pinout

Expand Down
13 changes: 13 additions & 0 deletions extra_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Import("env")
from pathlib import Path
import shutil


def post_program_action(source, target, env):
program_path = target[0].get_abspath()
path = Path(program_path)
shutil.copy(program_path, path.parent.parent.absolute())
env.AddPostAction("$BUILD_DIR/${PROGNAME}.bin", post_program_action)

env.Replace(PROGNAME="firmware_%s" % env.GetProjectOption("custom_prog_version"))

39 changes: 39 additions & 0 deletions include/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

This directory is intended for project header files.

A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.

```src/main.c

#include "header.h"

int main (void)
{
...
}
```

Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.

In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.

Read more about using header files in official GCC documentation:

* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes

https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
82 changes: 82 additions & 0 deletions include/calibration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/* calibration.h
*
* MIT License
*
* Copyright (c) 2022 awawa-dev
*
* https://github.com/awawa-dev/HyperSerialEsp8266
*
* 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 CALIBRATION_H
#define CALIBRATION_H

#include <stdint.h>
#include <algorithm>

#define ROUND_DIVIDE(numer, denom) (((numer) + (denom) / 2) / (denom))

struct {
uint8_t white[256];
uint8_t red[256];
uint8_t green[256];
uint8_t blue[256];
} channelCorrection;

struct {
uint8_t gain = 0xFF;
#ifdef COLD_WHITE
uint8_t red = 0xA0; // adjust red -> white in 0-0xFF range
uint8_t green = 0xA0; // adjust green -> white in 0-0xFF range
uint8_t blue = 0xA0; // adjust blue -> white in 0-0xFF range
#else
uint8_t red = 0xB0; // adjust red -> white in 0-0xFF range
uint8_t green = 0xB0; // adjust green -> white in 0-0xFF range
uint8_t blue = 0x70; // adjust blue -> white in 0-0xFF range
#endif

void setParams(uint8_t _gain, uint8_t _red, uint8_t _green, uint8_t _blue)
{
gain = _gain;
red = _red;
green = _green;
blue = _blue;
}

void prepareCalibration()
{
// prepare LUT calibration table, cold white is much better than "neutral" white
for (uint32_t i = 0; i < 256; i++)
{
// color calibration
uint32_t _gain = uint32_t(gain) * i; // adjust gain
uint32_t _red = red * i; // adjust red
uint32_t _green = green * i; // adjust green
uint32_t _blue = blue * i; // adjust blue

channelCorrection.white[i] = (uint8_t)std::min(ROUND_DIVIDE(_gain, 0xFF), (uint32_t)0xFF);
channelCorrection.red[i] = (uint8_t)std::min(ROUND_DIVIDE(_red, 0xFF), (uint32_t)0xFF);
channelCorrection.green[i] = (uint8_t)std::min(ROUND_DIVIDE(_green,0xFF), (uint32_t)0xFF);
channelCorrection.blue[i] = (uint8_t)std::min(ROUND_DIVIDE(_blue, 0xFF), (uint32_t)0xFF);
}
}
} calibrationConfig;
#endif

46 changes: 46 additions & 0 deletions lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c

and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>

int main (void)
{
...
}

```

PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
Loading

0 comments on commit 1399cf6

Please sign in to comment.