Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit 5d9e90f

Browse files
author
Khalil Estell
committed
💥✨ libhal 3.0.0
Migrate from Boost.LEAF to C++ exceptions
1 parent 0bc4ddf commit 5d9e90f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+538
-860
lines changed

.github/workflows/3.0.0-alpha.1.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: 🚀 Deploy exceptions v1
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy:
8+
uses: libhal/ci/.github/workflows/[email protected]
9+
with:
10+
version: exceptions
11+
arch: "x86_64"
12+
secrets: inherit

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ name: ✅ CI
33
on:
44
workflow_dispatch:
55
pull_request:
6-
release:
7-
types:
8-
- published
9-
- deleted
106
push:
117
branches:
128
- main
@@ -15,5 +11,5 @@ on:
1511

1612
jobs:
1713
ci:
18-
uses: libhal/ci/.github/workflows/library.yml@4.x.y
14+
uses: libhal/ci/.github/workflows/library_check.yml@5.x.y
1915
secrets: inherit

CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ libhal_unit_test(SOURCES
4747
tests/main.test.cpp
4848

4949
PACKAGES
50-
boost-leaf
5150
tl-function-ref
5251

5352
LINK_LIBRARIES
54-
boost::leaf
5553
tl::function-ref)

conanfile.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626

2727
class libhal_conan(ConanFile):
2828
name = "libhal"
29-
version = "2.0.3"
3029
license = "Apache-2.0"
31-
url = "https://github.com/conan-io/conan-center-index"
30+
url = "https://github.com/libhal/libhal"
3231
homepage = "https://libhal.github.io/libhal"
3332
description = ("A collection of interfaces and abstractions for embedded "
3433
"peripherals and devices using modern C++")
@@ -51,10 +50,6 @@ def _compilers_minimum_version(self):
5150
"apple-clang": "14.0.0"
5251
}
5352

54-
@property
55-
def _bare_metal(self):
56-
return self.settings.os == "baremetal"
57-
5853
def validate(self):
5954
if self.settings.get_safe("compiler.cppstd"):
6055
check_min_cppstd(self, self._min_cppstd)
@@ -66,7 +61,6 @@ def build_requirements(self):
6661

6762
def requirements(self):
6863
self.requires("tl-function-ref/1.0.0")
69-
self.requires("boost-leaf/1.83.0")
7064

7165
def layout(self):
7266
cmake_layout(self)
@@ -90,13 +84,5 @@ def package_info(self):
9084
self.cpp_info.libdirs = []
9185
self.cpp_info.resdirs = []
9286

93-
if self._bare_metal:
94-
self.cpp_info.defines = [
95-
"BOOST_LEAF_EMBEDDED",
96-
# TODO(#694): Remove this or have it be configurable. Users
97-
# should not be forced to operate without thread support
98-
"BOOST_LEAF_NO_THREADS"
99-
]
100-
10187
def package_id(self):
10288
self.info.clear()

include/libhal/accelerometer.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#pragma once
1616

17-
#include "error.hpp"
1817
#include "units.hpp"
1918

2019
namespace hal {
@@ -53,16 +52,16 @@ class accelerometer
5352
/**
5453
* @brief Read the latest acceleration sensed by the device
5554
*
56-
* @return result<read_t> - acceleration data
55+
* @return read_t - acceleration data
5756
*/
58-
[[nodiscard]] result<read_t> read()
57+
[[nodiscard]] read_t read()
5958
{
6059
return driver_read();
6160
}
6261

6362
virtual ~accelerometer() = default;
6463

6564
private:
66-
virtual result<read_t> driver_read() = 0;
65+
virtual read_t driver_read() = 0;
6766
};
6867
} // namespace hal

include/libhal/adc.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#pragma once
1616

17-
#include "error.hpp"
18-
1917
namespace hal {
2018
/**
2119
* @brief Analog to Digital Converter (ADC) hardware abstraction interface.
@@ -50,16 +48,16 @@ class adc
5048
/**
5149
* @brief Sample the analog to digital converter and return the result
5250
*
53-
* @return result<read_t> - the sampled adc value
51+
* @return read_t - the sampled adc value
5452
*/
55-
[[nodiscard]] result<read_t> read()
53+
[[nodiscard]] read_t read()
5654
{
5755
return driver_read();
5856
}
5957

6058
virtual ~adc() = default;
6159

6260
private:
63-
virtual result<read_t> driver_read() = 0;
61+
virtual read_t driver_read() = 0;
6462
};
6563
} // namespace hal

include/libhal/can.hpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <array>
1818
#include <cstdint>
1919

20-
#include "error.hpp"
2120
#include "functional.hpp"
2221
#include "units.hpp"
2322

@@ -149,10 +148,10 @@ class can
149148
* @brief Configure this can bus port to match the settings supplied
150149
*
151150
* @param p_settings - settings to apply to can driver
152-
* @return status - success or failure
151+
* @return void - success or failure
153152
* @throws std::errc::invalid_argument if the settings could not be achieved.
154153
*/
155-
[[nodiscard]] status configure(const settings& p_settings)
154+
void configure(const settings& p_settings)
156155
{
157156
return driver_configure(p_settings);
158157
}
@@ -176,11 +175,11 @@ class can
176175
* If this occurs, this function must be called to re-enable bus
177176
* communication.
178177
*
179-
* @return status - success or failure. In the case this function fails
178+
* @return void - success or failure. In the case this function fails
180179
* repeatedly, it is advised to simply not use the bus anymore as something is
181180
* critical wrong and may not be recoverable.
182181
*/
183-
[[nodiscard]] status bus_on()
182+
void bus_on()
184183
{
185184
return driver_bus_on();
186185
}
@@ -189,13 +188,13 @@ class can
189188
* @brief Send a can message
190189
*
191190
* @param p_message - the message to be sent
192-
* @return result<send_t> - success or failure
191+
* @return send_t - success or failure
193192
* @throws std::errc::network_down - if the can device is in the "bus-off"
194193
* state. This can happen if a critical fault in the bus has occurred. A call
195194
* to `bus_on()` will need to be issued to attempt to talk on the bus again.
196195
* See `bus_on()` for more details.
197196
*/
198-
[[nodiscard]] result<send_t> send(const message_t& p_message)
197+
send_t send(const message_t& p_message)
199198
{
200199
return driver_send(p_message);
201200
}
@@ -216,9 +215,9 @@ class can
216215
virtual ~can() = default;
217216

218217
private:
219-
virtual status driver_configure(const settings& p_settings) = 0;
220-
virtual status driver_bus_on() = 0;
221-
virtual result<send_t> driver_send(const message_t& p_message) = 0;
218+
virtual void driver_configure(const settings& p_settings) = 0;
219+
virtual void driver_bus_on() = 0;
220+
virtual send_t driver_send(const message_t& p_message) = 0;
222221
virtual void driver_on_receive(hal::callback<handler> p_handler) = 0;
223222
};
224223
} // namespace hal

include/libhal/dac.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
#pragma once
1616

17+
#include <algorithm>
1718
#include <cstdint>
1819

19-
#include "error.hpp"
20-
2120
namespace hal {
2221
/**
2322
* @brief Digital to Analog Converter (DAC) hardware abstraction interface.
@@ -58,9 +57,9 @@ class dac
5857
*
5958
* @param p_percentage - value from 0.0f to +1.0f representing the proportion
6059
* of the output voltage from the Vss to Vcc.
61-
* @return result<write_t> - success or failure
60+
* @return write_t - success or failure
6261
*/
63-
[[nodiscard]] result<write_t> write(float p_percentage)
62+
write_t write(float p_percentage)
6463
{
6564
auto clamped_percentage = std::clamp(p_percentage, 0.0f, 1.0f);
6665
return driver_write(clamped_percentage);
@@ -69,6 +68,6 @@ class dac
6968
virtual ~dac() = default;
7069

7170
private:
72-
virtual result<write_t> driver_write(float p_percentage) = 0;
71+
virtual write_t driver_write(float p_percentage) = 0;
7372
};
7473
} // namespace hal

include/libhal/distance_sensor.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#pragma once
1616

17-
#include "error.hpp"
1817
#include "units.hpp"
1918

2019
namespace hal {
@@ -96,16 +95,16 @@ class distance_sensor
9695
/**
9796
* @brief Read the current distance measured by the device
9897
*
99-
* @return result<read_t> - distance data
98+
* @return read_t - distance data
10099
*/
101-
[[nodiscard]] result<read_t> read()
100+
[[nodiscard]] read_t read()
102101
{
103102
return driver_read();
104103
}
105104

106105
virtual ~distance_sensor() = default;
107106

108107
private:
109-
virtual result<read_t> driver_read() = 0;
108+
virtual read_t driver_read() = 0;
110109
};
111110
} // namespace hal

include/libhal/error.hpp

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,66 +15,26 @@
1515
#pragma once
1616

1717
#include <system_error>
18-
19-
#include <boost/leaf/detail/all.hpp>
20-
21-
#define HAL_CHECK BOOST_LEAF_CHECK
18+
#include <type_traits>
2219

2320
namespace hal {
2421

25-
template<typename T, T... value>
26-
using match = boost::leaf::match<T, value...>;
27-
template<class T>
28-
using result = boost::leaf::result<T>;
29-
using status = result<void>;
3022
using error_handler = void(void);
3123

3224
inline error_handler* on_error_callback = nullptr;
3325

34-
/**
35-
* @brief a readability function for returning successful results;
36-
*
37-
* For functions that return `status`, rather than returning `{}` to default
38-
* initialize the status object as "success", use this function to make it more
39-
* clear to the reader.
40-
*
41-
* EXAMPLE:
42-
*
43-
* hal::status some_function() {
44-
* return hal::success();
45-
* }
46-
*
47-
* @return status - that is always successful
48-
*/
49-
inline status success()
50-
{
51-
// Default initialize the status object using the brace initialization, which
52-
// will set the status to the default "success" state.
53-
status successful_status{};
54-
return successful_status;
55-
}
56-
57-
template<class TryBlock, class... H>
58-
[[nodiscard]] constexpr auto attempt(TryBlock&& p_try_block, H&&... p_handlers)
59-
{
60-
return boost::leaf::try_handle_some(p_try_block, p_handlers...);
61-
}
62-
63-
template<class TryBlock, class... H>
64-
[[nodiscard]] constexpr auto attempt_all(TryBlock&& p_try_block,
65-
H&&... p_handlers)
26+
template<class thrown_t>
27+
void safe_throw(thrown_t&& p_thrown_object)
6628
{
67-
return boost::leaf::try_handle_all(p_try_block, p_handlers...);
68-
}
29+
static_assert(
30+
std::is_trivially_destructible_v<thrown_t>,
31+
"safe_throw() only works with trivially destructible thrown types");
6932

70-
template<class... Item>
71-
[[nodiscard]] inline auto new_error(Item&&... p_item)
72-
{
7333
if (on_error_callback) {
7434
on_error_callback();
7535
}
7636

77-
return boost::leaf::new_error(std::forward<Item>(p_item)...);
37+
throw p_thrown_object;
7838
}
7939

8040
[[noreturn]] inline void halt()

0 commit comments

Comments
 (0)