clang-format: reapply to recently modified sources
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
115
src/gpio/gpio.c
115
src/gpio/gpio.c
@@ -23,9 +23,9 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "gpio.h"
|
||||
#include "gpio/gpio_chardev.h"
|
||||
#include "linux/gpio.h"
|
||||
#include "mraa_internal.h"
|
||||
#include "gpio/gpio_chardev.h"
|
||||
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
@@ -38,8 +38,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||
#define MAX_SIZE 64
|
||||
@@ -69,7 +69,7 @@ mraa_gpio_close_event_handles_sysfs(int fds[], int num_fds)
|
||||
|
||||
for (int i = 0; i < num_fds; ++i) {
|
||||
// Check required to avoid closing stdin and of an uninitialized fd
|
||||
if(fds[i] != 0) {
|
||||
if (fds[i] != 0) {
|
||||
close(fds[i]);
|
||||
}
|
||||
}
|
||||
@@ -130,15 +130,13 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
|
||||
} else {
|
||||
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
||||
if (export == -1) {
|
||||
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s",
|
||||
pin, strerror(errno));
|
||||
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s", pin, strerror(errno));
|
||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||
goto init_internal_cleanup;
|
||||
}
|
||||
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||
if (write(export, bu, length * sizeof(char)) == -1) {
|
||||
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s",
|
||||
pin, strerror(errno));
|
||||
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s", pin, strerror(errno));
|
||||
close(export);
|
||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||
goto init_internal_cleanup;
|
||||
@@ -181,11 +179,9 @@ mraa_gpio_init(int pin)
|
||||
* example: pin 515, dev->pin = 515, dev->phy_pin = 3
|
||||
*/
|
||||
if (mraa_is_sub_platform_id(pin) && (board->sub_platform != NULL)) {
|
||||
syslog(LOG_NOTICE, "gpio%i: initialised on sub platform '%s' physical pin: %i",
|
||||
pin,
|
||||
board->sub_platform->platform_name != NULL ?
|
||||
board->sub_platform->platform_name : "",
|
||||
mraa_get_sub_platform_index(pin));
|
||||
syslog(LOG_NOTICE, "gpio%i: initialised on sub platform '%s' physical pin: %i", pin,
|
||||
board->sub_platform->platform_name != NULL ? board->sub_platform->platform_name : "",
|
||||
mraa_get_sub_platform_index(pin));
|
||||
|
||||
board = board->sub_platform;
|
||||
if (board == NULL) {
|
||||
@@ -201,8 +197,7 @@ mraa_gpio_init(int pin)
|
||||
}
|
||||
|
||||
if (pin < 0 || pin >= board->phy_pin_count) {
|
||||
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)",
|
||||
pin, board->phy_pin_count);
|
||||
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)", pin, board->phy_pin_count);
|
||||
return NULL;
|
||||
}
|
||||
if (board->pins[pin].capabilities.gpio != 1) {
|
||||
@@ -337,8 +332,8 @@ mraa_gpio_chardev_init(int pins[], int num_pins)
|
||||
|
||||
int line_in_group;
|
||||
line_in_group = gpio_group[chip_id].num_gpio_lines;
|
||||
gpio_group[chip_id].gpio_lines = realloc(gpio_group[chip_id].gpio_lines,
|
||||
(line_in_group + 1) * sizeof(unsigned int));
|
||||
gpio_group[chip_id].gpio_lines =
|
||||
realloc(gpio_group[chip_id].gpio_lines, (line_in_group + 1) * sizeof(unsigned int));
|
||||
if (gpio_group[chip_id].gpio_lines == NULL) {
|
||||
syslog(LOG_CRIT, "[GPIOD_INTERFACE]: Failed to allocate memory for internal member");
|
||||
mraa_gpio_close(dev);
|
||||
@@ -465,9 +460,8 @@ mraa_gpio_wait_interrupt(int fds[],
|
||||
,
|
||||
int control_fd
|
||||
#endif
|
||||
,
|
||||
mraa_gpio_events_t events
|
||||
)
|
||||
,
|
||||
mraa_gpio_events_t events)
|
||||
{
|
||||
unsigned char c;
|
||||
#ifdef HAVE_PTHREAD_CANCEL
|
||||
@@ -564,7 +558,8 @@ mraa_gpio_get_events(mraa_gpio_context dev)
|
||||
unsigned int pin_idx;
|
||||
mraa_gpiod_group_t gpio_iter;
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
for (int i = 0; i < gpio_iter->num_gpio_lines; ++i) {
|
||||
if (dev->events[event_idx].id != -1) {
|
||||
pin_idx = gpio_iter->gpio_group_to_pins_table[i];
|
||||
@@ -606,19 +601,21 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int *fps = calloc(dev->num_pins, sizeof(int));
|
||||
int* fps = calloc(dev->num_pins, sizeof(int));
|
||||
if (!fps) {
|
||||
syslog(LOG_ERR, "mraa_gpio_interrupt_handler_multiple() malloc error");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Is this pin on a subplatform? Do nothing... */
|
||||
if (mraa_is_sub_platform_id(dev->pin)) {}
|
||||
if (mraa_is_sub_platform_id(dev->pin)) {
|
||||
}
|
||||
/* Is the platform chardev_capable? */
|
||||
else if (plat->chardev_capable) {
|
||||
mraa_gpiod_group_t gpio_group;
|
||||
|
||||
for_each_gpio_group(gpio_group, dev) {
|
||||
for_each_gpio_group(gpio_group, dev)
|
||||
{
|
||||
for (int i = 0; i < gpio_group->num_gpio_lines; ++i) {
|
||||
fps[idx++] = gpio_group->event_handles[i];
|
||||
}
|
||||
@@ -672,12 +669,11 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
} else {
|
||||
ret = mraa_gpio_wait_interrupt(fps, idx
|
||||
#ifndef HAVE_PTHREAD_CANCEL
|
||||
,
|
||||
dev->isr_control_pipe[0]
|
||||
,
|
||||
dev->isr_control_pipe[0]
|
||||
#endif
|
||||
,
|
||||
dev->events
|
||||
);
|
||||
,
|
||||
dev->events);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +690,7 @@ mraa_gpio_interrupt_handler(void* arg)
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
#endif
|
||||
} else {
|
||||
// we must have got an error code or exit request so die nicely
|
||||
// we must have got an error code or exit request so die nicely
|
||||
#ifdef HAVE_PTHREAD_CANCEL
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
|
||||
#endif
|
||||
@@ -789,7 +785,7 @@ mraa_gpio_edge_mode(mraa_gpio_context dev, mraa_gpio_edge_t mode)
|
||||
|
||||
/* Initialize events array. */
|
||||
if (dev->events == NULL && mode != MRAA_GPIO_EDGE_NONE) {
|
||||
dev->events = malloc(dev->num_pins * sizeof (mraa_gpio_event));
|
||||
dev->events = malloc(dev->num_pins * sizeof(mraa_gpio_event));
|
||||
if (dev->events == NULL) {
|
||||
syslog(LOG_ERR, "mraa_gpio_edge_mode() malloc error");
|
||||
return MRAA_ERROR_NO_RESOURCES;
|
||||
@@ -945,8 +941,8 @@ mraa_gpio_isr_exit(mraa_gpio_context dev)
|
||||
dev->isr_thread_terminating = 0;
|
||||
|
||||
if (dev->events) {
|
||||
free(dev->events);
|
||||
dev->events = NULL;
|
||||
free(dev->events);
|
||||
dev->events = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -977,8 +973,10 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
_mraa_close_gpio_desc(dev);
|
||||
|
||||
/* We save flag values from the first valid line. */
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
mraa_gpiod_line_info* linfo = mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
mraa_gpiod_line_info* linfo =
|
||||
mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||
if (!linfo) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
@@ -1005,8 +1003,10 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
line_handle = mraa_get_lines_handle(gpio_iter->dev_fd, gpio_iter->gpio_lines, gpio_iter->num_gpio_lines, flags, 0);
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
line_handle = mraa_get_lines_handle(gpio_iter->dev_fd, gpio_iter->gpio_lines,
|
||||
gpio_iter->num_gpio_lines, flags, 0);
|
||||
if (line_handle <= 0) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line handle");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
@@ -1071,8 +1071,10 @@ mraa_gpio_chardev_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
unsigned flags = 0;
|
||||
mraa_gpiod_group_t gpio_iter;
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
mraa_gpiod_line_info* linfo = mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
mraa_gpiod_line_info* linfo =
|
||||
mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||
if (!linfo) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
@@ -1097,7 +1099,8 @@ mraa_gpio_chardev_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
if (gpio_iter->gpiod_handle != -1) {
|
||||
close(gpio_iter->gpiod_handle);
|
||||
gpio_iter->gpiod_handle = -1;
|
||||
@@ -1125,7 +1128,7 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_dir_replace)) {
|
||||
return dev->advance_func->gpio_dir_replace(dev, dir);
|
||||
return dev->advance_func->gpio_dir_replace(dev, dir);
|
||||
}
|
||||
|
||||
if (IS_FUNC_DEFINED(dev, gpio_dir_pre)) {
|
||||
@@ -1160,7 +1163,7 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
return mraa_gpio_write(it, 0);
|
||||
default:
|
||||
syslog(LOG_ERR, "gpio%i: dir: Failed to open 'direction' for writing: %s",
|
||||
it->pin, strerror(errno));
|
||||
it->pin, strerror(errno));
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
}
|
||||
@@ -1202,7 +1205,7 @@ mraa_gpio_dir(mraa_gpio_context dev, mraa_gpio_dir_t dir)
|
||||
}
|
||||
|
||||
mraa_result_t
|
||||
mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
||||
mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t* dir)
|
||||
{
|
||||
mraa_result_t result = MRAA_SUCCESS;
|
||||
|
||||
@@ -1216,8 +1219,10 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
||||
if (plat->chardev_capable) {
|
||||
mraa_gpiod_group_t gpio_iter;
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
mraa_gpiod_line_info* linfo = mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
mraa_gpiod_line_info* linfo =
|
||||
mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||
if (!linfo) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
||||
return MRAA_ERROR_UNSPECIFIED;
|
||||
@@ -1295,7 +1300,7 @@ mraa_gpio_read(mraa_gpio_context dev)
|
||||
int output_values[1] = { 0 };
|
||||
|
||||
if (mraa_gpio_read_multi(dev, output_values) != MRAA_SUCCESS)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
return output_values[0];
|
||||
}
|
||||
@@ -1314,8 +1319,8 @@ mraa_gpio_read(mraa_gpio_context dev)
|
||||
}
|
||||
char bu[2];
|
||||
if (read(dev->value_fp, bu, 2 * sizeof(char)) != 2) {
|
||||
syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s",
|
||||
dev->pin, strerror(errno));
|
||||
syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s", dev->pin,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
lseek(dev->value_fp, 0, SEEK_SET);
|
||||
@@ -1336,21 +1341,22 @@ mraa_gpio_read_multi(mraa_gpio_context dev, int output_values[])
|
||||
|
||||
mraa_gpiod_group_t gpio_iter;
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
int status;
|
||||
unsigned flags = GPIOHANDLE_REQUEST_INPUT;
|
||||
|
||||
if (gpio_iter->gpiod_handle <= 0) {
|
||||
gpio_iter->gpiod_handle = mraa_get_lines_handle(gpio_iter->dev_fd, gpio_iter->gpio_lines,
|
||||
gpio_iter->num_gpio_lines, flags, 0);
|
||||
gpio_iter->num_gpio_lines, flags, 0);
|
||||
if (gpio_iter->gpiod_handle <= 0) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting gpio line handle");
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
status = mraa_get_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines,
|
||||
gpio_iter->rw_values);
|
||||
status =
|
||||
mraa_get_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines, gpio_iter->rw_values);
|
||||
if (status < 0) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error writing gpio");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
@@ -1460,7 +1466,8 @@ mraa_gpio_write_multi(mraa_gpio_context dev, int input_values[])
|
||||
}
|
||||
free(counters);
|
||||
|
||||
for_each_gpio_group(gpio_iter, dev) {
|
||||
for_each_gpio_group(gpio_iter, dev)
|
||||
{
|
||||
int status;
|
||||
unsigned flags = GPIOHANDLE_REQUEST_OUTPUT;
|
||||
|
||||
@@ -1473,8 +1480,8 @@ mraa_gpio_write_multi(mraa_gpio_context dev, int input_values[])
|
||||
}
|
||||
}
|
||||
|
||||
status = mraa_set_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines,
|
||||
gpio_iter->rw_values);
|
||||
status =
|
||||
mraa_set_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines, gpio_iter->rw_values);
|
||||
if (status < 0) {
|
||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error writing gpio");
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#include <json-c/json.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "mraa_internal.h"
|
||||
|
||||
@@ -64,9 +64,8 @@ mraa_init_json_platform_get_index(json_object* jobj, const char* io, const char*
|
||||
|
||||
*pos = (int) json_object_get_int(jobj_temp);
|
||||
if (*pos < 0 || *pos > upper) {
|
||||
syslog(LOG_ERR,
|
||||
"init_json_platform: %s %s at position: %d, gave: %d which was out of range", io,
|
||||
key, index, *pos);
|
||||
syslog(LOG_ERR, "init_json_platform: %s %s at position: %d, gave: %d which was out of range",
|
||||
io, key, index, *pos);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
return MRAA_SUCCESS;
|
||||
@@ -291,7 +290,7 @@ mraa_init_json_platform_i2c(json_object* jobj_i2c, mraa_board_t* board, int inde
|
||||
json_object* jobj_temp = NULL;
|
||||
|
||||
// Default to no mux pins defined
|
||||
if(board->pins != NULL) {
|
||||
if (board->pins != NULL) {
|
||||
board->pins[pin].i2c.mux_total = 0;
|
||||
} else {
|
||||
return MRAA_ERROR_NO_DATA_AVAILABLE;
|
||||
@@ -559,8 +558,9 @@ mraa_init_json_platform_loop(json_object* jobj_platform, const char* obj_key, mr
|
||||
jobj_io = json_object_array_get_idx(jobj_temp, i);
|
||||
// Check to see it's the right type
|
||||
if (!json_object_is_type(jobj_io, json_type_object)) {
|
||||
syslog(LOG_ERR, "init_json_platform: One of more of the elements in the \"%s\" "
|
||||
"array where not JSON objects",
|
||||
syslog(LOG_ERR,
|
||||
"init_json_platform: One of more of the elements in the \"%s\" "
|
||||
"array where not JSON objects",
|
||||
obj_key);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -595,8 +595,7 @@ mraa_init_json_platform_size_check(json_object* jobj_platform,
|
||||
// make sure we don't have more than our range
|
||||
array_length = json_object_array_length(jobj_temp);
|
||||
if (array_length > range) {
|
||||
syslog(LOG_ERR,
|
||||
"init_json_platform: The size of the %s array given was %d, max was: %d",
|
||||
syslog(LOG_ERR, "init_json_platform: The size of the %s array given was %d, max was: %d",
|
||||
obj_key, array_length, range);
|
||||
return MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
@@ -617,7 +616,7 @@ mraa_init_json_platform(const char* platform_json)
|
||||
char* buffer = NULL;
|
||||
struct stat st;
|
||||
int file_lock = 0, i = 0;
|
||||
json_object *jobj_platform = NULL;
|
||||
json_object* jobj_platform = NULL;
|
||||
mraa_board_t* board = NULL;
|
||||
|
||||
// Try to lock the file for use
|
||||
|
||||
210
src/mraa.c
210
src/mraa.c
@@ -28,43 +28,43 @@
|
||||
#define _XOPEN_SOURCE 600 /* Get nftw() and S_IFSOCK declarations */
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <sched.h>
|
||||
#include <string.h>
|
||||
#include <pwd.h>
|
||||
#include <sched.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if !defined(PERIPHERALMAN)
|
||||
#include <glob.h>
|
||||
#include <ftw.h>
|
||||
#include <glob.h>
|
||||
#endif
|
||||
#include <dirent.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(IMRAA)
|
||||
#include <json-c/json.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include "mraa_internal.h"
|
||||
#include "aio.h"
|
||||
#include "firmata/firmata_mraa.h"
|
||||
#include "grovepi/grovepi.h"
|
||||
#include "gpio.h"
|
||||
#include "gpio/gpio_chardev.h"
|
||||
#include "version.h"
|
||||
#include "grovepi/grovepi.h"
|
||||
#include "i2c.h"
|
||||
#include "mraa_internal.h"
|
||||
#include "pwm.h"
|
||||
#include "aio.h"
|
||||
#include "spi.h"
|
||||
#include "uart.h"
|
||||
#include "version.h"
|
||||
|
||||
#if defined(PERIPHERALMAN)
|
||||
#include "peripheralmanager/peripheralman.h"
|
||||
@@ -100,17 +100,20 @@ mraa_set_log_level(int level)
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
mraa_boolean_t mraa_is_kernel_chardev_interface_compatible()
|
||||
mraa_boolean_t
|
||||
mraa_is_kernel_chardev_interface_compatible()
|
||||
{
|
||||
if (mraa_get_number_of_gpio_chips() <= 0) {
|
||||
syslog(LOG_NOTICE, "gpio: platform supports chardev but kernel doesn't, falling back to sysfs");
|
||||
syslog(LOG_NOTICE,
|
||||
"gpio: platform supports chardev but kernel doesn't, falling back to sysfs");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
mraa_boolean_t mraa_is_platform_chardev_interface_capable()
|
||||
mraa_boolean_t
|
||||
mraa_is_platform_chardev_interface_capable()
|
||||
{
|
||||
if ((plat != NULL) && (plat->chardev_capable)) {
|
||||
return mraa_is_kernel_chardev_interface_compatible();
|
||||
@@ -202,17 +205,15 @@ imraa_init()
|
||||
/* If a usb platform lib is present, attempt to load and look for
|
||||
* necessary symbols for adding extended I/O */
|
||||
void* usblib = dlopen("libmraa-platform-ft4222.so", RTLD_LAZY);
|
||||
if (usblib)
|
||||
{
|
||||
if (usblib) {
|
||||
syslog(LOG_NOTICE, "Found USB platform extender library: libmraa-platform-ft4222.so");
|
||||
syslog(LOG_NOTICE, "Detecting FT4222 subplatforms...");
|
||||
fptr_add_platform_extender add_ft4222_platform =
|
||||
(fptr_add_platform_extender)dlsym(usblib, "mraa_usb_platform_extender");
|
||||
(fptr_add_platform_extender) dlsym(usblib, "mraa_usb_platform_extender");
|
||||
|
||||
/* If this method exists, call it to add a subplatform */
|
||||
syslog(LOG_NOTICE, "Detecting FT4222 subplatforms complete, found %i subplatform/s",
|
||||
((add_ft4222_platform != NULL) && (add_ft4222_platform(plat) == MRAA_SUCCESS))
|
||||
? 1 : 0);
|
||||
((add_ft4222_platform != NULL) && (add_ft4222_platform(plat) == MRAA_SUCCESS)) ? 1 : 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -250,7 +251,8 @@ imraa_init()
|
||||
syslog(LOG_NOTICE, "gpio: 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());
|
||||
syslog(LOG_NOTICE, "libmraa initialised for platform '%s' of type %d", mraa_get_platform_name(),
|
||||
mraa_get_platform_type());
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -300,9 +302,8 @@ mraa_deinit()
|
||||
* allocate space for device_path, others use #defines or consts,
|
||||
* which means this has to be handled differently per platform
|
||||
*/
|
||||
if ((plat->platform_type == MRAA_JSON_PLATFORM) ||
|
||||
(plat->platform_type == MRAA_UP2) ||
|
||||
(plat->platform_type == MRAA_IEI_TANK)) {
|
||||
if ((plat->platform_type == MRAA_JSON_PLATFORM) || (plat->platform_type == MRAA_UP2) ||
|
||||
(plat->platform_type == MRAA_IEI_TANK)) {
|
||||
for (i = 0; i < plat->uart_dev_count; i++) {
|
||||
if (plat->uart_dev[i].device_path != NULL) {
|
||||
free(plat->uart_dev[i].device_path);
|
||||
@@ -377,7 +378,7 @@ mraa_iio_detect()
|
||||
plat_iio->iio_device_count = num_iio_devices;
|
||||
plat_iio->iio_devices = calloc(num_iio_devices, sizeof(struct _iio));
|
||||
struct _iio* device;
|
||||
for (i=0; i < num_iio_devices; i++) {
|
||||
for (i = 0; i < num_iio_devices; i++) {
|
||||
device = &plat_iio->iio_devices[i];
|
||||
device->num = i;
|
||||
snprintf(filepath, 64, "/sys/bus/iio/devices/iio:device%d/name", i);
|
||||
@@ -390,7 +391,7 @@ mraa_iio_detect()
|
||||
len = strlen(name);
|
||||
// use strndup
|
||||
device->name = malloc((sizeof(char) * len) + sizeof(char));
|
||||
strncpy(device->name, name, len+1);
|
||||
strncpy(device->name, name, len + 1);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
@@ -409,22 +410,23 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
|
||||
for (mi = 0; mi < meta.mux_total; mi++) {
|
||||
|
||||
switch(meta.mux[mi].pincmd) {
|
||||
case PINCMD_UNDEFINED: // used for backward compatibility
|
||||
if(meta.mux[mi].pin != last_pin) {
|
||||
switch (meta.mux[mi].pincmd) {
|
||||
case PINCMD_UNDEFINED: // used for backward compatibility
|
||||
if (meta.mux[mi].pin != last_pin) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
}
|
||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mux_i == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
last_pin = meta.mux[mi].pin;
|
||||
}
|
||||
// this function will sometimes fail, however this is not critical as
|
||||
// long as the write succeeds - Test case galileo gen2 pin2
|
||||
mraa_gpio_dir(mux_i, MRAA_GPIO_OUT);
|
||||
ret = mraa_gpio_write(mux_i, meta.mux[mi].value);
|
||||
if(ret != MRAA_SUCCESS) {
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
@@ -434,19 +436,20 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
break;
|
||||
|
||||
case PINCMD_SET_VALUE:
|
||||
if(meta.mux[mi].pin != last_pin) {
|
||||
if (meta.mux[mi].pin != last_pin) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
}
|
||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mux_i == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
last_pin = meta.mux[mi].pin;
|
||||
}
|
||||
|
||||
ret = mraa_gpio_write(mux_i, meta.mux[mi].value);
|
||||
|
||||
if(ret != MRAA_SUCCESS) {
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
@@ -456,19 +459,20 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
break;
|
||||
|
||||
case PINCMD_SET_DIRECTION:
|
||||
if(meta.mux[mi].pin != last_pin) {
|
||||
if (meta.mux[mi].pin != last_pin) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
}
|
||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mux_i == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
last_pin = meta.mux[mi].pin;
|
||||
}
|
||||
|
||||
ret = mraa_gpio_dir(mux_i, meta.mux[mi].value);
|
||||
|
||||
if(ret != MRAA_SUCCESS) {
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
@@ -478,22 +482,23 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
break;
|
||||
|
||||
case PINCMD_SET_IN_VALUE:
|
||||
if(meta.mux[mi].pin != last_pin) {
|
||||
if (meta.mux[mi].pin != last_pin) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
}
|
||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mux_i == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
last_pin = meta.mux[mi].pin;
|
||||
}
|
||||
|
||||
ret = mraa_gpio_dir(mux_i, MRAA_GPIO_IN);
|
||||
|
||||
if(ret == MRAA_SUCCESS)
|
||||
if (ret == MRAA_SUCCESS)
|
||||
ret = mraa_gpio_write(mux_i, meta.mux[mi].value);
|
||||
|
||||
if(ret != MRAA_SUCCESS) {
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
@@ -503,22 +508,23 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
break;
|
||||
|
||||
case PINCMD_SET_OUT_VALUE:
|
||||
if(meta.mux[mi].pin != last_pin) {
|
||||
if (meta.mux[mi].pin != last_pin) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
}
|
||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mux_i == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
last_pin = meta.mux[mi].pin;
|
||||
}
|
||||
|
||||
ret = mraa_gpio_dir(mux_i, MRAA_GPIO_OUT);
|
||||
|
||||
if(ret == MRAA_SUCCESS)
|
||||
if (ret == MRAA_SUCCESS)
|
||||
ret = mraa_gpio_write(mux_i, meta.mux[mi].value);
|
||||
|
||||
if(ret != MRAA_SUCCESS) {
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
@@ -528,19 +534,20 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
break;
|
||||
|
||||
case PINCMD_SET_MODE:
|
||||
if(meta.mux[mi].pin != last_pin) {
|
||||
if (meta.mux[mi].pin != last_pin) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
}
|
||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
||||
if (mux_i == NULL) return MRAA_ERROR_INVALID_HANDLE;
|
||||
if (mux_i == NULL)
|
||||
return MRAA_ERROR_INVALID_HANDLE;
|
||||
last_pin = meta.mux[mi].pin;
|
||||
}
|
||||
|
||||
ret = mraa_gpio_mode(mux_i, meta.mux[mi].value);
|
||||
|
||||
if(ret != MRAA_SUCCESS) {
|
||||
if (ret != MRAA_SUCCESS) {
|
||||
if (mux_i != NULL) {
|
||||
mraa_gpio_owner(mux_i, 0);
|
||||
mraa_gpio_close(mux_i);
|
||||
@@ -553,7 +560,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
||||
break;
|
||||
|
||||
default:
|
||||
syslog(LOG_NOTICE, "mraa_setup_mux_mapped: wrong command %d on pin %d with value %d", meta.mux[mi].pincmd, meta.mux[mi].pin, meta.mux[mi].value);
|
||||
syslog(LOG_NOTICE, "mraa_setup_mux_mapped: wrong command %d on pin %d with value %d",
|
||||
meta.mux[mi].pincmd, meta.mux[mi].pin, meta.mux[mi].value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -654,7 +662,8 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
|
||||
pin = mraa_get_sub_platform_index(pin);
|
||||
}
|
||||
|
||||
if (current_plat == NULL || current_plat->platform_type == MRAA_UNKNOWN_PLATFORM || current_plat->platform_type == MRAA_NULL_PLATFORM) {
|
||||
if (current_plat == NULL || current_plat->platform_type == MRAA_UNKNOWN_PLATFORM ||
|
||||
current_plat->platform_type == MRAA_NULL_PLATFORM) {
|
||||
return 0;
|
||||
}
|
||||
if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
|
||||
@@ -876,9 +885,9 @@ mraa_get_platform_pin_count(uint8_t platform_offset)
|
||||
return mraa_get_pin_count();
|
||||
else {
|
||||
if (mraa_has_sub_platform())
|
||||
return plat->sub_platform->phy_pin_count;
|
||||
return plat->sub_platform->phy_pin_count;
|
||||
else
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -920,14 +929,14 @@ mraa_gpio_lookup(const char* pin_name)
|
||||
}
|
||||
|
||||
for (i = 0; i < plat->phy_pin_count; i++) {
|
||||
// Skip non GPIO pins
|
||||
if (!(plat->pins[i].capabilities.gpio))
|
||||
continue;
|
||||
// Skip non GPIO pins
|
||||
if (!(plat->pins[i].capabilities.gpio))
|
||||
continue;
|
||||
|
||||
if (plat->pins[i].name != NULL &&
|
||||
strncmp(pin_name, plat->pins[i].name, strlen(plat->pins[i].name) + 1) == 0) {
|
||||
return i;
|
||||
}
|
||||
if (plat->pins[i].name != NULL &&
|
||||
strncmp(pin_name, plat->pins[i].name, strlen(plat->pins[i].name) + 1) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -946,10 +955,10 @@ mraa_i2c_lookup(const char* i2c_name)
|
||||
}
|
||||
|
||||
for (i = 0; i < plat->i2c_bus_count; i++) {
|
||||
if (plat->i2c_bus[i].name != NULL &&
|
||||
strncmp(i2c_name, plat->i2c_bus[i].name, strlen(plat->i2c_bus[i].name) + 1) == 0) {
|
||||
return plat->i2c_bus[i].bus_id;
|
||||
}
|
||||
if (plat->i2c_bus[i].name != NULL &&
|
||||
strncmp(i2c_name, plat->i2c_bus[i].name, strlen(plat->i2c_bus[i].name) + 1) == 0) {
|
||||
return plat->i2c_bus[i].bus_id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -968,10 +977,10 @@ mraa_spi_lookup(const char* spi_name)
|
||||
}
|
||||
|
||||
for (i = 0; i < plat->spi_bus_count; i++) {
|
||||
if (plat->spi_bus[i].name != NULL &&
|
||||
strncmp(spi_name, plat->spi_bus[i].name, strlen(plat->spi_bus[i].name) + 1) == 0) {
|
||||
return plat->spi_bus[i].bus_id;
|
||||
}
|
||||
if (plat->spi_bus[i].name != NULL &&
|
||||
strncmp(spi_name, plat->spi_bus[i].name, strlen(plat->spi_bus[i].name) + 1) == 0) {
|
||||
return plat->spi_bus[i].bus_id;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -990,10 +999,10 @@ mraa_pwm_lookup(const char* pwm_name)
|
||||
}
|
||||
|
||||
for (i = 0; i < plat->pwm_dev_count; i++) {
|
||||
if (plat->pwm_dev[i].name != NULL &&
|
||||
strncmp(pwm_name, plat->pwm_dev[i].name, strlen(plat->pwm_dev[i].name) + 1) == 0) {
|
||||
return plat->pwm_dev[i].index;
|
||||
}
|
||||
if (plat->pwm_dev[i].name != NULL &&
|
||||
strncmp(pwm_name, plat->pwm_dev[i].name, strlen(plat->pwm_dev[i].name) + 1) == 0) {
|
||||
return plat->pwm_dev[i].index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1012,10 +1021,10 @@ mraa_uart_lookup(const char* uart_name)
|
||||
}
|
||||
|
||||
for (i = 0; i < plat->uart_dev_count; i++) {
|
||||
if (plat->uart_dev[i].name != NULL &&
|
||||
strncmp(uart_name, plat->uart_dev[i].name, strlen(plat->uart_dev[i].name) + 1) == 0) {
|
||||
return plat->uart_dev[i].index;
|
||||
}
|
||||
if (plat->uart_dev[i].name != NULL &&
|
||||
strncmp(uart_name, plat->uart_dev[i].name, strlen(plat->uart_dev[i].name) + 1) == 0) {
|
||||
return plat->uart_dev[i].index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1029,9 +1038,9 @@ mraa_get_default_i2c_bus(uint8_t platform_offset)
|
||||
return plat->def_i2c_bus;
|
||||
} else {
|
||||
if (mraa_has_sub_platform())
|
||||
return plat->sub_platform->def_i2c_bus;
|
||||
return plat->sub_platform->def_i2c_bus;
|
||||
else
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1195,23 +1204,22 @@ mraa_count_i2c_files(const char* path, const struct stat* sb, int flag, struct F
|
||||
}
|
||||
|
||||
int
|
||||
mraa_find_i2c_bus_pci(const char* pci_device, const char *pci_id, const char* adapter_name)
|
||||
mraa_find_i2c_bus_pci(const char* pci_device, const char* pci_id, const char* adapter_name)
|
||||
{
|
||||
/**
|
||||
* For example we'd get something like:
|
||||
* pci0000:00/0000:00:16.3/i2c_desiignware.3
|
||||
*/
|
||||
char path[1024];
|
||||
snprintf(path, 1024-1, "/sys/devices/pci%s/%s/%s/", pci_device, pci_id, adapter_name);
|
||||
snprintf(path, 1024 - 1, "/sys/devices/pci%s/%s/%s/", pci_device, pci_id, adapter_name);
|
||||
if (mraa_file_exist(path)) {
|
||||
struct dirent **namelist;
|
||||
struct dirent** namelist;
|
||||
int n;
|
||||
n = scandir(path, &namelist, NULL, alphasort);
|
||||
if (n < 0) {
|
||||
syslog(LOG_ERR, "Failed to get information on i2c");
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (n--) {
|
||||
char* dup = strdup(namelist[n]->d_name);
|
||||
char* orig_dup = dup;
|
||||
@@ -1270,7 +1278,7 @@ mraa_find_i2c_bus(const char* devname, int startfrom)
|
||||
// i2c devices are numbered numerically so 0 must exist otherwise there is
|
||||
// no i2c-dev loaded
|
||||
if (mraa_file_exist("/sys/class/i2c-dev/i2c-0")) {
|
||||
for (;i < num_i2c_devices; i++) {
|
||||
for (; i < num_i2c_devices; i++) {
|
||||
off_t size, err;
|
||||
snprintf(path, 64, "/sys/class/i2c-dev/i2c-%u/name", i);
|
||||
fd = open(path, O_RDONLY);
|
||||
@@ -1379,8 +1387,8 @@ mraa_add_subplatform(mraa_platform_t subplatformtype, const char* dev)
|
||||
return MRAA_ERROR_FEATURE_NOT_SUPPORTED;
|
||||
}
|
||||
int i2c_bus;
|
||||
char *dev_dup = strdup(dev);
|
||||
if(mraa_atoi(dev_dup, &i2c_bus) != MRAA_SUCCESS && i2c_bus < plat->i2c_bus_count) {
|
||||
char* dev_dup = strdup(dev);
|
||||
if (mraa_atoi(dev_dup, &i2c_bus) != MRAA_SUCCESS && i2c_bus < plat->i2c_bus_count) {
|
||||
syslog(LOG_NOTICE, "mraa: Cannot add GrovePi subplatform, invalid i2c bus specified");
|
||||
free(dev_dup);
|
||||
return MRAA_ERROR_INVALID_PARAMETER;
|
||||
@@ -1443,8 +1451,9 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
|
||||
int id = -1;
|
||||
const char* uartdev = NULL;
|
||||
for (i = 0; i < subplat_num; i++) {
|
||||
struct json_object *ioobj = json_object_array_get_idx(ioarray, i);
|
||||
json_object_object_foreach(ioobj, key, val) {
|
||||
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
|
||||
json_object_object_foreach(ioobj, key, val)
|
||||
{
|
||||
if (strncmp(key, "id", strlen("id") + 1) == 0) {
|
||||
if (mraa_atoi(json_object_get_string(val), &id) != MRAA_SUCCESS) {
|
||||
id = -1;
|
||||
@@ -1465,13 +1474,12 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
|
||||
}
|
||||
if (json_object_object_get_ex(jobj_lock, "IO", &ioarray) == true &&
|
||||
json_object_is_type(ioarray, json_type_array)) {
|
||||
/* assume we have declared IO so we are preinitialised and wipe the
|
||||
* advance func array
|
||||
/* assume we have declared IO so we are preinitialised and wipe the
|
||||
* advance func array
|
||||
*/
|
||||
memset(plat->adv_func, 0, sizeof(mraa_adv_func_t));
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ret = MRAA_ERROR_INVALID_RESOURCE;
|
||||
}
|
||||
json_object_put(jobj_lock);
|
||||
@@ -1598,11 +1606,13 @@ mraa_init_io(const char* desc)
|
||||
} else if (strncmp(type, PWM_KEY, strlen(PWM_KEY) + 1) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the chip id string into a useable Int");
|
||||
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the chip id string into a "
|
||||
"useable Int");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Pwm, unable to convert the pin string into a useable Int");
|
||||
syslog(LOG_ERR,
|
||||
"mraa_init_io: Pwm, unable to convert the pin string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_pwm_init_raw(id, pin);
|
||||
@@ -1611,11 +1621,13 @@ mraa_init_io(const char* desc)
|
||||
} else if (strncmp(type, SPI_KEY, strlen(SPI_KEY) + 1) == 0) {
|
||||
if (raw) {
|
||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the bus string into a useable Int");
|
||||
syslog(LOG_ERR,
|
||||
"mraa_init_io: Spi, unable to convert the bus string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
|
||||
syslog(LOG_ERR, "mraa_init_io: Spi, unable to convert the cs string into a useable Int");
|
||||
syslog(LOG_ERR,
|
||||
"mraa_init_io: Spi, unable to convert the cs string into a useable Int");
|
||||
return NULL;
|
||||
}
|
||||
return (void*) mraa_spi_init_raw(id, pin);
|
||||
|
||||
Reference in New Issue
Block a user