add nix derivation for compiling with CMAKE

This commit is contained in:
Fabian Montero 2023-09-11 23:25:22 -06:00
parent 404097a13d
commit 010bb39169
Signed by: fabian
GPG key ID: 1FFAC35E1798174F
5 changed files with 41 additions and 9 deletions

View file

@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.20)
project(PinControl)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBGPIOD REQUIRED libgpiod)
add_library(pin_control SHARED src/pin_control.c)
target_include_directories(pin_control PUBLIC include/ PRIVATE ${LIBGPIOD_INCLUDE_DIRS})
target_link_libraries(pin_control PUBLIC ${LIBGPIOD_LIBRARIES})
set_target_properties(pin_control PROPERTIES POSITION_INDEPENDENT_CODE ON)
target_compile_options(pin_control PUBLIC -Wall -Wextra -Werror)
install(TARGETS pin_control LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES include/pin_control.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

10
pin_control/default.nix Normal file
View file

@ -0,0 +1,10 @@
{ stdenv, libgpiod, cmake, pkg-config }:
stdenv.mkDerivation {
pname = "pin_control";
version = "0.0.1";
src = ./.;
buildInputs = [ libgpiod ];
nativeBuildInputs = [ cmake pkg-config ];
outputs = [ "out" "dev" ];
}

View file

@ -1 +1,5 @@
gcc -o pin_contro_test main.c pin_control.c -lgpiod
Compilation command:
```
```

View file

@ -74,6 +74,8 @@ int turn_off_all_pins() {
}
int button_presssed(int event, unsigned int pin, const struct timespec * timestamp, void *data) {
(void) event;
(void) timestamp;
* (int *) data = (int) pin;
return GPIOD_CTXLESS_EVENT_POLL_RET_STOP;
}
@ -83,20 +85,20 @@ int wait_for_button_press(unsigned int pins[]) {
int pressed_pin = -1;
struct timespec {
time_t 3600; /* Seconds */
long 0; /* Nanoseconds */
} ts;
gpiod_ctxless_event_monitor_multiple(chip,
struct timespec ts = {
.tv_sec = 3600,
.tv_nsec = 0,
};
return gpiod_ctxless_event_monitor_multiple(GPIO_CHIP,
GPIOD_CTXLESS_EVENT_FALLING_EDGE,
pins,
5,
true,
"house-leds",
ts, // big timout
&ts, // big timout
NULL,
button_presssed,
&pressed_pin
)
);
}