Skip to content

Commit 0ae3aa1

Browse files
committed
Fix RQI GPIO number changes since kernel 5.15.0
1 parent 3902df0 commit 0ae3aa1

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ endif()
262262
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/postinst;")
263263
set(CPACK_GENERATOR "DEB")
264264
## Set the package version
265-
set(CPACK_PACKAGE_VERSION "1.3.11")
265+
set(CPACK_PACKAGE_VERSION "1.3.12")
266266
# Set the package name
267267
set(CPACK_PACKAGE_NAME "neuron-library")
268268
# Set the package file format

src/x86/roscube_i.c

+42-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#include <sys/mman.h>
3131
#include <sys/stat.h>
3232
#include <sys/time.h>
33+
#include <sys/utsname.h>
3334
#include <linux/i2c-dev.h>
35+
#include <linux/version.h>
3436

3537
#include "common.h"
3638
#include "gpio.h"
@@ -48,14 +50,46 @@
4850
#define MAX_SIZE 64
4951
#define POLL_TIMEOUT
5052

51-
static volatile int base1, base2, _fd;
52-
#define base1 220
53-
#define base2 253
54-
#define led_base 276
53+
static volatile int _fd;
5554
static mraa_gpio_context gpio;
5655
static char* uart_name[MRAA_ROSCUBE_UARTCOUNT] = {"COM1", "COM2"};
5756
static char* uart_path[MRAA_ROSCUBE_UARTCOUNT] = {"/dev/ttyS0", "/dev/ttyS1"};
5857

58+
static void get_gpio_base(int *base1, int *base2, int *led_base)
59+
{
60+
struct utsname buffer;
61+
char *p;
62+
long ver[16];
63+
int i=0;
64+
65+
errno = 0;
66+
if (uname(&buffer) != 0) {
67+
perror("uname");
68+
exit(EXIT_FAILURE);
69+
}
70+
71+
p = buffer.release;
72+
while (*p) {
73+
if (isdigit(*p)) {
74+
ver[i] = strtol(p, &p, 10);
75+
i++;
76+
} else {
77+
p++;
78+
}
79+
}
80+
81+
long ver_hex = (ver[0] << 16) + (ver[1] << 8) + ver[2];
82+
if (ver_hex < KERNEL_VERSION(5,15,0)) {
83+
*base1 = 220;
84+
*base2 = 253;
85+
*led_base = 276;
86+
} else {
87+
*base1 = 732;
88+
*base2 = 765;
89+
*led_base = 788;
90+
}
91+
}
92+
5993
// utility function to setup pin mapping of boards
6094
static mraa_result_t mraa_roscube_set_pininfo(mraa_board_t* board, int mraa_index, char* name,
6195
mraa_pincapabilities_t caps, int sysfs_pin)
@@ -113,6 +147,8 @@ static mraa_result_t mraa_roscube_init_uart(mraa_board_t* board, int index)
113147

114148
int index_mapping(int index)
115149
{
150+
int base1, base2, led_base;
151+
get_gpio_base(&base1, &base2, &led_base);
116152
return index + led_base;
117153
}
118154

@@ -258,6 +294,8 @@ mraa_board_t* mraa_roscube_i()
258294
b->adv_func->led_set_close = rqi_led_set_close;
259295
b->adv_func->led_check_bright = rqi_led_check_bright;
260296

297+
int base1, base2, led_base;
298+
get_gpio_base(&base1, &base2, &led_base);
261299
syslog(LOG_NOTICE, "ROSCubeI: base1 %d base2 %d\n", base1, base2);
262300

263301
mraa_roscube_set_pininfo(b, 1, "CN_DI0", (mraa_pincapabilities_t){ 1, 1, 0, 0, 0, 0, 0, 0 }, base1 + 0);

0 commit comments

Comments
 (0)