gpio: Add gpio chardev interface
Signed-off-by: Mihai Stefanescu <mihai.t.gh.stefanescu@gmail.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
aa7006cce9
commit
1665e09928
1587
src/gpio/gpio.c
1587
src/gpio/gpio.c
File diff suppressed because it is too large
Load Diff
58
src/mraa.c
58
src/mraa.c
@@ -45,7 +45,7 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#if defined(IMRAA)
|
||||
#include <json-c/json.h>
|
||||
@@ -98,6 +98,57 @@ mraa_set_log_level(int level)
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
mraa_boolean_t mraa_is_kernel_chardev_interface_compatible()
|
||||
{
|
||||
struct utsname buf;
|
||||
int status;
|
||||
|
||||
status = uname(&buf);
|
||||
|
||||
if (status) {
|
||||
syslog(LOG_ERR, "uname() error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int major, minor;
|
||||
char *token;
|
||||
|
||||
token = strtok(buf.release, ".");
|
||||
if (token == NULL) {
|
||||
syslog(LOG_ERR, "Could not find kernel version major number");
|
||||
return 0;
|
||||
}
|
||||
status = mraa_atoi(token, &major);
|
||||
if (status) {
|
||||
syslog(LOG_ERR, "mraa_atoi() error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
token = strtok(NULL, ".");
|
||||
if (token == NULL) {
|
||||
syslog(LOG_ERR, "Could not find kernel version minor number");
|
||||
return 0;
|
||||
}
|
||||
status = mraa_atoi(token, &minor);
|
||||
if (status) {
|
||||
syslog(LOG_ERR, "mraa_atoi() error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (major < 4 || minor < 8) {
|
||||
syslog(LOG_ERR, "Kernel version %i.%i not supported for chardev interface. Need version 4.8 or newer!", major, minor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO: Add all relevant checks here and return the overall result. */
|
||||
mraa_boolean_t mraa_is_platform_chardev_interface_capable()
|
||||
{
|
||||
return mraa_is_kernel_chardev_interface_compatible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whilst the actual mraa init function is now called imraa_init, it's only
|
||||
* callable externally if IMRAA is enabled
|
||||
@@ -218,6 +269,11 @@ imraa_init()
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
}
|
||||
|
||||
plat->chardev_capable = mraa_is_platform_chardev_interface_capable();
|
||||
if (plat->chardev_capable) {
|
||||
syslog(LOG_NOTICE, "libmraa: support for chardev interface is activated");
|
||||
}
|
||||
|
||||
syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(), mraa_get_platform_type());
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user