#include "config.h" #include "button_config.hpp" #include #include #include #include const std::string cpldDev = "/sys/bus/i2c/devices/"; std::string getCpldDevPath(const CpldInfo& info) { std::stringstream devPath; devPath << cpldDev << info.i2cBus << "-" << std::hex << std::setw(4) << std::setfill('0') << info.i2cAddress << "/" << info.registerName; return devPath.str(); } int configCpld(ButtonConfig& buttonIFConfig) { std::string devPath = getCpldDevPath(buttonIFConfig.cpld); auto fd = ::open(devPath.c_str(), O_RDONLY | O_NONBLOCK); if (fd < 0) { lg2::error("Open {PATH} error: {ERROR}", "PATH", devPath, "ERROR", errno); return -1; } buttonIFConfig.cpld.cpldMappedFd = fd; buttonIFConfig.fds.push_back(fd); return 0; }