clang-format: reapply to recently modified sources
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
@@ -23,9 +23,9 @@
|
|||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
|
#include "gpio/gpio_chardev.h"
|
||||||
#include "linux/gpio.h"
|
#include "linux/gpio.h"
|
||||||
#include "mraa_internal.h"
|
#include "mraa_internal.h"
|
||||||
#include "gpio/gpio_chardev.h"
|
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -38,8 +38,8 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
#define SYSFS_CLASS_GPIO "/sys/class/gpio"
|
||||||
#define MAX_SIZE 64
|
#define MAX_SIZE 64
|
||||||
@@ -130,15 +130,13 @@ mraa_gpio_init_internal(mraa_adv_func_t* func_table, int pin)
|
|||||||
} else {
|
} else {
|
||||||
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
int export = open(SYSFS_CLASS_GPIO "/export", O_WRONLY);
|
||||||
if (export == -1) {
|
if (export == -1) {
|
||||||
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s",
|
syslog(LOG_ERR, "gpio%i: init: Failed to open 'export' for writing: %s", pin, strerror(errno));
|
||||||
pin, strerror(errno));
|
|
||||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||||
goto init_internal_cleanup;
|
goto init_internal_cleanup;
|
||||||
}
|
}
|
||||||
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
length = snprintf(bu, sizeof(bu), "%d", dev->pin);
|
||||||
if (write(export, bu, length * sizeof(char)) == -1) {
|
if (write(export, bu, length * sizeof(char)) == -1) {
|
||||||
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s",
|
syslog(LOG_ERR, "gpio%i: init: Failed to write to 'export': %s", pin, strerror(errno));
|
||||||
pin, strerror(errno));
|
|
||||||
close(export);
|
close(export);
|
||||||
status = MRAA_ERROR_INVALID_RESOURCE;
|
status = MRAA_ERROR_INVALID_RESOURCE;
|
||||||
goto init_internal_cleanup;
|
goto init_internal_cleanup;
|
||||||
@@ -181,10 +179,8 @@ mraa_gpio_init(int pin)
|
|||||||
* example: pin 515, dev->pin = 515, dev->phy_pin = 3
|
* example: pin 515, dev->pin = 515, dev->phy_pin = 3
|
||||||
*/
|
*/
|
||||||
if (mraa_is_sub_platform_id(pin) && (board->sub_platform != NULL)) {
|
if (mraa_is_sub_platform_id(pin) && (board->sub_platform != NULL)) {
|
||||||
syslog(LOG_NOTICE, "gpio%i: initialised on sub platform '%s' physical pin: %i",
|
syslog(LOG_NOTICE, "gpio%i: initialised on sub platform '%s' physical pin: %i", pin,
|
||||||
pin,
|
board->sub_platform->platform_name != NULL ? board->sub_platform->platform_name : "",
|
||||||
board->sub_platform->platform_name != NULL ?
|
|
||||||
board->sub_platform->platform_name : "",
|
|
||||||
mraa_get_sub_platform_index(pin));
|
mraa_get_sub_platform_index(pin));
|
||||||
|
|
||||||
board = board->sub_platform;
|
board = board->sub_platform;
|
||||||
@@ -201,8 +197,7 @@ mraa_gpio_init(int pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pin < 0 || pin >= board->phy_pin_count) {
|
if (pin < 0 || pin >= board->phy_pin_count) {
|
||||||
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)",
|
syslog(LOG_ERR, "gpio: init: pin %i beyond platform pin count (%i)", pin, board->phy_pin_count);
|
||||||
pin, board->phy_pin_count);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (board->pins[pin].capabilities.gpio != 1) {
|
if (board->pins[pin].capabilities.gpio != 1) {
|
||||||
@@ -337,8 +332,8 @@ mraa_gpio_chardev_init(int pins[], int num_pins)
|
|||||||
|
|
||||||
int line_in_group;
|
int line_in_group;
|
||||||
line_in_group = gpio_group[chip_id].num_gpio_lines;
|
line_in_group = gpio_group[chip_id].num_gpio_lines;
|
||||||
gpio_group[chip_id].gpio_lines = realloc(gpio_group[chip_id].gpio_lines,
|
gpio_group[chip_id].gpio_lines =
|
||||||
(line_in_group + 1) * sizeof(unsigned int));
|
realloc(gpio_group[chip_id].gpio_lines, (line_in_group + 1) * sizeof(unsigned int));
|
||||||
if (gpio_group[chip_id].gpio_lines == NULL) {
|
if (gpio_group[chip_id].gpio_lines == NULL) {
|
||||||
syslog(LOG_CRIT, "[GPIOD_INTERFACE]: Failed to allocate memory for internal member");
|
syslog(LOG_CRIT, "[GPIOD_INTERFACE]: Failed to allocate memory for internal member");
|
||||||
mraa_gpio_close(dev);
|
mraa_gpio_close(dev);
|
||||||
@@ -466,8 +461,7 @@ mraa_gpio_wait_interrupt(int fds[],
|
|||||||
int control_fd
|
int control_fd
|
||||||
#endif
|
#endif
|
||||||
,
|
,
|
||||||
mraa_gpio_events_t events
|
mraa_gpio_events_t events)
|
||||||
)
|
|
||||||
{
|
{
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
#ifdef HAVE_PTHREAD_CANCEL
|
#ifdef HAVE_PTHREAD_CANCEL
|
||||||
@@ -564,7 +558,8 @@ mraa_gpio_get_events(mraa_gpio_context dev)
|
|||||||
unsigned int pin_idx;
|
unsigned int pin_idx;
|
||||||
mraa_gpiod_group_t gpio_iter;
|
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) {
|
for (int i = 0; i < gpio_iter->num_gpio_lines; ++i) {
|
||||||
if (dev->events[event_idx].id != -1) {
|
if (dev->events[event_idx].id != -1) {
|
||||||
pin_idx = gpio_iter->gpio_group_to_pins_table[i];
|
pin_idx = gpio_iter->gpio_group_to_pins_table[i];
|
||||||
@@ -613,12 +608,14 @@ mraa_gpio_interrupt_handler(void* arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Is this pin on a subplatform? Do nothing... */
|
/* 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? */
|
/* Is the platform chardev_capable? */
|
||||||
else if (plat->chardev_capable) {
|
else if (plat->chardev_capable) {
|
||||||
mraa_gpiod_group_t gpio_group;
|
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) {
|
for (int i = 0; i < gpio_group->num_gpio_lines; ++i) {
|
||||||
fps[idx++] = gpio_group->event_handles[i];
|
fps[idx++] = gpio_group->event_handles[i];
|
||||||
}
|
}
|
||||||
@@ -676,8 +673,7 @@ mraa_gpio_interrupt_handler(void* arg)
|
|||||||
dev->isr_control_pipe[0]
|
dev->isr_control_pipe[0]
|
||||||
#endif
|
#endif
|
||||||
,
|
,
|
||||||
dev->events
|
dev->events);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -977,8 +973,10 @@ mraa_gpio_mode(mraa_gpio_context dev, mraa_gpio_mode_t mode)
|
|||||||
_mraa_close_gpio_desc(dev);
|
_mraa_close_gpio_desc(dev);
|
||||||
|
|
||||||
/* We save flag values from the first valid line. */
|
/* We save flag values from the first valid line. */
|
||||||
for_each_gpio_group(gpio_iter, dev) {
|
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]);
|
{
|
||||||
|
mraa_gpiod_line_info* linfo =
|
||||||
|
mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||||
if (!linfo) {
|
if (!linfo) {
|
||||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
||||||
return MRAA_ERROR_UNSPECIFIED;
|
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;
|
return MRAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
for_each_gpio_group(gpio_iter, dev) {
|
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);
|
{
|
||||||
|
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) {
|
if (line_handle <= 0) {
|
||||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line handle");
|
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line handle");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
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;
|
unsigned flags = 0;
|
||||||
mraa_gpiod_group_t gpio_iter;
|
mraa_gpiod_group_t gpio_iter;
|
||||||
|
|
||||||
for_each_gpio_group(gpio_iter, dev) {
|
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]);
|
{
|
||||||
|
mraa_gpiod_line_info* linfo =
|
||||||
|
mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||||
if (!linfo) {
|
if (!linfo) {
|
||||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
||||||
return MRAA_ERROR_UNSPECIFIED;
|
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;
|
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) {
|
if (gpio_iter->gpiod_handle != -1) {
|
||||||
close(gpio_iter->gpiod_handle);
|
close(gpio_iter->gpiod_handle);
|
||||||
gpio_iter->gpiod_handle = -1;
|
gpio_iter->gpiod_handle = -1;
|
||||||
@@ -1216,8 +1219,10 @@ mraa_gpio_read_dir(mraa_gpio_context dev, mraa_gpio_dir_t *dir)
|
|||||||
if (plat->chardev_capable) {
|
if (plat->chardev_capable) {
|
||||||
mraa_gpiod_group_t gpio_iter;
|
mraa_gpiod_group_t gpio_iter;
|
||||||
|
|
||||||
for_each_gpio_group(gpio_iter, dev) {
|
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]);
|
{
|
||||||
|
mraa_gpiod_line_info* linfo =
|
||||||
|
mraa_get_line_info_by_chip_number(gpio_iter->gpio_chip, gpio_iter->gpio_lines[0]);
|
||||||
if (!linfo) {
|
if (!linfo) {
|
||||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error getting line info");
|
||||||
return MRAA_ERROR_UNSPECIFIED;
|
return MRAA_ERROR_UNSPECIFIED;
|
||||||
@@ -1314,8 +1319,8 @@ mraa_gpio_read(mraa_gpio_context dev)
|
|||||||
}
|
}
|
||||||
char bu[2];
|
char bu[2];
|
||||||
if (read(dev->value_fp, bu, 2 * sizeof(char)) != 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",
|
syslog(LOG_ERR, "gpio%i: read: Failed to read a sensible value from sysfs: %s", dev->pin,
|
||||||
dev->pin, strerror(errno));
|
strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
lseek(dev->value_fp, 0, SEEK_SET);
|
lseek(dev->value_fp, 0, SEEK_SET);
|
||||||
@@ -1336,7 +1341,8 @@ mraa_gpio_read_multi(mraa_gpio_context dev, int output_values[])
|
|||||||
|
|
||||||
mraa_gpiod_group_t gpio_iter;
|
mraa_gpiod_group_t gpio_iter;
|
||||||
|
|
||||||
for_each_gpio_group(gpio_iter, dev) {
|
for_each_gpio_group(gpio_iter, dev)
|
||||||
|
{
|
||||||
int status;
|
int status;
|
||||||
unsigned flags = GPIOHANDLE_REQUEST_INPUT;
|
unsigned flags = GPIOHANDLE_REQUEST_INPUT;
|
||||||
|
|
||||||
@@ -1349,8 +1355,8 @@ mraa_gpio_read_multi(mraa_gpio_context dev, int output_values[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = mraa_get_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines,
|
status =
|
||||||
gpio_iter->rw_values);
|
mraa_get_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines, gpio_iter->rw_values);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error writing gpio");
|
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error writing gpio");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
@@ -1460,7 +1466,8 @@ mraa_gpio_write_multi(mraa_gpio_context dev, int input_values[])
|
|||||||
}
|
}
|
||||||
free(counters);
|
free(counters);
|
||||||
|
|
||||||
for_each_gpio_group(gpio_iter, dev) {
|
for_each_gpio_group(gpio_iter, dev)
|
||||||
|
{
|
||||||
int status;
|
int status;
|
||||||
unsigned flags = GPIOHANDLE_REQUEST_OUTPUT;
|
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,
|
status =
|
||||||
gpio_iter->rw_values);
|
mraa_set_line_values(gpio_iter->gpiod_handle, gpio_iter->num_gpio_lines, gpio_iter->rw_values);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error writing gpio");
|
syslog(LOG_ERR, "[GPIOD_INTERFACE]: error writing gpio");
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
|
|||||||
@@ -23,14 +23,14 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "mraa_internal.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);
|
*pos = (int) json_object_get_int(jobj_temp);
|
||||||
if (*pos < 0 || *pos > upper) {
|
if (*pos < 0 || *pos > upper) {
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR, "init_json_platform: %s %s at position: %d, gave: %d which was out of range",
|
||||||
"init_json_platform: %s %s at position: %d, gave: %d which was out of range", io,
|
io, key, index, *pos);
|
||||||
key, index, *pos);
|
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
return MRAA_SUCCESS;
|
return MRAA_SUCCESS;
|
||||||
@@ -559,7 +558,8 @@ mraa_init_json_platform_loop(json_object* jobj_platform, const char* obj_key, mr
|
|||||||
jobj_io = json_object_array_get_idx(jobj_temp, i);
|
jobj_io = json_object_array_get_idx(jobj_temp, i);
|
||||||
// Check to see it's the right type
|
// Check to see it's the right type
|
||||||
if (!json_object_is_type(jobj_io, json_type_object)) {
|
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\" "
|
syslog(LOG_ERR,
|
||||||
|
"init_json_platform: One of more of the elements in the \"%s\" "
|
||||||
"array where not JSON objects",
|
"array where not JSON objects",
|
||||||
obj_key);
|
obj_key);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
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
|
// make sure we don't have more than our range
|
||||||
array_length = json_object_array_length(jobj_temp);
|
array_length = json_object_array_length(jobj_temp);
|
||||||
if (array_length > range) {
|
if (array_length > range) {
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR, "init_json_platform: The size of the %s array given was %d, max was: %d",
|
||||||
"init_json_platform: The size of the %s array given was %d, max was: %d",
|
|
||||||
obj_key, array_length, range);
|
obj_key, array_length, range);
|
||||||
return MRAA_ERROR_INVALID_RESOURCE;
|
return MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
|
|||||||
98
src/mraa.c
98
src/mraa.c
@@ -28,43 +28,43 @@
|
|||||||
#define _XOPEN_SOURCE 600 /* Get nftw() and S_IFSOCK declarations */
|
#define _XOPEN_SOURCE 600 /* Get nftw() and S_IFSOCK declarations */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#if !defined(PERIPHERALMAN)
|
#if !defined(PERIPHERALMAN)
|
||||||
#include <glob.h>
|
|
||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
|
#include <glob.h>
|
||||||
#endif
|
#endif
|
||||||
#include <dirent.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#if defined(IMRAA)
|
#if defined(IMRAA)
|
||||||
#include <json-c/json.h>
|
#include <json-c/json.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mraa_internal.h"
|
#include "aio.h"
|
||||||
#include "firmata/firmata_mraa.h"
|
#include "firmata/firmata_mraa.h"
|
||||||
#include "grovepi/grovepi.h"
|
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "gpio/gpio_chardev.h"
|
#include "gpio/gpio_chardev.h"
|
||||||
#include "version.h"
|
#include "grovepi/grovepi.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
#include "mraa_internal.h"
|
||||||
#include "pwm.h"
|
#include "pwm.h"
|
||||||
#include "aio.h"
|
|
||||||
#include "spi.h"
|
#include "spi.h"
|
||||||
#include "uart.h"
|
#include "uart.h"
|
||||||
|
#include "version.h"
|
||||||
|
|
||||||
#if defined(PERIPHERALMAN)
|
#if defined(PERIPHERALMAN)
|
||||||
#include "peripheralmanager/peripheralman.h"
|
#include "peripheralmanager/peripheralman.h"
|
||||||
@@ -100,17 +100,20 @@ mraa_set_log_level(int level)
|
|||||||
return MRAA_ERROR_INVALID_PARAMETER;
|
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) {
|
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 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
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)) {
|
if ((plat != NULL) && (plat->chardev_capable)) {
|
||||||
return mraa_is_kernel_chardev_interface_compatible();
|
return mraa_is_kernel_chardev_interface_compatible();
|
||||||
@@ -202,8 +205,7 @@ imraa_init()
|
|||||||
/* If a usb platform lib is present, attempt to load and look for
|
/* If a usb platform lib is present, attempt to load and look for
|
||||||
* necessary symbols for adding extended I/O */
|
* necessary symbols for adding extended I/O */
|
||||||
void* usblib = dlopen("libmraa-platform-ft4222.so", RTLD_LAZY);
|
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, "Found USB platform extender library: libmraa-platform-ft4222.so");
|
||||||
syslog(LOG_NOTICE, "Detecting FT4222 subplatforms...");
|
syslog(LOG_NOTICE, "Detecting FT4222 subplatforms...");
|
||||||
fptr_add_platform_extender add_ft4222_platform =
|
fptr_add_platform_extender add_ft4222_platform =
|
||||||
@@ -211,8 +213,7 @@ imraa_init()
|
|||||||
|
|
||||||
/* If this method exists, call it to add a subplatform */
|
/* If this method exists, call it to add a subplatform */
|
||||||
syslog(LOG_NOTICE, "Detecting FT4222 subplatforms complete, found %i subplatform/s",
|
syslog(LOG_NOTICE, "Detecting FT4222 subplatforms complete, found %i subplatform/s",
|
||||||
((add_ft4222_platform != NULL) && (add_ft4222_platform(plat) == MRAA_SUCCESS))
|
((add_ft4222_platform != NULL) && (add_ft4222_platform(plat) == MRAA_SUCCESS)) ? 1 : 0);
|
||||||
? 1 : 0);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -250,7 +251,8 @@ imraa_init()
|
|||||||
syslog(LOG_NOTICE, "gpio: support for chardev interface is activated");
|
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;
|
return MRAA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -300,8 +302,7 @@ mraa_deinit()
|
|||||||
* allocate space for device_path, others use #defines or consts,
|
* allocate space for device_path, others use #defines or consts,
|
||||||
* which means this has to be handled differently per platform
|
* which means this has to be handled differently per platform
|
||||||
*/
|
*/
|
||||||
if ((plat->platform_type == MRAA_JSON_PLATFORM) ||
|
if ((plat->platform_type == MRAA_JSON_PLATFORM) || (plat->platform_type == MRAA_UP2) ||
|
||||||
(plat->platform_type == MRAA_UP2) ||
|
|
||||||
(plat->platform_type == MRAA_IEI_TANK)) {
|
(plat->platform_type == MRAA_IEI_TANK)) {
|
||||||
for (i = 0; i < plat->uart_dev_count; i++) {
|
for (i = 0; i < plat->uart_dev_count; i++) {
|
||||||
if (plat->uart_dev[i].device_path != NULL) {
|
if (plat->uart_dev[i].device_path != NULL) {
|
||||||
@@ -417,7 +418,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
mraa_gpio_close(mux_i);
|
mraa_gpio_close(mux_i);
|
||||||
}
|
}
|
||||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
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;
|
last_pin = meta.mux[mi].pin;
|
||||||
}
|
}
|
||||||
// this function will sometimes fail, however this is not critical as
|
// this function will sometimes fail, however this is not critical as
|
||||||
@@ -440,7 +442,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
mraa_gpio_close(mux_i);
|
mraa_gpio_close(mux_i);
|
||||||
}
|
}
|
||||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
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;
|
last_pin = meta.mux[mi].pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,7 +465,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
mraa_gpio_close(mux_i);
|
mraa_gpio_close(mux_i);
|
||||||
}
|
}
|
||||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
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;
|
last_pin = meta.mux[mi].pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -484,7 +488,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
mraa_gpio_close(mux_i);
|
mraa_gpio_close(mux_i);
|
||||||
}
|
}
|
||||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
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;
|
last_pin = meta.mux[mi].pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -509,7 +514,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
mraa_gpio_close(mux_i);
|
mraa_gpio_close(mux_i);
|
||||||
}
|
}
|
||||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
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;
|
last_pin = meta.mux[mi].pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,7 +540,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
mraa_gpio_close(mux_i);
|
mraa_gpio_close(mux_i);
|
||||||
}
|
}
|
||||||
mux_i = mraa_gpio_init_raw(meta.mux[mi].pin);
|
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;
|
last_pin = meta.mux[mi].pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +560,8 @@ mraa_setup_mux_mapped(mraa_pin_t meta)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -654,7 +662,8 @@ mraa_pin_mode_test(int pin, mraa_pinmodes_t mode)
|
|||||||
pin = mraa_get_sub_platform_index(pin);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
|
if (pin > (current_plat->phy_pin_count - 1) || pin < 0)
|
||||||
@@ -1210,8 +1219,7 @@ mraa_find_i2c_bus_pci(const char* pci_device, const char *pci_id, const char* ad
|
|||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
syslog(LOG_ERR, "Failed to get information on i2c");
|
syslog(LOG_ERR, "Failed to get information on i2c");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
while (n--) {
|
while (n--) {
|
||||||
char* dup = strdup(namelist[n]->d_name);
|
char* dup = strdup(namelist[n]->d_name);
|
||||||
char* orig_dup = dup;
|
char* orig_dup = dup;
|
||||||
@@ -1444,7 +1452,8 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
|
|||||||
const char* uartdev = NULL;
|
const char* uartdev = NULL;
|
||||||
for (i = 0; i < subplat_num; i++) {
|
for (i = 0; i < subplat_num; i++) {
|
||||||
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
|
struct json_object* ioobj = json_object_array_get_idx(ioarray, i);
|
||||||
json_object_object_foreach(ioobj, key, val) {
|
json_object_object_foreach(ioobj, key, val)
|
||||||
|
{
|
||||||
if (strncmp(key, "id", strlen("id") + 1) == 0) {
|
if (strncmp(key, "id", strlen("id") + 1) == 0) {
|
||||||
if (mraa_atoi(json_object_get_string(val), &id) != MRAA_SUCCESS) {
|
if (mraa_atoi(json_object_get_string(val), &id) != MRAA_SUCCESS) {
|
||||||
id = -1;
|
id = -1;
|
||||||
@@ -1470,8 +1479,7 @@ mraa_add_from_lockfile(const char* imraa_lock_file)
|
|||||||
*/
|
*/
|
||||||
memset(plat->adv_func, 0, sizeof(mraa_adv_func_t));
|
memset(plat->adv_func, 0, sizeof(mraa_adv_func_t));
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ret = MRAA_ERROR_INVALID_RESOURCE;
|
ret = MRAA_ERROR_INVALID_RESOURCE;
|
||||||
}
|
}
|
||||||
json_object_put(jobj_lock);
|
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) {
|
} else if (strncmp(type, PWM_KEY, strlen(PWM_KEY) + 1) == 0) {
|
||||||
if (raw) {
|
if (raw) {
|
||||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
|
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 NULL;
|
||||||
}
|
}
|
||||||
return (void*) mraa_pwm_init_raw(id, pin);
|
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) {
|
} else if (strncmp(type, SPI_KEY, strlen(SPI_KEY) + 1) == 0) {
|
||||||
if (raw) {
|
if (raw) {
|
||||||
if (mraa_init_io_helper(&str, &id, delim) != MRAA_SUCCESS) {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (mraa_init_io_helper(&str, &pin, delim) != MRAA_SUCCESS) {
|
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 NULL;
|
||||||
}
|
}
|
||||||
return (void*) mraa_spi_init_raw(id, pin);
|
return (void*) mraa_spi_init_raw(id, pin);
|
||||||
|
|||||||
Reference in New Issue
Block a user