Skip to content

Commit

Permalink
🎨 Upgrade to bootstrap-4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kammce committed Aug 6, 2024
1 parent 36238d8 commit e069f18
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 26 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class libhal___device___conan(ConanFile):
topics = ("__device__", "libhal", "driver")
settings = "compiler", "build_type", "os", "arch"

python_requires = "libhal-bootstrap/[^3.0.0]"
python_requires = "libhal-bootstrap/[^4.0.0]"
python_requires_extend = "libhal-bootstrap.library"

def requirements(self):
Expand Down
3 changes: 3 additions & 0 deletions demos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ libhal_build_demos(
DEMOS
__device__

INCLUDES
.

PACKAGES
libhal-__device__

Expand Down
6 changes: 3 additions & 3 deletions demos/applications/__device__.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ void application(resource_list& p_map)
using namespace std::chrono_literals;
using namespace hal::literals;

auto& clock = *p_map.clock;
auto& console = *p_map.console;
auto& led = *p_map.led;
auto& clock = *p_map.clock.value();
auto& console = *p_map.console.value();
auto& led = *p_map.status_led.value();

hal::print(console, "Demo Application Starting...\n\n");

Expand Down
2 changes: 1 addition & 1 deletion demos/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class demos(ConanFile):
python_requires = "libhal-bootstrap/[^3.0.0]"
python_requires = "libhal-bootstrap/[^4.0.0]"
python_requires_extend = "libhal-bootstrap.demo"

def requirements(self):
Expand Down
44 changes: 32 additions & 12 deletions demos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,31 @@
// limitations under the License.

#include <libhal-exceptions/control.hpp>
#include <libhal-util/serial.hpp>
#include <libhal-util/steady_clock.hpp>
#include <libhal/error.hpp>

#include "resource_list.hpp"
#include <resource_list.hpp>

resource_list resources{};

[[noreturn]] void terminate_handler() noexcept
{
using namespace std::chrono_literals;

auto& led = *resources.led;
auto& clock = *resources.clock;
if (not resources.status_led && not resources.console) {
// spin here until debugger is connected
while (true) {
continue;
}
}

// Otherwise, blink the led in a pattern

auto& led = *resources.status_led.value();
auto& clock = *resources.clock.value();

while (true) {
using namespace std::chrono_literals;
led.level(false);
hal::delay(clock, 100ms);
led.level(true);
Expand All @@ -41,17 +51,27 @@ resource_list resources{};

int main()
{
// Set terminate routine...
hal::set_terminate(terminate_handler);

try {
resources = initialize_platform();
} catch (...) {
// Catch all exceptions preventing terminate from
hal::halt();
while (true) {
// halt here and wait for a debugger to connect
continue;
}
}

application(resources);
resources.reset();
return 0;
hal::set_terminate(terminate_handler);

try {
application(resources);
} catch (std::bad_optional_access const& e) {
if (resources.console) {
hal::print(*resources.console.value(),
"A resource required by the application was not available!\n"
"Calling terminate!\n");
}
} // Allow any other exceptions to terminate the application

// Terminate if the code reaches this point.
std::terminate();
}
4 changes: 2 additions & 2 deletions demos/platforms/lpc4078.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ resource_list initialize_platform()
static hal::lpc40::output_pin led(1, 10);

return {
.reset = []() { hal::cortex_m::reset(); },
.console = &uart0,
.clock = &counter,
.led = &led,
.reset = []() { hal::cortex_m::reset(); },
.status_led = &led,
};
}
31 changes: 31 additions & 0 deletions demos/platforms/micromod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Khalil Estell
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <libhal-micromod/micromod.hpp>

#include <resource_list.hpp>

resource_list initialize_platform()
{
using namespace hal::literals;

hal::micromod::v1::initialize_platform();

return {
.reset = +[]() { hal::micromod::v1::reset(); },
.console = &hal::micromod::v1::console(hal::buffer<128>),
.clock = &hal::micromod::v1::uptime_clock(),
.status_led = &hal::micromod::v1::led(),
};
}
6 changes: 3 additions & 3 deletions demos/platforms/stm32f103c8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <libhal-stm32f1/output_pin.hpp>
#include <libhal-stm32f1/uart.hpp>

#include "../resource_list.hpp"
#include <resource_list.hpp>

resource_list initialize_platform()
{
Expand All @@ -44,9 +44,9 @@ resource_list initialize_platform()
static hal::stm32f1::output_pin led('C', 13);

return {
.reset = +[]() { hal::cortex_m::reset(); },
.console = &uart1,
.clock = &counter,
.led = &led,
.reset = +[]() { hal::cortex_m::reset(); },
.status_led = &led,
};
}
8 changes: 5 additions & 3 deletions demos/resource_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

#pragma once

#include <optional>

#include <libhal/functional.hpp>
#include <libhal/output_pin.hpp>
#include <libhal/serial.hpp>
#include <libhal/steady_clock.hpp>

struct resource_list
{
hal::serial* console;
hal::steady_clock* clock;
hal::output_pin* led;
hal::callback<void()> reset;
std::optional<hal::serial*> console;
std::optional<hal::steady_clock*> clock;
std::optional<hal::output_pin*> status_led;
// Add more driver interfaces here ...
};

Expand Down
2 changes: 1 addition & 1 deletion test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
python_requires = "libhal-bootstrap/[^2.0.0]"
python_requires = "libhal-bootstrap/[^4.0.0]"
python_requires_extend = "libhal-bootstrap.library_test_package"

def requirements(self):
Expand Down

0 comments on commit e069f18

Please sign in to comment.