Skip to content

Commit

Permalink
Add MK8 based on ESP32-C6 (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Dec 9, 2024
1 parent f16ee4f commit 289a6fb
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 15 additions & 0 deletions main/devices/Device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ static constexpr double BATTERY_BOOT_THRESHOLD = 3.2;
*/
static constexpr double BATTERY_SHUTDOWN_THRESHOLD = 3.0;

#elif defined(MK8)
#include <devices/UglyDucklingMk8.hpp>
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
Expand Down
42 changes: 42 additions & 0 deletions main/devices/UglyDucklingMk8.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <kernel/FileSystem.hpp>
#include <kernel/Kernel.hpp>
#include <kernel/Pin.hpp>
#include <kernel/Service.hpp>
#include <kernel/drivers/LedDriver.hpp>

#include <peripherals/Peripheral.hpp>

#include <devices/DeviceDefinition.hpp>

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<Mk8Config> {
public:
UglyDucklingMk8()
: DeviceDefinition<Mk8Config>(
pins::STATUS,
pins::BOOT) {
}

void registerDeviceSpecificPeripheralFactories(PeripheralManager& peripheralManager) override {
}
};

} // namespace farmhub::devices
41 changes: 41 additions & 0 deletions wokwi/diagram.flow-control-mk8.json
Original file line number Diff line number Diff line change
@@ -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": {}
}

0 comments on commit 289a6fb

Please sign in to comment.