From 87c6feee68f5ca25dbd598f746737e525c8a121e Mon Sep 17 00:00:00 2001 From: Khalil Estell Date: Sun, 10 Nov 2024 12:44:37 -0800 Subject: [PATCH] :sparkles: Ad inert drivers from -soft --- CMakeLists.txt | 15 ++++ conanfile.py | 4 +- include/libhal-util/atomic_spin_lock.hpp | 4 +- include/libhal-util/bit_bang_i2c.hpp | 7 -- include/libhal-util/bit_bang_spi.hpp | 4 +- include/libhal-util/i2c_minimum_speed.hpp | 58 --------------- .../inert_drivers/inert_accelerometer.hpp | 45 ++++++++++++ .../libhal-util/inert_drivers/inert_adc.hpp | 48 ++++++++++++ .../libhal-util/inert_drivers/inert_dac.hpp | 39 ++++++++++ .../inert_drivers/inert_distance_sensor.hpp | 45 ++++++++++++ .../inert_drivers/inert_gyroscope.hpp | 45 ++++++++++++ .../inert_drivers/inert_input_pin.hpp | 49 +++++++++++++ .../inert_drivers/inert_interrupt_pin.hpp | 42 +++++++++++ .../inert_drivers/inert_magnetometer.hpp | 45 ++++++++++++ .../libhal-util/inert_drivers/inert_motor.hpp | 40 ++++++++++ .../inert_drivers/inert_output_pin.hpp | 73 +++++++++++++++++++ .../libhal-util/inert_drivers/inert_pwm.hpp | 43 +++++++++++ .../inert_drivers/inert_rotation_sensor.hpp | 45 ++++++++++++ .../inert_drivers/inert_steady_clock.hpp | 55 ++++++++++++++ .../inert_temperature_sensor.hpp | 45 ++++++++++++ .../libhal-util/inert_drivers/inert_timer.hpp | 53 ++++++++++++++ include/libhal-util/input_pin.hpp | 14 +--- include/libhal-util/interrupt_pin.hpp | 15 +--- include/libhal-util/output_pin.hpp | 15 +--- .../inert_accelerometer.test.cpp | 36 +++++++++ tests/inert_drivers/inert_adc.test.cpp | 34 +++++++++ tests/inert_drivers/inert_dac.test.cpp | 31 ++++++++ .../inert_distance_sensor.test.cpp | 34 +++++++++ tests/inert_drivers/inert_gyroscope.test.cpp | 36 +++++++++ tests/inert_drivers/inert_input_pin.test.cpp | 40 ++++++++++ .../inert_interrupt_pin.test.cpp | 32 ++++++++ .../inert_drivers/inert_magnetometer.test.cpp | 36 +++++++++ tests/inert_drivers/inert_motor.test.cpp | 31 ++++++++ tests/inert_drivers/inert_output_pin.test.cpp | 52 +++++++++++++ tests/inert_drivers/inert_pwm.test.cpp | 32 ++++++++ .../inert_rotation_sensor.test.cpp | 34 +++++++++ .../inert_drivers/inert_steady_clock.test.cpp | 39 ++++++++++ .../inert_temperature_sensor.test.cpp | 34 +++++++++ tests/inert_drivers/inert_timer.test.cpp | 42 +++++++++++ tests/serial.test.cpp | 10 +-- 40 files changed, 1283 insertions(+), 118 deletions(-) delete mode 100644 include/libhal-util/i2c_minimum_speed.hpp create mode 100644 include/libhal-util/inert_drivers/inert_accelerometer.hpp create mode 100644 include/libhal-util/inert_drivers/inert_adc.hpp create mode 100644 include/libhal-util/inert_drivers/inert_dac.hpp create mode 100644 include/libhal-util/inert_drivers/inert_distance_sensor.hpp create mode 100644 include/libhal-util/inert_drivers/inert_gyroscope.hpp create mode 100644 include/libhal-util/inert_drivers/inert_input_pin.hpp create mode 100644 include/libhal-util/inert_drivers/inert_interrupt_pin.hpp create mode 100644 include/libhal-util/inert_drivers/inert_magnetometer.hpp create mode 100644 include/libhal-util/inert_drivers/inert_motor.hpp create mode 100644 include/libhal-util/inert_drivers/inert_output_pin.hpp create mode 100644 include/libhal-util/inert_drivers/inert_pwm.hpp create mode 100644 include/libhal-util/inert_drivers/inert_rotation_sensor.hpp create mode 100644 include/libhal-util/inert_drivers/inert_steady_clock.hpp create mode 100644 include/libhal-util/inert_drivers/inert_temperature_sensor.hpp create mode 100644 include/libhal-util/inert_drivers/inert_timer.hpp create mode 100644 tests/inert_drivers/inert_accelerometer.test.cpp create mode 100644 tests/inert_drivers/inert_adc.test.cpp create mode 100644 tests/inert_drivers/inert_dac.test.cpp create mode 100644 tests/inert_drivers/inert_distance_sensor.test.cpp create mode 100644 tests/inert_drivers/inert_gyroscope.test.cpp create mode 100644 tests/inert_drivers/inert_input_pin.test.cpp create mode 100644 tests/inert_drivers/inert_interrupt_pin.test.cpp create mode 100644 tests/inert_drivers/inert_magnetometer.test.cpp create mode 100644 tests/inert_drivers/inert_motor.test.cpp create mode 100644 tests/inert_drivers/inert_output_pin.test.cpp create mode 100644 tests/inert_drivers/inert_pwm.test.cpp create mode 100644 tests/inert_drivers/inert_rotation_sensor.test.cpp create mode 100644 tests/inert_drivers/inert_steady_clock.test.cpp create mode 100644 tests/inert_drivers/inert_temperature_sensor.test.cpp create mode 100644 tests/inert_drivers/inert_timer.test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8439a47..41dee05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,21 @@ cmake_minimum_required(VERSION 3.15) project(libhal-util LANGUAGES CXX) set(TEST_SOURCES_LIST + tests/inert_drivers/inert_accelerometer.test.cpp + tests/inert_drivers/inert_adc.test.cpp + tests/inert_drivers/inert_dac.test.cpp + tests/inert_drivers/inert_distance_sensor.test.cpp + tests/inert_drivers/inert_gyroscope.test.cpp + tests/inert_drivers/inert_input_pin.test.cpp + tests/inert_drivers/inert_interrupt_pin.test.cpp + tests/inert_drivers/inert_magnetometer.test.cpp + tests/inert_drivers/inert_motor.test.cpp + tests/inert_drivers/inert_pwm.test.cpp + tests/inert_drivers/inert_output_pin.test.cpp + tests/inert_drivers/inert_rotation_sensor.test.cpp + tests/inert_drivers/inert_steady_clock.test.cpp + tests/inert_drivers/inert_temperature_sensor.test.cpp + tests/inert_drivers/inert_timer.test.cpp tests/as_bytes.test.cpp tests/can.test.cpp tests/bit.test.cpp diff --git a/conanfile.py b/conanfile.py index 1165cf0..a351dea 100644 --- a/conanfile.py +++ b/conanfile.py @@ -59,10 +59,10 @@ def validate(self): def build_requirements(self): self.tool_requires("cmake/3.27.1") self.tool_requires("libhal-cmake-util/[^4.1.0]") - self.test_requires("boost-ext-ut/1.1.9") + self.test_requires("boost-ext-ut/2.1.0") def requirements(self): - self.requires("libhal/[^4.4.0]", transitive_headers=True) + self.requires("libhal/[^4.7.0]", transitive_headers=True) def layout(self): cmake_layout(self) diff --git a/include/libhal-util/atomic_spin_lock.hpp b/include/libhal-util/atomic_spin_lock.hpp index 1472288..074b711 100644 --- a/include/libhal-util/atomic_spin_lock.hpp +++ b/include/libhal-util/atomic_spin_lock.hpp @@ -19,7 +19,7 @@ #include #include -namespace hal::soft { +namespace hal { /** * @brief Atomic spin lock that implements hal::pollable_lock * @@ -86,4 +86,4 @@ class timed_atomic_spin_lock : public hal::timed_lock hal::steady_clock* m_steady_clock; atomic_spin_lock m_atomic_spin_lock; }; -} // namespace hal::soft +} // namespace hal diff --git a/include/libhal-util/bit_bang_i2c.hpp b/include/libhal-util/bit_bang_i2c.hpp index 63c02d8..2a56d80 100644 --- a/include/libhal-util/bit_bang_i2c.hpp +++ b/include/libhal-util/bit_bang_i2c.hpp @@ -192,10 +192,3 @@ class bit_bang_i2c : public i2c float m_duty_cycle; }; } // namespace hal - -namespace hal { -// This is here for backwards compatibility. -// We made a mistake on the first review and accidentally put bit_bang_i2c in -// the hal namespace. -using hal::soft::bit_bang_i2c; -} // namespace hal diff --git a/include/libhal-util/bit_bang_spi.hpp b/include/libhal-util/bit_bang_spi.hpp index bc2036f..536ae24 100644 --- a/include/libhal-util/bit_bang_spi.hpp +++ b/include/libhal-util/bit_bang_spi.hpp @@ -19,7 +19,7 @@ #include #include -namespace hal::soft { +namespace hal { /** * @brief A bit bang implementation for spi. * @@ -124,4 +124,4 @@ class bit_bang_spi : public spi delay_mode m_delay_mode; }; -} // namespace hal::soft +} // namespace hal diff --git a/include/libhal-util/i2c_minimum_speed.hpp b/include/libhal-util/i2c_minimum_speed.hpp deleted file mode 100644 index 10c9be0..0000000 --- a/include/libhal-util/i2c_minimum_speed.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// 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. - -#pragma once - -#include - -namespace hal { - -// TODO(#38) Remove on libhal 5.0.0 -/** - * @brief A i2c wrapper to ensure that the lowest i2c device frequency is used. - * @deprecated Do not use this class as it is a trap. This wrapper cannot ensure - * that the i2c clock speed is the minimum possible for all devices on the bus - * without knowledge about the system before hand. - */ -class minimum_speed_i2c : public hal::i2c -{ -public: - constexpr static auto default_max_speed = 2'000'000; - /** - * @brief Create minimum_speed_i2c object. - * - * @param p_i2c - i2c object that the device will use - * @param p_frequency - the maximum starting frequency the device can use - */ - minimum_speed_i2c(hal::i2c& p_i2c, hertz p_frequency = default_max_speed); - -private: - /** - * @brief Pass through configuration function from this class to the passed - * i2c driver. - * - * @param p_new_setting - settings to be set - */ - void driver_configure(settings const& p_new_setting) override; - - void driver_transaction( - hal::byte p_address, - std::span p_data_out, - std::span p_data_in, - hal::function_ref p_timeout) override; - - hal::i2c* m_i2c; - hertz m_lowest_seen_frequency; -}; -} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_accelerometer.hpp b/include/libhal-util/inert_drivers/inert_accelerometer.hpp new file mode 100644 index 0000000..d8b1b02 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_accelerometer.hpp @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of acceleration sensing hardware + * + */ +class inert_accelerometer : public hal::accelerometer +{ +public: + /** + * @brief Create inert_accelerometer object + * + * @param p_values - what will be returned from the read function. + */ + constexpr inert_accelerometer(read_t p_values) + : m_values(p_values) + { + } + +private: + read_t driver_read() + { + return m_values; + } + + read_t m_values; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_adc.hpp b/include/libhal-util/inert_drivers/inert_adc.hpp new file mode 100644 index 0000000..97b4e80 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_adc.hpp @@ -0,0 +1,48 @@ +// 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. + +#pragma once + +#include + +#include + +namespace hal { +/** + * @brief Inert implementation of Analog to Digital Converter (ADC) hardware + * + */ +class inert_adc : public hal::adc +{ +public: + /** + * @brief Create inert_adc object + * + * @param p_result - What will be returned from inert_adc's read function, + * clamped to -1.0f to 1.0f. + */ + constexpr inert_adc(float p_result) + : m_result(std::clamp(p_result, -1.0f, 1.0f)) + { + } + +private: + float driver_read() + { + return m_result; + } + + float m_result; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_dac.hpp b/include/libhal-util/inert_drivers/inert_dac.hpp new file mode 100644 index 0000000..afd5642 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_dac.hpp @@ -0,0 +1,39 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of Digital to Analog Converter (DAC) hardware + * + */ +class inert_dac : public hal::dac +{ +public: + /** + * @brief Create inert_dac object + */ + constexpr inert_dac() + { + } + +private: + void driver_write(float) + { + } +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_distance_sensor.hpp b/include/libhal-util/inert_drivers/inert_distance_sensor.hpp new file mode 100644 index 0000000..da8e8bf --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_distance_sensor.hpp @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of linear distance hardware + * + */ +class inert_distance_sensor : public hal::distance_sensor +{ +public: + /** + * @brief Create inert_distance_sensor object + * + * @param p_result - what will be returned from the read function. + */ + constexpr inert_distance_sensor(hal::meters p_result) + : m_result(p_result) + { + } + +private: + hal::meters driver_read() + { + return m_result; + } + + hal::meters m_result; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_gyroscope.hpp b/include/libhal-util/inert_drivers/inert_gyroscope.hpp new file mode 100644 index 0000000..9af4eb6 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_gyroscope.hpp @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of angular velocity sensing hardware + * + */ +class inert_gyroscope : public hal::gyroscope +{ +public: + /** + * @brief Create inert_gyroscope object + * + * @param p_result - what will be returned from the read function. + */ + constexpr inert_gyroscope(read_t p_result) + : m_result(p_result) + { + } + +private: + read_t driver_read() + { + return m_result; + } + + read_t m_result; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_input_pin.hpp b/include/libhal-util/inert_drivers/inert_input_pin.hpp new file mode 100644 index 0000000..e9e4357 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_input_pin.hpp @@ -0,0 +1,49 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of digital input pin hardware + * + */ +class inert_input_pin : public hal::input_pin +{ +public: + /** + * @brief Create inert_input_pin object + * + * @param p_level - what will be returned from the level function. + */ + constexpr inert_input_pin(bool p_level) + : m_level(p_level) + { + } + +private: + void driver_configure([[maybe_unused]] settings const& p_settings) + { + } + + bool driver_level() + { + return m_level; + } + + bool m_level; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_interrupt_pin.hpp b/include/libhal-util/inert_drivers/inert_interrupt_pin.hpp new file mode 100644 index 0000000..8c0e36a --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_interrupt_pin.hpp @@ -0,0 +1,42 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of digital interrupt pin hardware + * + */ +class inert_interrupt_pin : public hal::interrupt_pin +{ +public: + /** + * @brief Create inert_interrupt_pin object + */ + constexpr inert_interrupt_pin() + { + } + +private: + void driver_configure([[maybe_unused]] settings const& p_settings) + { + } + void driver_on_trigger([[maybe_unused]] hal::callback p_callback) + { + } +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_magnetometer.hpp b/include/libhal-util/inert_drivers/inert_magnetometer.hpp new file mode 100644 index 0000000..3fcaf69 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_magnetometer.hpp @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of magnetic field strength sensing hardware + * + */ +class inert_magnetometer : public hal::magnetometer +{ +public: + /** + * @brief Create an inert_magnetometer object + * + * @param p_result - what will be returned from the read function. + */ + constexpr inert_magnetometer(read_t p_result) + : m_result(p_result) + { + } + +private: + read_t driver_read() + { + return m_result; + } + + read_t m_result; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_motor.hpp b/include/libhal-util/inert_drivers/inert_motor.hpp new file mode 100644 index 0000000..da0ed56 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_motor.hpp @@ -0,0 +1,40 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of open loop motorized actuator hardware + * + */ +class inert_motor : public hal::motor +{ +public: + /** + * @brief Create inert_motor object + * + */ + constexpr inert_motor() + { + } + +private: + void driver_power([[maybe_unused]] float p_power) + { + } +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_output_pin.hpp b/include/libhal-util/inert_drivers/inert_output_pin.hpp new file mode 100644 index 0000000..03e12b1 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_output_pin.hpp @@ -0,0 +1,73 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of digital output pin hardware + * + */ +class inert_output_pin : public hal::output_pin +{ +public: + /** + * @brief Create inert_output_pin + * + * @param p_level - level_t object to return when level() is called. This + * value can be changed by using level(bool) after creation. + */ + constexpr inert_output_pin(bool p_level) + : m_level(p_level) + { + } + +private: + void driver_configure([[maybe_unused]] settings const& p_settings) + { + } + void driver_level(bool p_high) + { + m_level = p_high; + } + + bool driver_level() + { + return m_level; + } + + bool m_level; +}; + +/** + * @brief Returns a default inert output pin for use as a default parameter + * + * Consider a driver that can accept an output pin but normally doesn't need to + * use it, this paramater can be used as a default parameters. For example, a + * driver that can optionally light up a status LED during activity. Rather than + * use std::optional which would add an additional branch at all unique call + * sites for the output pin, adding to code size, this driver can be used as a + * substitute. + * + * @return hal::output_pin& - reference to a single default inert output pin. + * All calls to this function return the same output pin. + */ +inline hal::output_pin& default_inert_output_pin() +{ + static inert_output_pin _default_inert_output_pin(false); + return _default_inert_output_pin; +} +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_pwm.hpp b/include/libhal-util/inert_drivers/inert_pwm.hpp new file mode 100644 index 0000000..93af93c --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_pwm.hpp @@ -0,0 +1,43 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of Pulse Width Modulation (PWM) channel hardware + * + */ +class inert_pwm : public hal::pwm +{ +public: + /** + * @brief Create inert_pwm object + * + */ + constexpr inert_pwm() + { + } + +private: + void driver_frequency([[maybe_unused]] hertz p_frequency) + { + } + void driver_duty_cycle([[maybe_unused]] float p_duty_cycle) + { + } +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_rotation_sensor.hpp b/include/libhal-util/inert_drivers/inert_rotation_sensor.hpp new file mode 100644 index 0000000..e51c633 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_rotation_sensor.hpp @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of rotation measuring hardware + * + */ +class inert_rotation_sensor : public hal::rotation_sensor +{ +public: + /** + * @brief Create inert_rotation_sensor object + * + * @param p_position - what will be returned from the read function. + */ + constexpr inert_rotation_sensor(read_t p_position) + : m_position(p_position) + { + } + +private: + read_t driver_read() + { + return m_position; + } + + read_t m_position; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_steady_clock.hpp b/include/libhal-util/inert_drivers/inert_steady_clock.hpp new file mode 100644 index 0000000..751a051 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_steady_clock.hpp @@ -0,0 +1,55 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of steady clock mechanism + * + */ +class inert_steady_clock : public hal::steady_clock +{ +public: + /** + * @brief Create inert_steady_clock object + * + * @param p_frequency - what will be returned from the frequency function. + * @param p_uptime - the starting value that will be returned when uptime() is + * called. The uptime will increment by 1 each time uptime() is called. + */ + constexpr inert_steady_clock(hal::hertz p_frequency, std::uint64_t p_uptime) + : m_frequency(p_frequency) + , m_uptime(p_uptime) + { + } + +private: + hal::hertz driver_frequency() + { + return m_frequency; + } + + std::uint64_t driver_uptime() + { + m_uptime++; + return m_uptime; + } + + hal::hertz m_frequency; + std::uint64_t m_uptime; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_temperature_sensor.hpp b/include/libhal-util/inert_drivers/inert_temperature_sensor.hpp new file mode 100644 index 0000000..6ee8350 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_temperature_sensor.hpp @@ -0,0 +1,45 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of temperature sensing hardware + * + */ +class inert_temperature_sensor : public hal::temperature_sensor +{ +public: + /** + * @brief Create inert_temperature_sensor object + * + * @param p_temperature - hal::celsius object to return when read() is called + */ + constexpr inert_temperature_sensor(hal::celsius p_temperature) + : m_temperature(p_temperature) + { + } + +private: + hal::celsius driver_read() + { + return m_temperature; + } + + hal::celsius m_temperature; +}; +} // namespace hal diff --git a/include/libhal-util/inert_drivers/inert_timer.hpp b/include/libhal-util/inert_drivers/inert_timer.hpp new file mode 100644 index 0000000..d1096a5 --- /dev/null +++ b/include/libhal-util/inert_drivers/inert_timer.hpp @@ -0,0 +1,53 @@ +// 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. + +#pragma once + +#include + +namespace hal { +/** + * @brief Inert implementation of timer hardware + * + */ +class inert_timer : public hal::timer +{ +public: + /** + * @brief Create inert_timer object + * + * @param p_is_running - what will be returned from the is_running function. + */ + constexpr inert_timer(bool p_is_running) + : m_is_running(p_is_running) + { + } + +private: + bool driver_is_running() + { + return m_is_running; + } + + void driver_cancel() + { + } + void driver_schedule([[maybe_unused]] hal::callback p_callback, + [[maybe_unused]] hal::time_duration p_delay) + { + } + + bool m_is_running; +}; +} // namespace hal diff --git a/include/libhal-util/input_pin.hpp b/include/libhal-util/input_pin.hpp index d808717..d7152b6 100644 --- a/include/libhal-util/input_pin.hpp +++ b/include/libhal-util/input_pin.hpp @@ -21,17 +21,5 @@ * */ namespace hal { -/** - * @ingroup InputPin - * @brief Compares two input pin states - * - * @param p_lhs An input pin - * @param p_rhs An input pin - * @return A boolean if they are the same or not. - */ -[[nodiscard]] constexpr auto operator==(input_pin::settings const& p_lhs, - input_pin::settings const& p_rhs) -{ - return p_lhs.resistor == p_rhs.resistor; -} +// Nothing yet } // namespace hal diff --git a/include/libhal-util/interrupt_pin.hpp b/include/libhal-util/interrupt_pin.hpp index b69f518..18f651e 100644 --- a/include/libhal-util/interrupt_pin.hpp +++ b/include/libhal-util/interrupt_pin.hpp @@ -21,18 +21,5 @@ * */ namespace hal { -/** - * @ingroup InterruptPin - * @brief Compares two interrupt pin states, compares both their trigger and - * resistor. - * - * @param p_lhs An interrupt pin - * @param p_rhs An interrupt pin - * @return A boolean if they are the same or not. - */ -[[nodiscard]] constexpr auto operator==(interrupt_pin::settings const& p_lhs, - interrupt_pin::settings const& p_rhs) -{ - return p_lhs.resistor == p_rhs.resistor && p_lhs.trigger == p_rhs.trigger; -} +// Nothing yet } // namespace hal diff --git a/include/libhal-util/output_pin.hpp b/include/libhal-util/output_pin.hpp index 5cd49bf..5cd2467 100644 --- a/include/libhal-util/output_pin.hpp +++ b/include/libhal-util/output_pin.hpp @@ -22,18 +22,5 @@ */ namespace hal { -/** - * @ingroup OutputPin - * @brief Compares two output pin states, compares both resistor and open drain. - * - * @param p_lhs An output pin - * @param p_rhs An output pin - * @return A boolean if they are the same or not. - */ -[[nodiscard]] constexpr auto operator==(output_pin::settings const& p_lhs, - output_pin::settings const& p_rhs) -{ - return p_lhs.resistor == p_rhs.resistor && - p_lhs.open_drain == p_rhs.open_drain; -} +// Nothing yet } // namespace hal diff --git a/tests/inert_drivers/inert_accelerometer.test.cpp b/tests/inert_drivers/inert_accelerometer.test.cpp new file mode 100644 index 0000000..4e65a38 --- /dev/null +++ b/tests/inert_drivers/inert_accelerometer.test.cpp @@ -0,0 +1,36 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_accelerometer_test = []() { + using namespace boost::ut; + "inert_accelerometer"_test = []() { + // Setup + constexpr auto expected = accelerometer::read_t{ 0.1f, 0.2f, 0.3f }; + inert_accelerometer test(expected); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected.x == result.x); + expect(that % expected.y == result.y); + expect(that % expected.z == result.z); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_adc.test.cpp b/tests/inert_drivers/inert_adc.test.cpp new file mode 100644 index 0000000..2c4918a --- /dev/null +++ b/tests/inert_drivers/inert_adc.test.cpp @@ -0,0 +1,34 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_adc_test = []() { + using namespace boost::ut; + "inert_adc"_test = []() { + // Setup + constexpr auto expected = 0.5f; + inert_adc test(expected); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected == result); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_dac.test.cpp b/tests/inert_drivers/inert_dac.test.cpp new file mode 100644 index 0000000..fceb51a --- /dev/null +++ b/tests/inert_drivers/inert_dac.test.cpp @@ -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 + +#include + +namespace hal { +boost::ut::suite inert_dac_test = []() { + using namespace boost::ut; + "inert_dac"_test = []() { + // Setup + inert_dac test; + + // Exercise + // Verify + test.write(0.1f); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_distance_sensor.test.cpp b/tests/inert_drivers/inert_distance_sensor.test.cpp new file mode 100644 index 0000000..d1fde17 --- /dev/null +++ b/tests/inert_drivers/inert_distance_sensor.test.cpp @@ -0,0 +1,34 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_distance_sensor_test = []() { + using namespace boost::ut; + "inert_distance_sensor"_test = []() { + // Setup + constexpr hal::meters expected_read = 0.1f; + inert_distance_sensor test(expected_read); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected_read == result); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_gyroscope.test.cpp b/tests/inert_drivers/inert_gyroscope.test.cpp new file mode 100644 index 0000000..8745e72 --- /dev/null +++ b/tests/inert_drivers/inert_gyroscope.test.cpp @@ -0,0 +1,36 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_gyroscope_test = []() { + using namespace boost::ut; + "inert_gyroscope"_test = []() { + // Setup + constexpr auto expected_read = gyroscope::read_t{ 0.1f, 0.2f, 0.3f }; + inert_gyroscope test(expected_read); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected_read.x == result.x); + expect(that % expected_read.y == result.y); + expect(that % expected_read.z == result.z); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_input_pin.test.cpp b/tests/inert_drivers/inert_input_pin.test.cpp new file mode 100644 index 0000000..34eeb8e --- /dev/null +++ b/tests/inert_drivers/inert_input_pin.test.cpp @@ -0,0 +1,40 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_input_pin_test = []() { + using namespace boost::ut; + "inert_input_pin"_test = []() { + // Setup + auto level_true = true; + auto level_false = false; + auto configure_settings = input_pin::settings{}; + inert_input_pin test1(level_true); + inert_input_pin test2(level_false); + + // Exercise + test1.configure(configure_settings); + auto level_high_result = test1.level(); + auto level_low_result = test2.level(); + + // Verify + expect(that % true == level_high_result); + expect(that % false == level_low_result); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_interrupt_pin.test.cpp b/tests/inert_drivers/inert_interrupt_pin.test.cpp new file mode 100644 index 0000000..7af4620 --- /dev/null +++ b/tests/inert_drivers/inert_interrupt_pin.test.cpp @@ -0,0 +1,32 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_interrupt_pin_test = []() { + using namespace boost::ut; + "inert_interrupt_pin"_test = []() { + // Setup + auto configure_settings = interrupt_pin::settings{}; + inert_interrupt_pin test; + + // Exercise + // Verify + test.configure(configure_settings); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_magnetometer.test.cpp b/tests/inert_drivers/inert_magnetometer.test.cpp new file mode 100644 index 0000000..d41003a --- /dev/null +++ b/tests/inert_drivers/inert_magnetometer.test.cpp @@ -0,0 +1,36 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_magnetometer_test = []() { + using namespace boost::ut; + "inert_magnetometer"_test = []() { + // Setup + constexpr auto expected_read = magnetometer::read_t{ 0.1f, 0.2f, 0.3f }; + inert_magnetometer test(expected_read); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected_read.x == result.x); + expect(that % expected_read.y == result.y); + expect(that % expected_read.z == result.z); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_motor.test.cpp b/tests/inert_drivers/inert_motor.test.cpp new file mode 100644 index 0000000..0705607 --- /dev/null +++ b/tests/inert_drivers/inert_motor.test.cpp @@ -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 + +#include + +namespace hal { +boost::ut::suite inert_motor_test = []() { + using namespace boost::ut; + "inert_motor"_test = []() { + // Setup + inert_motor test; + + // Exercise + // Verify + test.power(0.1f); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_output_pin.test.cpp b/tests/inert_drivers/inert_output_pin.test.cpp new file mode 100644 index 0000000..9f447fa --- /dev/null +++ b/tests/inert_drivers/inert_output_pin.test.cpp @@ -0,0 +1,52 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_output_pin_test = []() { + using namespace boost::ut; + "inert_output_pin"_test = []() { + // Setup + inert_output_pin test(false); + + // Exercise + test.level(true); + auto get_level_high_result = test.level(); + test.level(false); + auto get_level_low_result = test.level(); + + // Verify + expect(that % true == get_level_high_result); + expect(that % false == get_level_low_result); + }; + + "default_inert_output_pin"_test = []() { + // Setup + hal::output_pin& test = hal::default_inert_output_pin(); + + // Exercise + test.level(true); + auto get_level_high_result = test.level(); + test.level(false); + auto get_level_low_result = test.level(); + + // Verify + expect(that % true == get_level_high_result); + expect(that % false == get_level_low_result); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_pwm.test.cpp b/tests/inert_drivers/inert_pwm.test.cpp new file mode 100644 index 0000000..07be11c --- /dev/null +++ b/tests/inert_drivers/inert_pwm.test.cpp @@ -0,0 +1,32 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_pwm_test = []() { + using namespace boost::ut; + "inert_pwm"_test = []() { + // Setup + inert_pwm test; + + // Exercise + // Verify + test.frequency(0.1f); + test.duty_cycle(0.1f); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_rotation_sensor.test.cpp b/tests/inert_drivers/inert_rotation_sensor.test.cpp new file mode 100644 index 0000000..f048e0c --- /dev/null +++ b/tests/inert_drivers/inert_rotation_sensor.test.cpp @@ -0,0 +1,34 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_rotation_sensor_test = []() { + using namespace boost::ut; + "inert_rotation_sensor"_test = []() { + // Setup + constexpr auto expected_read = rotation_sensor::read_t{ 0.1f }; + inert_rotation_sensor test(expected_read); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected_read.angle == result.angle); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_steady_clock.test.cpp b/tests/inert_drivers/inert_steady_clock.test.cpp new file mode 100644 index 0000000..8bd9e69 --- /dev/null +++ b/tests/inert_drivers/inert_steady_clock.test.cpp @@ -0,0 +1,39 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_steady_clock_test = []() { + using namespace boost::ut; + "inert_steady_clock"_test = []() { + // Setup + constexpr hal::hertz expected_frequency = 0.5f; + constexpr std::uint64_t start_uptime = 99; + constexpr std::uint64_t expected_uptime = 100; + + inert_steady_clock test(expected_frequency, start_uptime); + + // Exercise + auto frequency_result = test.frequency(); + auto uptime_result = test.uptime(); + + // Verify + expect(that % expected_frequency == frequency_result); + expect(that % expected_uptime == uptime_result); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_temperature_sensor.test.cpp b/tests/inert_drivers/inert_temperature_sensor.test.cpp new file mode 100644 index 0000000..abeb5c1 --- /dev/null +++ b/tests/inert_drivers/inert_temperature_sensor.test.cpp @@ -0,0 +1,34 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_temperature_sensor_test = []() { + using namespace boost::ut; + "inert_temperature_sensor"_test = []() { + // Setup + constexpr hal::celsius expected_temp = 0.5f; + inert_temperature_sensor test(expected_temp); + + // Exercise + auto result = test.read(); + + // Verify + expect(that % expected_temp == result); + }; +}; +} // namespace hal diff --git a/tests/inert_drivers/inert_timer.test.cpp b/tests/inert_drivers/inert_timer.test.cpp new file mode 100644 index 0000000..0906170 --- /dev/null +++ b/tests/inert_drivers/inert_timer.test.cpp @@ -0,0 +1,42 @@ +// 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 + +#include + +namespace hal { +boost::ut::suite inert_timer_test = []() { + using namespace boost::ut; + "inert_timer"_test = []() { + // Setup + hal::callback const callback = []() {}; + hal::time_duration const delay = {}; + auto is_running = true; + auto is_not_running = false; + inert_timer test1(is_running); + inert_timer test2(is_not_running); + + // Exercise + auto is_running_result1 = test1.is_running(); + auto is_running_result2 = test2.is_running(); + test1.cancel(); + test1.schedule(callback, delay); + + // Verify + expect(that % true == is_running_result1); + expect(that % false == is_running_result2); + }; +}; +} // namespace hal diff --git a/tests/serial.test.cpp b/tests/serial.test.cpp index 5683e7b..f76b0da 100644 --- a/tests/serial.test.cpp +++ b/tests/serial.test.cpp @@ -206,7 +206,7 @@ void serial_util_test() expect(!serial.m_flush_called); expect(that % nullptr == serial.m_out.data()); expect(that % 0 == serial.m_out.size()); - expect(that % expected == actual) << expected << " != " << actual; + expect(that % expected == actual); }; "[failure read] read"_test = []() { @@ -241,7 +241,7 @@ void serial_util_test() expect(that % serial.m_read_was_called); expect(that % nullptr == serial.m_out.data()); expect(that % 0 == serial.m_out.size()); - expect(that % expected == actual) << expected << " != " << actual; + expect(that % expected == actual); }; "[failure read] read"_test = []() { @@ -277,8 +277,7 @@ void serial_util_test() expect(!serial.m_flush_called); expect(that % write_buffer.data() == serial.m_out.data()); expect(that % write_buffer.size() == serial.m_out.size()); - expect(that % expected_read == actual) - << expected_read << " != " << actual; + expect(that % expected_read == actual); }; "[failure read] write_then_read"_test = []() { @@ -337,8 +336,7 @@ void serial_util_test() expect(that % expected_write.data() == serial.m_out.data()); expect(that % expected_write.size() == serial.m_out.size()); expect(serial.m_read_was_called); - expect(that % expected_read == actual) - << expected_read << " != " << actual; + expect(that % expected_read == actual); }; "[failure on write] write_then_read"_test = []() {