Skip to content

Commit

Permalink
Add support for M5Stack Core and Core2 (#56)
Browse files Browse the repository at this point in the history
* feat: add support fore M5 Core2

* docs: mention Core2 in description

* feat: add core2 configuration to github actions

* feat: support three buttons on core2

* Try using a build matrix for the CI.

* Try again with the build matrix.

* Minor workflow action cleanup.

* Refactor clang-format to separate stage.

* Add a final success stage so CI can pass.

* Depend on format check for success.

* Add M5Stack Core release binary.

---------

Co-authored-by: Sebastian Müller <[email protected]>
  • Loading branch information
gkoh and sbstjn authored Oct 24, 2023
1 parent 36f64a3 commit 0a1ebbf
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 23 deletions.
37 changes: 28 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ on:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
format:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Run clang-format style check
Expand All @@ -27,6 +23,24 @@ jobs:
check-path: '.'
exclude-regex: 'lib/M5ez/examples'

# This workflow contains a matrix of build platforms
build:
strategy:
matrix:
platform:
- m5stick-c
- m5stick-c-plus
- m5stack-core
- m5stack-core2

# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
Expand All @@ -37,8 +51,13 @@ jobs:
run: |
pip install -r requirements.txt
- name: Build furble (M5StickC)
run: platformio run -e m5stick-c
- name: Build furble (${{ matrix.platform }})
run: platformio run -e ${{ matrix.platform }}

- name: Build furble (M5StickC Plus)
run: platformio run -e m5stick-c-plus
success:
runs-on: ubuntu-latest
needs:
- format
- build
steps:
- run: echo "Success"!
16 changes: 15 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ env:
FURBLE_VERSION: ${{ github.ref_name }}+${{ github.run_attempt }}
M5STICKC_FIRMWARE: furble-m5stick-c-${{ github.ref_name }}+${{ github.run_attempt }}.bin
M5STICKC_PLUS_FIRMWARE: furble-m5stick-c-plus-${{ github.ref_name }}+${{ github.run_attempt }}.bin
M5STACK_CORE_FIRMWARE: furble-m5stack-core-${{ github.ref_name }}+${{ github.run_attempt }}.bin
M5STACK_CORE2_FIRMWARE: furble-m5stack-core2-${{ github.ref_name }}+${{ github.run_attempt }}.bin

jobs:
build:
Expand Down Expand Up @@ -39,9 +41,19 @@ jobs:
platformio run -e m5stick-c-plus
cp -v .pio/build/m5stick-c-plus/firmware.bin $M5STICKC_PLUS_FIRMWARE
- name: Build furble (M5Stack Core)
run: |
platformio run -e m5stack-core
cp -v .pio/build/m5stack-core/firmware.bin $M5STACK_CORE_FIRMWARE
- name: Build furble (M5Stack Core2)
run: |
platformio run -e m5stack-core2
cp -v .pio/build/m5stack-core2/firmware.bin $M5STACK_CORE2_FIRMWARE
- name: Generate release hashes
run: |
sha256sum $M5STICKC_FIRMWARE $M5STICKC_PLUS_FIRMWARE > sha256sum.txt
sha256sum $M5STICKC_FIRMWARE $M5STICKC_PLUS_FIRMWARE $M%M5STACK_CORE_FIRMWARE $M5STACK_CORE2_FIRMWARE > sha256sum.txt
- name: Release
uses: softprops/action-gh-release@v1
Expand All @@ -50,4 +62,6 @@ jobs:
files: |
${{ env.M5STICKC_FIRMWARE }}
${{ env.M5STICKC_PLUS_FIRMWARE }}
${{ env.M5STACK_CORE_FIRMWARE }}
${{ env.M5STACK_CORE2_FIRMWARE }}
sha256sum.txt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.pio
.vscode
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The remote uses the camera's native Bluetooth Low Energy interface so additional
adapters are not required.

furble is developed as a PlatformIO project for the M5StickC and M5StickC Plus
(ESP32 based devices).
(ESP32 based devices). Additionally, it can be used on the M5Stack Core2.

## Supported Cameras

Expand Down Expand Up @@ -118,6 +118,8 @@ In most cases it should be:
- `platformio run -e m5stick-c -t upload`
- OR plug in the M5StickC Plus
- `platformio run -e m5stick-c-plus -t upload`
- OR plug in the M5Stack Core2
- `platformio run -e m5stack-core2 -t upload`

## Usage

Expand Down
35 changes: 29 additions & 6 deletions lib/M5ez/src/M5ez.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ void ezCanvas::_putString(String text) {

String ezButtons::_btn_a_s, ezButtons::_btn_a_l;
String ezButtons::_btn_b_s, ezButtons::_btn_b_l;
String ezButtons::_btn_c_s, ezButtons::_btn_c_l;
bool ezButtons::_key_release_wait;
bool ezButtons::_lower_button_row, ezButtons::_upper_button_row;

Expand All @@ -543,12 +544,13 @@ void ezButtons::show(String buttons) {
ez.chopString(buttons, "#", buttonVector, true);
switch (buttonVector.size()) {
case 1:
_drawButtons("", "", buttons, "");
_drawButtons("", "", buttons, "", "", "", "", "", "");
break;
case 2:
_drawButtons(buttonVector[0], "", buttonVector[1], "", "", "", "", "", "");
case 3:
// Three elements, so shortpress only
_drawButtons(buttonVector[0], "", buttonVector[1], "");
_drawButtons(buttonVector[0], "", buttonVector[1], "", buttonVector[2], "", "", "", "");
break;
}
}
Expand All @@ -558,17 +560,26 @@ void ezButtons::clear(bool wipe /* = true */) {
M5.Lcd.fillRect(0, ez.canvas.bottom() + 1, TFT_H - ez.canvas.bottom() - 1, TFT_W,
ez.screen.background());
}
_btn_a_s = _btn_a_l = _btn_b_s = _btn_b_l = "";
_btn_a_s = _btn_a_l = _btn_b_s = _btn_b_l = _btn_c_s = _btn_c_l = "";
_lower_button_row = false;
_upper_button_row = false;
ez.canvas.bottom(TFT_H - 1);
}

void ezButtons::_drawButtons(String btn_a_s, String btn_a_l, String btn_b_s, String btn_b_l) {
void ezButtons::_drawButtons(String btn_a_s,
String btn_a_l,
String btn_b_s,
String btn_b_l,
String btn_c_s,
String btn_c_l,
String btn_ab,
String btn_bc,
String btn_ac) {
int16_t btnwidth = int16_t((TFT_W - 4 * ez.theme->button_gap) / 3);

// See if any buttons are used on the bottom row
if (btn_a_s != "" || btn_a_l != "" || btn_b_s != "" || btn_b_l != "") {
if (btn_a_s != "" || btn_a_l != "" || btn_b_s != "" || btn_b_l != "" || btn_c_s != ""
|| btn_c_l != "") {
if (!_lower_button_row) {
// If the lower button row wasn't there before, clear the area first
M5.Lcd.fillRect(0, TFT_H - ez.theme->button_height - ez.theme->button_gap, TFT_W,
Expand All @@ -587,13 +598,19 @@ void ezButtons::_drawButtons(String btn_a_s, String btn_a_l, String btn_b_s, Str
_btn_b_s = btn_b_s;
_btn_b_l = btn_b_l;
}
if (_btn_c_s != btn_c_s || _btn_c_l != btn_c_l) {
_drawButton(1, ez.rightOf(btn_c_s, "|", true), ez.rightOf(btn_c_l, "|", true),
2 * btnwidth + 3 * ez.theme->button_gap, btnwidth);
_btn_c_s = btn_c_s;
_btn_c_l = btn_c_l;
}
_lower_button_row = true;
} else {
if (_lower_button_row) {
// If there was a lower button row before and it's now gone, clear the area
M5.Lcd.fillRect(0, TFT_H - ez.theme->button_height - ez.theme->button_gap, TFT_W,
ez.theme->button_height + ez.theme->button_gap, ez.screen.background());
_btn_a_s = _btn_a_l = _btn_b_s = _btn_b_l = "";
_btn_a_s = _btn_a_l = _btn_b_s = _btn_b_l = _btn_c_s = _btn_c_l = "";
_lower_button_row = false;
}
}
Expand Down Expand Up @@ -743,6 +760,10 @@ void ezSettings::begin() {
ez.settings.menuObj.addItem("Theme chooser", ez.theme->menu);
}
ez.settings.menuObj.addItem("Factory defaults", ez.settings.defaults);

#ifdef M5STACK_CORE2
M5.Lcd.setRotation(1);
#endif
}

void ezSettings::menu() {
Expand Down Expand Up @@ -2834,6 +2855,8 @@ void M5ez::setFont(const GFXfont *font) {
int16_t M5ez::fontHeight() {
#if M5STICKC_PLUS
return M5.Lcd.fontHeight(M5.Lcd.getFont());
#elif M5STACK_CORE2
return 26;
#else
return 11;
#endif
Expand Down
25 changes: 22 additions & 3 deletions lib/M5ez/src/M5ez.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
#define TFT_HEADER_HEIGHT 23
#define TFT_BUTTON_HEIGHT 19
#define TFT_RADIUS 8
#else
#endif

#ifdef M5STICKC
#define TFT_W 160
#define TFT_H 80
#define TFT_FONT hzk16
Expand All @@ -77,6 +79,15 @@
#define TFT_RADIUS 3
#endif

#ifdef M5STACK_CORE2
#define TFT_W 320
#define TFT_H 240
#define TFT_FONT sans16
#define TFT_HEADER_HEIGHT 23
#define TFT_BUTTON_HEIGHT 19
#define TFT_RADIUS 8
#endif

struct line_t {
int16_t position;
String line;
Expand Down Expand Up @@ -318,12 +329,20 @@ class ezButtons {
private:
static String _btn_a_s, _btn_a_l;
static String _btn_b_s, _btn_b_l;
static String _btn_c_s, _btn_c_l;
static bool _key_release_wait;
static bool _lower_button_row, _upper_button_row;
static void _drawButtons(String btn_a_s, String btn_a_l, String btn_b_s, String btn_b_l);
static void _drawButtons(String btn_a_s,
String btn_a_l,
String btn_b_s,
String btn_b_l,
String btn_c_s,
String btn_c_l,
String btn_ab,
String btn_bc,
String btn_ac);
static void _drawButton(int16_t row, String text_s, String text_l, int16_t x, int16_t w);
static void _drawButtonString(String text, int16_t x, int16_t y, uint16_t color, int16_t datum);
//
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
17 changes: 15 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,30 @@ lib_deps =

[env]
platform = espressif32
board = m5stick-c
board_build.f_cpu = 80000000L
upload_protocol = esptool
framework = arduino

[env:m5stick-c]
build_flags = ${furble.build_flags}
board = m5stick-c
build_flags = ${furble.build_flags} -D M5STICKC
lib_deps =
${furble.lib_deps}

[env:m5stick-c-plus]
board = m5stick-c
build_flags = ${furble.build_flags} -D M5STICKC_PLUS
lib_deps =
${furble.lib_deps}

[env:m5stack-core]
board = m5stack-core-esp32
build_flags = ${furble.build_flags} -D M5STACK_CORE2
lib_deps =
${furble.lib_deps}

[env:m5stack-core2]
board = m5stack-core2
build_flags = ${furble.build_flags} -D M5STACK_CORE2
lib_deps =
${furble.lib_deps}
14 changes: 13 additions & 1 deletion src/furble.ino
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,26 @@ static void about(void) {

static void remote_control(Furble::Device *device) {
Serial.println("Remote Control");
ez.msgBox("Remote Shutter", "Shutter Control: A\nFocus: B\nBack: Power", "", false);

#ifdef M5STACK_CORE2
ez.msgBox("Remote Shutter", "", "Release#Focus#Back", false);
#else
ez.msgBox("Remote Shutter", "Back: Power", "Release#Focus", false);
#endif
while (true) {
M5.update();

update_geodata(device);

#ifdef M5STACK_CORE2
if (M5.BtnC.wasPressed()) {
break;
}
#else
if (M5.BtnPWR.wasClicked()) {
break;
}
#endif

if (M5.BtnA.wasPressed()) {
device->shutterPress();
Expand Down Expand Up @@ -280,6 +291,7 @@ void setup() {
ez.header.insert(GPS_HEADER_POSITION, "gps", ez.theme->header_height * 0.8, gps_draw_widget);
ez.addEvent(service_grove_gps, millis() + 500);
ez.addEvent(current_service, millis() + 500);

NimBLEDevice::init(FURBLE_STR);
NimBLEDevice::setSecurityAuth(true, true, true);

Expand Down

0 comments on commit 0a1ebbf

Please sign in to comment.