| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | /** |
| 5 | * @file request-config.hpp |
| 6 | */ |
| 7 | |
| 8 | #ifndef __LIBGPIOD_CXX_LINE_SETTINGS_HPP__ |
| 9 | #define __LIBGPIOD_CXX_LINE_SETTINGS_HPP__ |
| 10 | |
| 11 | #if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__) |
| 12 | #error "Only gpiod.hpp can be included directly." |
| 13 | #endif |
| 14 | |
| 15 | #include <chrono> |
| 16 | #include <memory> |
| 17 | |
| 18 | #include "line.hpp" |
| 19 | |
| 20 | namespace gpiod { |
| 21 | |
| 22 | class line_config; |
| 23 | |
| 24 | /** |
| 25 | * @brief Stores GPIO line settings. |
| 26 | */ |
| 27 | class line_settings final |
| 28 | { |
| 29 | public: |
| 30 | |
| 31 | /** |
| 32 | * @brief Initializes the line_settings object with default values. |
| 33 | */ |
| 34 | line_settings(); |
| 35 | |
| 36 | /** |
| 37 | * @brief Copy constructor. |
| 38 | * @param other Object to copy. |
| 39 | */ |
| 40 | line_settings(const line_settings& other); |
| 41 | |
| 42 | /** |
| 43 | * @brief Move constructor. |
| 44 | * @param other Object to move. |
| 45 | */ |
| 46 | line_settings(line_settings&& other) noexcept; |
| 47 | |
| 48 | ~line_settings(); |
| 49 | |
| 50 | /** |
| 51 | * @brief Copy assignment operator. |
| 52 | * @param other Object to copy. |
| 53 | * @return Reference to self. |
| 54 | */ |
| 55 | line_settings& operator=(const line_settings& other); |
| 56 | |
| 57 | /** |
| 58 | * @brief Move assignment operator. |
| 59 | * @param other Object to move. |
| 60 | * @return Reference to self. |
| 61 | */ |
| 62 | line_settings& operator=(line_settings&& other); |
| 63 | |
| 64 | /** |
| 65 | * @brief Reset the line settings to default values. |
| 66 | * @return Reference to self. |
| 67 | */ |
| 68 | line_settings& reset() noexcept; |
| 69 | |
| 70 | /** |
| 71 | * @brief Set direction. |
| 72 | * @param direction New direction. |
| 73 | * @return Reference to self. |
| 74 | */ |
| 75 | line_settings& set_direction(line::direction direction); |
| 76 | |
| 77 | /** |
| 78 | * @brief Get direction. |
| 79 | * @return Current direction setting. |
| 80 | */ |
| 81 | line::direction direction() const; |
| 82 | |
| 83 | /** |
| 84 | * @brief Set edge detection. |
| 85 | * @param edge New edge detection setting. |
| 86 | * @return Reference to self. |
| 87 | */ |
| 88 | line_settings& set_edge_detection(line::edge edge); |
| 89 | |
| 90 | /** |
| 91 | * @brief Get edge detection. |
| 92 | * @return Current edge detection setting. |
| 93 | */ |
| 94 | line::edge edge_detection() const; |
| 95 | |
| 96 | /** |
| 97 | * @brief Set bias setting. |
| 98 | * @param bias New bias. |
| 99 | * @return Reference to self. |
| 100 | */ |
| 101 | line_settings& set_bias(line::bias bias); |
| 102 | |
| 103 | /** |
| 104 | * @brief Get bias setting. |
| 105 | * @return Current bias. |
| 106 | */ |
| 107 | line::bias bias() const; |
| 108 | |
| 109 | /** |
| 110 | * @brief Set drive setting. |
| 111 | * @param drive New drive. |
| 112 | * @return Reference to self. |
| 113 | */ |
| 114 | line_settings& set_drive(line::drive drive); |
| 115 | |
| 116 | /** |
| 117 | * @brief Get drive setting. |
| 118 | * @return Current drive. |
| 119 | */ |
| 120 | line::drive drive() const; |
| 121 | |
| 122 | /** |
| 123 | * @brief Set the active-low setting. |
| 124 | * @param active_low New active-low setting. |
| 125 | * @return Reference to self. |
| 126 | */ |
| 127 | line_settings& set_active_low(bool active_low); |
| 128 | |
| 129 | /** |
| 130 | * @brief Get the active-low setting. |
| 131 | * @return Current active-low setting. |
| 132 | */ |
| 133 | bool active_low() const noexcept; |
| 134 | |
| 135 | /** |
| 136 | * @brief Set debounce period. |
| 137 | * @param period New debounce period in microseconds. |
| 138 | * @return Reference to self. |
| 139 | */ |
| 140 | line_settings& set_debounce_period(const ::std::chrono::microseconds& period); |
| 141 | |
| 142 | /** |
| 143 | * @brief Get debounce period. |
| 144 | * @return Current debounce period. |
| 145 | */ |
| 146 | ::std::chrono::microseconds debounce_period() const noexcept; |
| 147 | |
| 148 | /** |
| 149 | * @brief Set the event clock to use for edge event timestamps. |
| 150 | * @param event_clock Clock to use. |
| 151 | * @return Reference to self. |
| 152 | */ |
| 153 | line_settings& set_event_clock(line::clock event_clock); |
| 154 | |
| 155 | /** |
| 156 | * @brief Get the event clock used for edge event timestamps. |
| 157 | * @return Current event clock type. |
| 158 | */ |
| 159 | line::clock event_clock() const; |
| 160 | |
| 161 | /** |
| 162 | * @brief Set the output value. |
| 163 | * @param value New output value. |
| 164 | * @return Reference to self. |
| 165 | */ |
| 166 | line_settings& set_output_value(line::value value); |
| 167 | |
| 168 | /** |
| 169 | * @brief Get the output value. |
| 170 | * @return Current output value. |
| 171 | */ |
| 172 | line::value output_value() const; |
| 173 | |
| 174 | private: |
| 175 | |
| 176 | struct impl; |
| 177 | |
| 178 | ::std::unique_ptr<impl> _m_priv; |
| 179 | |
| 180 | friend line_config; |
| 181 | }; |
| 182 | |
| 183 | /** |
| 184 | * @brief Stream insertion operator for line settings. |
| 185 | * @param out Output stream to write to. |
| 186 | * @param settings Line settings object to insert into the output stream. |
| 187 | * @return Reference to out. |
| 188 | */ |
| 189 | ::std::ostream& operator<<(::std::ostream& out, const line_settings& settings); |
| 190 | |
| 191 | } /* namespace gpiod */ |
| 192 | |
| 193 | #endif /* __LIBGPIOD_CXX_LINE_SETTINGS_HPP__ */ |