| #include "gpio_handle.hpp" |
| |
| #include <gpioplus/chip.hpp> |
| #include <gpioplus/handle.hpp> |
| #include <phosphor-logging/log.hpp> |
| |
| #include <cstdlib> |
| #include <memory> |
| #include <string> |
| |
| namespace gpio |
| { |
| |
| using namespace phosphor::logging; |
| |
| std::unique_ptr<gpioplus::HandleInterface> |
| BuildGpioHandle(const std::string& gpiochip, const std::string& line) |
| { |
| char *gpioEnd, *lineEnd; |
| unsigned long chipId = std::strtoul(gpiochip.c_str(), &gpioEnd, 10); |
| unsigned long lineOffset = std::strtoul(line.c_str(), &lineEnd, 10); |
| |
| if (!gpioEnd || gpioEnd != &gpiochip.c_str()[gpiochip.length()]) |
| { |
| log<level::ERR>("Unable to handle giochip entry", |
| entry("GPIOCHIP=%s", gpiochip.c_str())); |
| return nullptr; |
| } |
| |
| if (!lineEnd || lineEnd != &line.c_str()[line.length()]) |
| { |
| log<level::ERR>("Unable to handle line entry", |
| entry("LINE=%s", line.c_str())); |
| return nullptr; |
| } |
| |
| try |
| { |
| gpioplus::Chip chip(chipId); |
| gpioplus::HandleFlags flags(chip.getLineInfo(lineOffset).flags); |
| flags.output = true; |
| std::vector<gpioplus::Handle::Line> lines = { |
| {static_cast<uint32_t>(lineOffset), 0}}; |
| |
| return std::make_unique<gpioplus::Handle>(chip, lines, flags, |
| "phosphor-hwmon"); |
| } |
| catch (const std::exception& e) |
| { |
| log<level::ERR>("Unable to set up GPIO handle", |
| entry("ERROR=%s", e.what())); |
| return nullptr; |
| } |
| } |
| |
| } // namespace gpio |