From 89f403a5902670f48df581568c25aa8c8fb2e6d4 Mon Sep 17 00:00:00 2001 From: Khalil Estell Date: Mon, 7 Oct 2024 07:05:00 -0700 Subject: [PATCH] :art: Tidying up the code This code came in without a pull request and before some of the newer style guide requirements were added. --- .clang-format | 1 + .gitignore | 1 - demos/CMakeLists.txt | 5 +- demos/applications/gpio.cpp | 13 ++-- demos/applications/{i2c_test.cpp => i2c.cpp} | 2 +- demos/applications/uart.cpp | 31 ++++++---- demos/compile_commands 2.json | 62 -------------------- include/libhal-linux/errors.hpp | 19 +++++- include/libhal-linux/i2c.hpp | 17 +++++- include/libhal-linux/input_pin.hpp | 10 +--- include/libhal-linux/output_pin.hpp | 44 +++++++------- include/libhal-linux/serial.hpp | 21 +++++-- include/libhal-linux/steady_clock.hpp | 45 +++++++------- src/i2c.cpp | 31 +++++----- src/input_pin.cpp | 3 +- src/output_pin.cpp | 4 +- src/serial.cpp | 15 +++-- tests/main.test.cpp | 2 +- 18 files changed, 160 insertions(+), 166 deletions(-) rename demos/applications/{i2c_test.cpp => i2c.cpp} (96%) delete mode 100644 demos/compile_commands 2.json diff --git a/.clang-format b/.clang-format index b72f919..3fedce1 100644 --- a/.clang-format +++ b/.clang-format @@ -7,3 +7,4 @@ AllowShortFunctionsOnASingleLine: None FixNamespaceComments: true SpacesBeforeTrailingComments: 2 ColumnLimit: 80 +InsertNewlineAtEOF: true diff --git a/.gitignore b/.gitignore index aeab307..dce0395 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,3 @@ conanbuildinfo.txt # CMake CMakeUserPresets.json - diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt index 8c73ea9..04694c2 100644 --- a/demos/CMakeLists.txt +++ b/demos/CMakeLists.txt @@ -26,15 +26,14 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # ${CMAKE_SOURCE_DIR}/compile_commands.json # DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json) - find_package(libhal-linux REQUIRED CONFIG) -set(DEMOS gpio blinker i2c_test uart steady_clock_test) +set(DEMOS gpio blinker i2c uart steady_clock_test) foreach(DEMO ${DEMOS}) message(STATUS "Generating Demo for \"${PROJECT_NAME}_${DEMO}") add_executable(${PROJECT_NAME}_${DEMO} main.cpp applications/${DEMO}.cpp) target_include_directories(${PROJECT_NAME}_${DEMO} PUBLIC .) target_compile_features(${PROJECT_NAME}_${DEMO} PRIVATE cxx_std_23) target_link_libraries(${PROJECT_NAME}_${DEMO} PRIVATE libhal::linux -static-libstdc++) - + endforeach() diff --git a/demos/applications/gpio.cpp b/demos/applications/gpio.cpp index 41ad915..d88f73f 100644 --- a/demos/applications/gpio.cpp +++ b/demos/applications/gpio.cpp @@ -12,27 +12,32 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include + #include #include #include -#include void application() { auto output_gpio = hal::gnu_linux::output_pin("/dev/gpiochip0", 2); auto input_gpio = hal::gnu_linux::input_pin("/dev/gpiochip0", 3); + std::cout << "blinking gpio 2 on gpiochip0\n"; + bool state = output_gpio.level(); bool saved_state = false; + while (true) { output_gpio.level(state); saved_state = output_gpio.level(); - std::cout << "current state: " << saved_state << std::endl; + std::cout << "current state: " << saved_state << "\n"; sleep(1); state ^= 1; - if (!input_gpio.level()) { - std::cout << "quiting, bye bye\n"; + if (not input_gpio.level()) { + std::cout << "quitting, bye bye\n"; break; } } diff --git a/demos/applications/i2c_test.cpp b/demos/applications/i2c.cpp similarity index 96% rename from demos/applications/i2c_test.cpp rename to demos/applications/i2c.cpp index 6879d79..1c5b414 100644 --- a/demos/applications/i2c_test.cpp +++ b/demos/applications/i2c.cpp @@ -38,7 +38,7 @@ void application() const auto addr = 0x68; const auto wake_sensor = std::array{ 0x6B, 0 }; hal::write(bus, addr, wake_sensor); - const auto set_scale = std::array{ 0xC1, 1 }; + while (true) { auto read_buffer = std::array{}; auto write_op = std::array{ 0x3B }; diff --git a/demos/applications/uart.cpp b/demos/applications/uart.cpp index d80c7e0..a1e8a60 100644 --- a/demos/applications/uart.cpp +++ b/demos/applications/uart.cpp @@ -1,29 +1,40 @@ +#include + #include +#include +#include + #include #include -#include -#include void application() { std::cout << "UART test\n"; - auto serial_file_path = "/dev/serial0"; + constexpr auto serial_file_path = "/dev/serial0"; auto serial_bus = hal::gnu_linux::serial(serial_file_path); - std::string test_str = "Hello from libhal\n"; + std::string_view const test_str = "Hello from libhal\n"; std::array input_buffer = { 0 }; + while (true) { hal::print(serial_bus, test_str); + sleep(1); - auto read_res = serial_bus.read(input_buffer); - if (input_buffer.at(0) == '\0') { + + auto const received_data = serial_bus.read(input_buffer); + + if (received_data.data.empty()) { std::cout << "Nothing to read\n"; continue; } - std::cout << "Len of res buffer: " << read_res.data.size() + + std::cout << "Len of res buffer: " << received_data.data.size() << " len of input buffer: " << input_buffer.size() << "\n"; - auto subspan = read_res.data.subspan(0, read_res.data.size()); - auto read_string = std::string(subspan.begin(), subspan.end()); + auto const read_string = + std::string_view(reinterpret_cast(received_data.data.data()), + received_data.data.size()); + sleep(1); - std::cout << "Read from serial:" << read_string; + + std::cout << "Read from serial: " << read_string << "\n"; } } \ No newline at end of file diff --git a/demos/compile_commands 2.json b/demos/compile_commands 2.json deleted file mode 100644 index 39fe9a8..0000000 --- a/demos/compile_commands 2.json +++ /dev/null @@ -1,62 +0,0 @@ -[ -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_gpio.dir/main.cpp.o -c /code/demos/main.cpp", - "file": "/code/demos/main.cpp", - "output": "CMakeFiles/linux_demos_gpio.dir/main.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_gpio.dir/applications/gpio.cpp.o -c /code/demos/applications/gpio.cpp", - "file": "/code/demos/applications/gpio.cpp", - "output": "CMakeFiles/linux_demos_gpio.dir/applications/gpio.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_blinker.dir/main.cpp.o -c /code/demos/main.cpp", - "file": "/code/demos/main.cpp", - "output": "CMakeFiles/linux_demos_blinker.dir/main.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_blinker.dir/applications/blinker.cpp.o -c /code/demos/applications/blinker.cpp", - "file": "/code/demos/applications/blinker.cpp", - "output": "CMakeFiles/linux_demos_blinker.dir/applications/blinker.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_i2c_test.dir/main.cpp.o -c /code/demos/main.cpp", - "file": "/code/demos/main.cpp", - "output": "CMakeFiles/linux_demos_i2c_test.dir/main.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_i2c_test.dir/applications/i2c_test.cpp.o -c /code/demos/applications/i2c_test.cpp", - "file": "/code/demos/applications/i2c_test.cpp", - "output": "CMakeFiles/linux_demos_i2c_test.dir/applications/i2c_test.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_uart.dir/main.cpp.o -c /code/demos/main.cpp", - "file": "/code/demos/main.cpp", - "output": "CMakeFiles/linux_demos_uart.dir/main.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_uart.dir/applications/uart.cpp.o -c /code/demos/applications/uart.cpp", - "file": "/code/demos/applications/uart.cpp", - "output": "CMakeFiles/linux_demos_uart.dir/applications/uart.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_steady_clock_test.dir/main.cpp.o -c /code/demos/main.cpp", - "file": "/code/demos/main.cpp", - "output": "CMakeFiles/linux_demos_steady_clock_test.dir/main.cpp.o" -}, -{ - "directory": "/code/demos/build/unspecified/Release", - "command": "/usr/bin/clang++-17 -I/code/demos/. -isystem /root/.conan2/p/b/libhaf431e523fb55f/p/include -isystem /root/.conan2/p/b/libhac2ef268c2495b/p/include -isystem /root/.conan2/p/libha6f1566c3082ef/p/include -isystem /root/.conan2/p/tl-fu31454aa876889/p/include -stdlib=libc++ -O3 -DNDEBUG -std=c++23 -o CMakeFiles/linux_demos_steady_clock_test.dir/applications/steady_clock_test.cpp.o -c /code/demos/applications/steady_clock_test.cpp", - "file": "/code/demos/applications/steady_clock_test.cpp", - "output": "CMakeFiles/linux_demos_steady_clock_test.dir/applications/steady_clock_test.cpp.o" -} -] \ No newline at end of file diff --git a/include/libhal-linux/errors.hpp b/include/libhal-linux/errors.hpp index 3d62b6a..e706647 100644 --- a/include/libhal-linux/errors.hpp +++ b/include/libhal-linux/errors.hpp @@ -1,7 +1,20 @@ +// 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 -// This is to be internal, will be in the precompiled shared object namespace hal::gnu_linux { struct errno_exception : public hal::exception @@ -29,4 +42,4 @@ struct invalid_character_device : public errno_exception std::string invalid_device_path; }; -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/include/libhal-linux/i2c.hpp b/include/libhal-linux/i2c.hpp index f04d41b..e33f89d 100644 --- a/include/libhal-linux/i2c.hpp +++ b/include/libhal-linux/i2c.hpp @@ -1,7 +1,20 @@ +// 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::gnu_linux { class i2c : public hal::i2c @@ -28,4 +41,4 @@ class i2c : public hal::i2c int m_fd = 0; }; -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/include/libhal-linux/input_pin.hpp b/include/libhal-linux/input_pin.hpp index 779622e..51e11ab 100644 --- a/include/libhal-linux/input_pin.hpp +++ b/include/libhal-linux/input_pin.hpp @@ -1,17 +1,13 @@ #pragma once -#include +#include + #include #include -#include -#include -#include -#include namespace { typedef struct gpio_v2_line_request gpio_line_request; typedef struct gpio_v2_line_values gpio_values; - } // namespace namespace hal::gnu_linux { @@ -45,4 +41,4 @@ class input_pin : public hal::input_pin gpio_line_request m_line_request; gpio_values m_values; }; -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/include/libhal-linux/output_pin.hpp b/include/libhal-linux/output_pin.hpp index d6cd6af..d0f1a14 100644 --- a/include/libhal-linux/output_pin.hpp +++ b/include/libhal-linux/output_pin.hpp @@ -1,23 +1,26 @@ +// 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 + #include #include #include -#include -#include -#include -#include - -namespace { -typedef struct gpio_v2_line_request gpio_line_request; -typedef struct gpio_v2_line_values gpio_values; -typedef struct gpio_v2_line_config gpio_config; - -} // namespace namespace hal::gnu_linux { - /** * @brief Output pin for the linux kernel. Wraps libgpiod 2.1 at the earlist. * Assumes a GPIO driver exists and is properly written for the specific @@ -27,10 +30,11 @@ class output_pin : public hal::output_pin { public: /** - * @brief Constructor. Takes a *full path* to the GPIO character device and a - * numeber that is known to said device. - * @param p_chip_name Full path to GPIO character device. - * @param p_pin Pin number for said device + * @brief Takes a *full path* to the GPIO character device and a number that + * is known to said device. + * + * @param p_chip_name - Full path to GPIO character device. + * @param p_pin - Pin number for said device * * @throws std::invalid_argument if an invalid chip path was given, an invalid * pin number was given, or if a request to said line failed. @@ -45,7 +49,7 @@ class output_pin : public hal::output_pin bool driver_level() override; int m_chip_fd = -1; - gpio_line_request m_line_request; - gpio_values m_values; + gpio_v2_line_request m_line_request; + gpio_v2_line_values m_values; }; -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/include/libhal-linux/serial.hpp b/include/libhal-linux/serial.hpp index de3e14e..0aea22f 100644 --- a/include/libhal-linux/serial.hpp +++ b/include/libhal-linux/serial.hpp @@ -1,11 +1,25 @@ +// 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 +#include + namespace hal::gnu_linux { class serial : public hal::serial { - public: serial(const std::string& p_file_path, settings p_settings = {}); virtual ~serial(); @@ -18,5 +32,4 @@ class serial : public hal::serial int m_fd = 0; }; - -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/include/libhal-linux/steady_clock.hpp b/include/libhal-linux/steady_clock.hpp index 721eb3f..ab5c59d 100644 --- a/include/libhal-linux/steady_clock.hpp +++ b/include/libhal-linux/steady_clock.hpp @@ -1,45 +1,50 @@ +// 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 -#include -#include + +#include #include #include +#include +#include + namespace hal::gnu_linux { template -concept Clock = requires -{ - { - T::now() - } -> std::convertible_to>; - +concept Clock = requires { + { T::now() } -> std::convertible_to>; std::is_integral_v; - std::is_same_v>; std::is_same_v>; std::is_same_v>; - { - T::is_steady - } -> std::convertible_to; + { T::is_steady } -> std::convertible_to; }; template class steady_clock : public hal::steady_clock { public: - steady_clock() - { - // Question from Khalil: why is this here? - std::chrono::time_point res = C::now(); - } + steady_clock() = default; private: std::uint64_t driver_uptime() override { - return static_cast(C::now().time_since_epoch().count()); } hertz driver_frequency() override @@ -50,4 +55,4 @@ class steady_clock : public hal::steady_clock } }; -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/src/i2c.cpp b/src/i2c.cpp index 3aef012..bc1cc24 100644 --- a/src/i2c.cpp +++ b/src/i2c.cpp @@ -1,12 +1,15 @@ -#include #include + #include -#include #include #include #include #include +#include + +#include + #include namespace { @@ -57,57 +60,51 @@ void i2c::driver_transaction( } else { real_address = p_address; } + // Enable 10 bit mode if set if (ioctl(m_fd, I2C_TENBIT, is_ten_bit) < 0) { - throw hal::operation_not_supported(this); } // Set peripheral address if (ioctl(m_fd, I2C_SLAVE, real_address) < 0) { - throw hal::no_such_device(real_address, this); } const bool is_reading = p_data_out.empty(); - const bool write_then_read = - &p_data_out.data()[0] != nullptr && &p_data_in.data()[0] != nullptr; + const bool write_then_read = not p_data_out.empty() && not p_data_in.empty(); if (write_then_read) { i2c_rdwr_ioctl_data data_queue; - std::array msgs; + std::array msgs{}; // First, the message thats to be written msgs[0].addr = real_address; - msgs[0].buf = (__u8*)(&p_data_out.data()[0]); + msgs[0].buf = reinterpret_cast<__u8*>(p_data_out.data()); msgs[0].flags = 0; msgs[0].len = p_data_out.size(); // Next, the message thats to be read msgs[1].addr = real_address; - msgs[1].buf = (__u8*)(&p_data_in.data()[0]); + msgs[1].buf = reinterpret_cast<__u8*>(p_data_in.data()); msgs[1].flags = I2C_M_RD; msgs[1].len = p_data_in.size(); data_queue.nmsgs = 2; - data_queue.msgs = &msgs[0]; + data_queue.msgs = msgs.data(); if (ioctl(m_fd, I2C_RDWR, &data_queue) < 0) { - throw hal::operation_not_permitted(this); } return; } if (is_reading) { - if (linux_read(m_fd, &p_data_in.data()[0], p_data_in.size()) == -1) { - + if (linux_read(m_fd, p_data_in.data(), p_data_in.size()) == -1) { throw hal::operation_not_permitted(this); } } else { - if (linux_write(m_fd, &p_data_out.data()[0], p_data_out.size()) == -1) { - + if (linux_write(m_fd, p_data_out.data(), p_data_out.size()) == -1) { throw hal::operation_not_permitted(this); } } } - -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/src/input_pin.cpp b/src/input_pin.cpp index 505bdf8..cd0387c 100644 --- a/src/input_pin.cpp +++ b/src/input_pin.cpp @@ -32,6 +32,7 @@ bool input_pin::driver_level() perror("driver_level input read"); throw hal::io_error(this); } + return static_cast(m_values.bits & m_values.mask); } @@ -58,4 +59,4 @@ void input_pin::driver_configure(const settings& p_settings) } } -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/src/output_pin.cpp b/src/output_pin.cpp index dd6157e..d098d19 100644 --- a/src/output_pin.cpp +++ b/src/output_pin.cpp @@ -14,12 +14,12 @@ #include #include +#include namespace hal::gnu_linux { output_pin::output_pin(const std::string& p_chip_name, const std::uint16_t p_pin) - { m_chip_fd = open(p_chip_name.c_str(), O_RDONLY); if (m_chip_fd < 0) { @@ -66,7 +66,7 @@ void output_pin::driver_configure(const settings& p_settings) GPIO_V2_LINE_SET_CONFIG_IOCTL, &m_line_request.config) < 0) { perror("Failed to configured"); - throw hal::operation_not_permitted(this); + throw hal::operation_not_supported(this); } } diff --git a/src/serial.cpp b/src/serial.cpp index a474eaf..d92691e 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -1,16 +1,16 @@ -#include -#include -// Internal includes TODO: move to source #include #include -#include -#include +#include #include #include #include +#include + +#include +#include #include #include @@ -157,7 +157,7 @@ void serial::driver_configure(const settings& p_settings) internal_baud = B2000000; break; default: - throw hal::argument_out_of_domain(this); + throw hal::operation_not_supported(this); } control_flags |= internal_baud; @@ -204,5 +204,4 @@ void serial::driver_flush() } tcflush(m_fd, TCIFLUSH); // Flushes both TX and RX } - -} // namespace hal::gnu_linux \ No newline at end of file +} // namespace hal::gnu_linux diff --git a/tests/main.test.cpp b/tests/main.test.cpp index b93f7cd..aa39724 100644 --- a/tests/main.test.cpp +++ b/tests/main.test.cpp @@ -19,4 +19,4 @@ extern void output_pin_test(); int main() { hal::gnu_linux::output_pin_test(); -} \ No newline at end of file +}