Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions samples/sensor/fxos8700-hid/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,25 @@ int callbacks_configure(struct device *gpio, u32_t pin, int flags,
void (*handler)(struct device*, struct gpio_callback*,
u32_t), struct gpio_callback *callback, u32_t *val)
{
int ret;
Copy link
Contributor

@jfischer-no jfischer-no Feb 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not hurry to fix it. IMHO it would be better to change val and def_val type to int.

diff --git a/samples/sensor/fxos8700-hid/src/main.c b/samples/sensor/fxos8700-hid/src/main.c
index de587ae687..d35a24084a 100644
--- a/samples/sensor/fxos8700-hid/src/main.c
+++ b/samples/sensor/fxos8700-hid/src/main.c
@@ -60,7 +60,7 @@ LOG_MODULE_REGISTER(main);
 
 static const u8_t hid_report_desc[] = HID_MOUSE_REPORT_DESC(2);
 
-static u32_t def_val[4];
+static int def_val[4];
 static volatile u8_t status[4];
 static K_SEM_DEFINE(sem, 0, 1);        /* starts off "not available" */
 static struct gpio_callback callback[4];
@@ -77,7 +77,7 @@ static struct gpio_callback callback[4];
 static void left_button(struct device *gpio, struct gpio_callback *cb,
                        u32_t pins)
 {
-       u32_t cur_val;
+       int cur_val;
        u8_t state = status[MOUSE_BTN_REPORT_POS];
 
        cur_val = gpio_pin_get(gpio, PIN0);
@@ -97,7 +97,7 @@ static void left_button(struct device *gpio, struct gpio_callback *cb,
 static void right_button(struct device *gpio, struct gpio_callback *cb,
                         u32_t pins)
 {
-       u32_t cur_val;
+       int cur_val;
        u8_t state = status[MOUSE_BTN_REPORT_POS];
 
        cur_val = gpio_pin_get(gpio, PIN1);
@@ -116,7 +116,7 @@ static void right_button(struct device *gpio, struct gpio_callback *cb,
 
 int callbacks_configure(struct device *gpio, u32_t pin, int flags,
                        void (*handler)(struct device*, struct gpio_callback*,
-                       u32_t), struct gpio_callback *callback, u32_t *val)
+                       u32_t), struct gpio_callback *callback, int *val)
 {
        if (!gpio) {
                LOG_ERR("Could not find PORT");

But there is more to fix, L:104 should probably be if (def_val[1] != cur_val) {. left_button() and right_button() return type is void and it is not possible to forward gpio_pin_get() error.


if (!gpio) {
LOG_ERR("Could not find PORT");
return -ENXIO;
}

gpio_pin_configure(gpio, pin,
GPIO_INPUT | GPIO_INT_DEBOUNCE | flags);
*val = gpio_pin_get(gpio, pin);
if (*val < 0) {
return *val;

ret = gpio_pin_get(gpio, pin);
if (ret < 0) {
LOG_ERR("Failed to get the state of pin %u, error: %d",
pin, ret);
return ret;
}

*val = (u8_t)ret;

gpio_init_callback(callback, handler, BIT(pin));
gpio_add_callback(gpio, callback);
gpio_pin_interrupt_configure(gpio, pin, GPIO_INT_EDGE_BOTH);
Expand Down