Skip to content
Permalink
Browse files

clang-format: reapply to recently modified sources

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
  • Loading branch information...
Propanu committed Mar 6, 2019
1 parent 41fc378 commit 7f8d3876e3eb2a2c19f6c23f65ac7f8595abda0f
Showing with 180 additions and 162 deletions.
  1. +61 −54 src/gpio/gpio.c
  2. +10 −11 src/json/jsonplatform.c
  3. +109 −97 src/mraa.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;
Oops, something went wrong.

0 comments on commit 7f8d387

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.