Skip to content

Commit

Permalink
Merge branch 'floitsch/linux.add-libgpiod.gpio.50.async-spi' into flo…
Browse files Browse the repository at this point in the history
…itsch/linux.add-libgpiod.gpio.60.move_tests
  • Loading branch information
floitsch committed Oct 16, 2024
2 parents d04284e + 3e394c9 commit fdcf3cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/event_sources/async_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void AsyncEventThread::stop() {
cancel();
}
state_ = STOPPED;
OS::signal(queue_cond_);
}
join();
}
Expand Down
17 changes: 13 additions & 4 deletions src/resources/spi_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ PRIMITIVE(init) {
PRIMITIVE(open) {
ARGS(SpiResourceGroup, group, cstring, pathname, int, frequency, int, mode);
if (frequency <= 0) FAIL(INVALID_ARGUMENT);
if (mode < 0 || mode > 3) FAIL(INVALID_ARGUMENT);

ByteArray* proxy = process->object_heap()->allocate_proxy();
if (proxy == null) FAIL(ALLOCATION_FAILED);
Expand All @@ -210,13 +211,21 @@ PRIMITIVE(open) {
// File descriptors that are intended for subprocesses have the flags cleared.
int fd = open(pathname, O_CLOEXEC | O_RDWR);
if (fd < 0) return return_open_error(process, errno);
int result = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &frequency);
if (result < 0) {
int ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &frequency);
if (ret < 0) {
close(fd);
return Primitive::os_error(errno, process);
}
result = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (result < 0) {
uint8 mode_byte;
switch (mode) {
case 0: mode_byte = SPI_MODE_0; break;
case 1: mode_byte = SPI_MODE_1; break;
case 2: mode_byte = SPI_MODE_2; break;
case 3: mode_byte = SPI_MODE_3; break;
default: UNREACHABLE();
}
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode_byte);
if (ret < 0) {
close(fd);
return Primitive::os_error(errno, process);
}
Expand Down

0 comments on commit fdcf3cc

Please sign in to comment.