From 289a6fb4992035e2a2a3a32e050e5ac377fbb6f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Thu, 5 Dec 2024 20:21:35 +0100 Subject: [PATCH] Add MK8 based on ESP32-C6 (WIP) --- .github/workflows/build.yml | 4 +++ CMakeLists.txt | 6 ++++- main/devices/Device.hpp | 15 +++++++++++ main/devices/UglyDucklingMk8.hpp | 42 +++++++++++++++++++++++++++++ wokwi/diagram.flow-control-mk8.json | 41 ++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 main/devices/UglyDucklingMk8.hpp create mode 100644 wokwi/diagram.flow-control-mk8.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f44f670c..5c420536 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,6 +31,10 @@ jobs: ud_gen: MK7 ud_debug: 1 target: esp32s3 + - environment: mk8-release + ud_gen: MK8 + ud_debug: 0 + target: esp32c6 steps: - uses: actions/checkout@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index eb03bd8f..e0f71a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,12 +14,16 @@ set_property(GLOBAL PROPERTY UD_GEN_TRACKER "${UD_GEN}") if(UD_GEN STREQUAL "MK4") if (NOT "$ENV{IDF_TARGET}" STREQUAL "esp32s2") - message(FATAL_ERROR "Error: Ugly Duckling MK4 is only supported on ESP32-S2, currently IDF_TARGET = '$ENV{IDF_TARGET}'") + message(FATAL_ERROR "Error: Ugly Duckling ${UD_GEN} is only supported on ESP32-S2, currently IDF_TARGET = '$ENV{IDF_TARGET}'") endif() elseif(UD_GEN STREQUAL "MK5" OR UD_GEN STREQUAL "MK6" OR UD_GEN STREQUAL "MK7") if (NOT "$ENV{IDF_TARGET}" STREQUAL "esp32s3") message(FATAL_ERROR "Error: Ugly Duckling ${UD_GEN} is only supported on ESP32-S3, currently IDF_TARGET = '$ENV{IDF_TARGET}'") endif() +elseif(UD_GEN STREQUAL "MK8") + if (NOT "$ENV{IDF_TARGET}" STREQUAL "esp32c6") + message(FATAL_ERROR "Error: Ugly Duckling ${UD_GEN} is only supported on ESP32-C6, currently IDF_TARGET = '$ENV{IDF_TARGET}'") + endif() else() message(FATAL_ERROR "Error: Unrecognized Ugly Duckling generation '${UD_GEN}'") endif() diff --git a/main/devices/Device.hpp b/main/devices/Device.hpp index 16f40bb5..c2789dea 100644 --- a/main/devices/Device.hpp +++ b/main/devices/Device.hpp @@ -88,6 +88,21 @@ static constexpr double BATTERY_BOOT_THRESHOLD = 3.2; */ static constexpr double BATTERY_SHUTDOWN_THRESHOLD = 3.0; +#elif defined(MK8) +#include +typedef farmhub::devices::UglyDucklingMk8 TDeviceDefinition; +typedef farmhub::devices::Mk8Config TDeviceConfiguration; + +/** + * @brief Do not boot if battery is below this threshold. + */ +static constexpr double BATTERY_BOOT_THRESHOLD = 3.2; + +/** + * @brief Shutdown if battery drops below this threshold. + */ +static constexpr double BATTERY_SHUTDOWN_THRESHOLD = 3.0; + #else #error "No device defined" #endif diff --git a/main/devices/UglyDucklingMk8.hpp b/main/devices/UglyDucklingMk8.hpp new file mode 100644 index 00000000..74ade32e --- /dev/null +++ b/main/devices/UglyDucklingMk8.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include + +#include + +using namespace farmhub::kernel; + +namespace farmhub::devices { + +namespace pins { +static InternalPinPtr BOOT = InternalPin::registerPin("BOOT", GPIO_NUM_0); +static InternalPinPtr STATUS = InternalPin::registerPin("STATUS", GPIO_NUM_8); +} // namespace pins + +class Mk8Config + : public DeviceConfiguration { +public: + Mk8Config() + : DeviceConfiguration("mk8") { + } +}; + +class UglyDucklingMk8 : public DeviceDefinition { +public: + UglyDucklingMk8() + : DeviceDefinition( + pins::STATUS, + pins::BOOT) { + } + + void registerDeviceSpecificPeripheralFactories(PeripheralManager& peripheralManager) override { + } +}; + +} // namespace farmhub::devices diff --git a/wokwi/diagram.flow-control-mk8.json b/wokwi/diagram.flow-control-mk8.json new file mode 100644 index 00000000..8121d7c4 --- /dev/null +++ b/wokwi/diagram.flow-control-mk8.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "author": "Lóránt Pintér", + "editor": "wokwi", + "parts": [ + { "type": "board-esp32-c6-devkitc-1", "id": "esp", "top": -0.18, "left": 4.57, "attrs": {} }, + { + "type": "wokwi-led", + "id": "statusLed", + "top": 63.6, + "left": -159.4, + "attrs": { "color": "white", "label": "Status" } + }, + { + "type": "wokwi-resistor", + "id": "r1", + "top": 119.15, + "left": -124.8, + "attrs": { "value": "22" } + }, + { + "type": "wokwi-pushbutton", + "id": "btn1", + "top": -61, + "left": 19.2, + "attrs": { "color": "green", "label": "Flash", "bounce": "0" } + } + ], + "connections": [ + [ "esp:TX", "$serialMonitor:RX", "", [] ], + [ "esp:RX", "$serialMonitor:TX", "", [] ], + [ "r1:1", "esp:3V3.2", "green", [ "v0" ] ], + [ "statusLed:C", "esp:26", "green", [ "v0" ] ], + [ "btn1:1.l", "esp:0", "green", [ "h-86.4", "v148.13" ] ], + [ "statusLed:C", "r1:1", "green", [ "v0" ] ], + [ "esp:8", "statusLed:A", "green", [ "h0" ] ], + [ "esp:GND.1", "r1:2", "black", [ "h0" ] ], + [ "esp:GND.4", "btn1:2.r", "black", [ "h17.65", "v-61.93" ] ] + ], + "dependencies": {} +}