| Henry Wu | e634411 | 2025-11-26 19:15:39 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <gpiod.hpp> |
| 4 | |
| 5 | #include <string> |
| 6 | |
| 7 | std::vector<std::unique_ptr<::gpiod::line_bulk>> requestMuxGPIOs( |
| 8 | const std::vector<std::string>& gpioLines, |
| 9 | const std::vector<bool>& gpioPolarities, bool inverted); |
| 10 | |
| 11 | /* |
| 12 | * @class GPIOGroup |
| 13 | * @brief A group of GPIO lines to be muxed together |
| 14 | */ |
| 15 | class GPIOGroup |
| 16 | { |
| 17 | public: |
| 18 | GPIOGroup(std::vector<std::string> lines, std::vector<bool> polarities); |
| 19 | |
| 20 | ~GPIOGroup(); |
| 21 | |
| 22 | // GPIOs set to route mux to the BMC |
| 23 | bool muxToBMC(); |
| 24 | // GPIOs set to the opposite values to route mux to the external device |
| 25 | bool muxToDevice(); |
| 26 | |
| 27 | void releaseAll(); |
| 28 | |
| 29 | GPIOGroup(const GPIOGroup&) = delete; |
| 30 | GPIOGroup& operator=(const GPIOGroup&) = delete; |
| 31 | GPIOGroup(GPIOGroup&& /*other*/) noexcept; |
| 32 | GPIOGroup& operator=(GPIOGroup&& /*other*/) noexcept; |
| 33 | |
| 34 | private: |
| 35 | bool mux(bool inverted); |
| 36 | |
| 37 | std::vector<std::string> lines; |
| 38 | std::vector<bool> polarities; |
| 39 | std::vector<std::unique_ptr<::gpiod::line_bulk>> activeBulks; |
| 40 | }; |
| 41 | |
| 42 | /* |
| 43 | * @class ScopedBmcMux |
| 44 | * @brief A RAII wrapper to mux GPIO lines to BMC on construction |
| 45 | * and back to device on destruction |
| 46 | */ |
| 47 | class ScopedBmcMux |
| 48 | { |
| 49 | public: |
| 50 | explicit ScopedBmcMux(GPIOGroup& group); |
| 51 | ~ScopedBmcMux(); |
| 52 | |
| 53 | ScopedBmcMux(const ScopedBmcMux&) = delete; |
| 54 | ScopedBmcMux& operator=(const ScopedBmcMux&) = delete; |
| 55 | |
| 56 | ScopedBmcMux(ScopedBmcMux&& /*other*/) = delete; |
| 57 | ScopedBmcMux& operator=(ScopedBmcMux&& /*other*/) = delete; |
| 58 | |
| 59 | private: |
| 60 | GPIOGroup& gpioGroup; |
| 61 | }; |