Skip to content
Merged
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
8 changes: 8 additions & 0 deletions src/modules/libgpiod/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBGPIOD REQUIRED IMPORTED_TARGET libgpiod)

set(LIBGPIOD_BIN libgpiod)

set(LIBGPIOD_SRCS
Expand All @@ -9,6 +12,11 @@ set(LIBGPIOD_SRCS

add_library(${LIBGPIOD_BIN} SHARED ${LIBGPIOD_SRCS})

target_link_libraries(${LIBGPIOD_BIN}
PRIVATE
PkgConfig::LIBGPIOD
)

set_target_properties(${LIBGPIOD_BIN} PROPERTIES
COMPILE_FLAGS "${MODULE_COMPILE_FLAGS}"
)
Expand Down
24 changes: 12 additions & 12 deletions src/modules/libgpiod/LibgpiodPin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ LibgpiodPin::LibgpiodPin(zmqpp::context &ctx, const std::string &name, const std
gpiod_line_ = gpiod_chip_get_line(gpiod_chip_, gpio_offset_);
assert(gpiod_line_ != nullptr);

set_direction(direction);
set_interrupt(interrupt_mode);
configure_line(direction, interrupt_mode);
}

LibgpiodPin::~LibgpiodPin()
Expand All @@ -68,16 +67,17 @@ void LibgpiodPin::release()
}
}

void LibgpiodPin::set_direction(Direction dir)
void LibgpiodPin::configure_line(Direction dir, InterruptMode mode)
{
if (dir == Direction::In)
{
gpiod_line_request_input(gpiod_line_, module_.general_config()->consumer().c_str());
}
else
{
gpiod_line_request_output(gpiod_line_, module_.general_config()->consumer().c_str(), initial_value_);
}
if (gpiod_line_) {
gpiod_line_release(gpiod_line_);
}

if (dir == Direction::Out) {
gpiod_line_request_output(gpiod_line_, module_.general_config()->consumer().c_str(), initial_value_);
} else {
set_interrupt(mode);
}
}

void LibgpiodPin::set_interrupt(InterruptMode mode)
Expand Down Expand Up @@ -176,7 +176,7 @@ void LibgpiodPin::register_sockets(zmqpp::reactor *reactor)
gpiod_fd_ = gpiod_line_event_get_fd(gpiod_line_);
ASSERT_LOG(gpiod_fd_ >= 0, "Bad GPIO line or the line is not setup for event monitoring.");
reactor->add(gpiod_fd_, std::bind(&LibgpiodPin::handle_interrupt, this),
zmqpp::poller::poll_pri);
zmqpp::poller::poll_in);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/libgpiod/LibgpiodPin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class LibgpiodPin
void handle_message();

/**
* Write direction to the `direction` file.
* Configure the line with direction to output or set interrupt mode.
*/
void set_direction(Direction dir);
void configure_line(Direction dir, InterruptMode mode);

/**
* Write interrupt mode to the `edge` file.
Expand Down
Loading