Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions fboss/lib/GpiodLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,28 @@ void GpiodLine::setValue(int defaultVal, int targetVal) {
}
}

int GpiodLine::getLineValue() {
struct gpiod_line_request_config config = {
.consumer = name_.c_str(),
.request_type = GPIOD_LINE_REQUEST_DIRECTION_AS_IS,
.flags = 0};

if (gpiod_line_request(line_, &config, 0) != 0) {
throw GpiodLineError(
fmt::format(
"GpiodLineTrace: gpiod_line_request() failed for {}", name_));
}

int val = gpiod_line_get_value(line_); // Read the line value

if (-1 == val) {
throw GpiodLineError(
fmt::format(
"GpiodLineTrace: gpiod_line_get_value() failed to get {} value, errno = {}",
name_,
folly::errnoStr(errno)));
}

return val;
}
} // namespace facebook::fboss
1 change: 1 addition & 0 deletions fboss/lib/GpiodLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class GpiodLine {
~GpiodLine();
int getValue();
void setValue(int defaultVal, int targetVal);
int getLineValue();

// Forbidden copy constructor and assignment operator
GpiodLine(GpiodLine const&) = delete;
Expand Down
5 changes: 3 additions & 2 deletions fboss/platform/rma-showtech/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,9 @@ void Utils::printGpio(const Gpio& gpio) {
std::cout << fmt::format(
"line {:>3}: {:<15} -> ", *line.lineIndex(), *line.name());
try {
std::cout << GpiodLine(chip, *line.lineIndex(), *line.name()).getValue()
<< std::endl;
std::cout
<< GpiodLine(chip, *line.lineIndex(), *line.name()).getLineValue()
<< std::endl;
} catch (const std::exception& e) {
std::cout << fmt::format("Error: failed to read gpio line: {}", e.what())
<< std::endl;
Expand Down
Loading