diff --git a/boards/arm/reel_board/dts/reel_board.dtsi b/boards/arm/reel_board/dts/reel_board.dtsi index 1e23aa7e71c5b..8e65430c0358e 100644 --- a/boards/arm/reel_board/dts/reel_board.dtsi +++ b/boards/arm/reel_board/dts/reel_board.dtsi @@ -9,15 +9,15 @@ leds { compatible = "gpio-leds"; red_led: led_0 { - gpios = <&gpio0 11 0>; + gpios = <&gpio0 11 GPIO_ACTIVE_LOW>; label = "User D3 red"; }; green_led: led_1 { - gpios = <&gpio0 12 0>; + gpios = <&gpio0 12 GPIO_ACTIVE_LOW>; label = "User D3 green"; }; blue_led: led_2 { - gpios = <&gpio1 9 0>; + gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; label = "User D3 blue"; }; }; @@ -38,7 +38,7 @@ gpio_keys { compatible = "gpio-keys"; user_button: button_0 { - gpios = <&gpio0 7 GPIO_PUD_PULL_UP>; + gpios = <&gpio0 7 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "User Button"; }; }; diff --git a/boards/arm/reel_board/reel_board.dts b/boards/arm/reel_board/reel_board.dts index 17fba78fc85b5..f8b5b23a47098 100644 --- a/boards/arm/reel_board/reel_board.dts +++ b/boards/arm/reel_board/reel_board.dts @@ -28,7 +28,7 @@ leds { compatible = "gpio-leds"; back_led: led_3 { - gpios = <&gpio0 13 0>; + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; label = "User D13 green"; }; }; diff --git a/samples/boards/reel_board/mesh_badge/src/board.h b/samples/boards/reel_board/mesh_badge/src/board.h index 64509b0ee1b1b..3b9f6c5f90268 100644 --- a/samples/boards/reel_board/mesh_badge/src/board.h +++ b/samples/boards/reel_board/mesh_badge/src/board.h @@ -5,15 +5,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -enum led_periph_device { - DEV_IDX_LED0 = 0, - DEV_IDX_LED1, - DEV_IDX_LED2, -}; - enum periph_device { - DEV_IDX_BUTTON = 0, - DEV_IDX_HDC1010, + DEV_IDX_HDC1010 = 0, DEV_IDX_MMA8652, DEV_IDX_APDS9960, DEV_IDX_EPD, diff --git a/samples/boards/reel_board/mesh_badge/src/mesh.c b/samples/boards/reel_board/mesh_badge/src/mesh.c index 0787b7adb0839..63efc8fd76008 100644 --- a/samples/boards/reel_board/mesh_badge/src/mesh.c +++ b/samples/boards/reel_board/mesh_badge/src/mesh.c @@ -62,7 +62,8 @@ static struct k_work mesh_start_work; /* Definitions of models user data (Start) */ static struct led_onoff_state led_onoff_state[] = { - { .dev_id = DEV_IDX_LED0 }, + /* Use LED 0 for this model */ + { .dev_id = 0 }, }; static void heartbeat(u8_t hops, u16_t feat) @@ -155,7 +156,6 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model, printk("addr 0x%02x state 0x%02x\n", bt_mesh_model_elem(model)->addr, state->current); - /* Pin set low turns on LED's on the reel board */ if (set_led_state(state->dev_id, onoff)) { printk("Failed to set led state\n"); diff --git a/samples/boards/reel_board/mesh_badge/src/periphs.c b/samples/boards/reel_board/mesh_badge/src/periphs.c index f5c0b4e6c34ef..b99f3143d7006 100644 --- a/samples/boards/reel_board/mesh_badge/src/periphs.c +++ b/samples/boards/reel_board/mesh_badge/src/periphs.c @@ -17,54 +17,13 @@ struct device_info { char *name; }; -struct led_device_info { - struct device *dev; - char *name; - u32_t pin; -}; - -static struct led_device_info led_dev_info[] = { - /* red front LED */ - { NULL, DT_ALIAS_LED0_GPIOS_CONTROLLER, DT_ALIAS_LED0_GPIOS_PIN }, - /* green front LED */ - { NULL, DT_ALIAS_LED1_GPIOS_CONTROLLER, DT_ALIAS_LED1_GPIOS_PIN }, - /* blue front LED */ - { NULL, DT_ALIAS_LED2_GPIOS_CONTROLLER, DT_ALIAS_LED2_GPIOS_PIN }, -}; - static struct device_info dev_info[] = { - { NULL, DT_ALIAS_SW0_GPIOS_CONTROLLER }, { NULL, DT_INST_0_TI_HDC1010_LABEL }, { NULL, DT_INST_0_NXP_MMA8652FC_LABEL }, { NULL, DT_INST_0_AVAGO_APDS9960_LABEL }, { NULL, DT_INST_0_SOLOMON_SSD16XXFB_LABEL }, }; -static void configure_gpios(void) -{ - gpio_pin_configure(led_dev_info[DEV_IDX_LED0].dev, - led_dev_info[DEV_IDX_LED0].pin, GPIO_DIR_OUT); - gpio_pin_write(led_dev_info[DEV_IDX_LED0].dev, - led_dev_info[DEV_IDX_LED0].pin, 1); - - gpio_pin_configure(led_dev_info[DEV_IDX_LED1].dev, - led_dev_info[DEV_IDX_LED1].pin, GPIO_DIR_OUT); - gpio_pin_write(led_dev_info[DEV_IDX_LED1].dev, - led_dev_info[DEV_IDX_LED1].pin, 1); - - gpio_pin_configure(led_dev_info[DEV_IDX_LED2].dev, - led_dev_info[DEV_IDX_LED2].pin, GPIO_DIR_OUT); - gpio_pin_write(led_dev_info[DEV_IDX_LED2].dev, - led_dev_info[DEV_IDX_LED2].pin, 1); -} - -int set_led_state(u8_t id, bool state) -{ - /* Invert state because of active low state for GPIO LED pins */ - return gpio_pin_write(led_dev_info[id].dev, led_dev_info[id].pin, - !state); -} - int get_hdc1010_val(struct sensor_value *val) { if (sensor_sample_fetch(dev_info[DEV_IDX_HDC1010].dev)) { @@ -195,18 +154,6 @@ int periphs_init(void) } } - /* Bind leds */ - for (i = 0U; i < ARRAY_SIZE(led_dev_info); i++) { - led_dev_info[i].dev = device_get_binding(led_dev_info[i].name); - if (led_dev_info[i].dev == NULL) { - printk("Failed to get %s led device\n", - led_dev_info[i].name); - return -EBUSY; - } - } - - configure_gpios(); - configure_accel(); return 0; diff --git a/samples/boards/reel_board/mesh_badge/src/reel_board.c b/samples/boards/reel_board/mesh_badge/src/reel_board.c index e0aaf7168f38f..8649303f6b6a0 100644 --- a/samples/boards/reel_board/mesh_badge/src/reel_board.c +++ b/samples/boards/reel_board/mesh_badge/src/reel_board.c @@ -47,8 +47,6 @@ struct font_info { #define STAT_COUNT 128 -#define EDGE (GPIO_INT_EDGE | GPIO_INT_DOUBLE_EDGE) - #ifdef DT_ALIAS_SW0_GPIOS_FLAGS #define PULL_UP DT_ALIAS_SW0_GPIOS_FLAGS #else @@ -66,11 +64,15 @@ static char str_buf[256]; static struct { struct device *dev; const char *name; - u32_t pin; + gpio_pin_t pin; + gpio_flags_t flags; } leds[] = { - { .name = DT_ALIAS_LED0_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED0_GPIOS_PIN, }, - { .name = DT_ALIAS_LED1_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED1_GPIOS_PIN, }, - { .name = DT_ALIAS_LED2_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED2_GPIOS_PIN, }, + { .name = DT_ALIAS_LED0_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED0_GPIOS_PIN, + .flags = DT_ALIAS_LED0_GPIOS_FLAGS}, + { .name = DT_ALIAS_LED1_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED1_GPIOS_PIN, + .flags = DT_ALIAS_LED1_GPIOS_FLAGS}, + { .name = DT_ALIAS_LED2_GPIOS_CONTROLLER, .pin = DT_ALIAS_LED2_GPIOS_PIN, + .flags = DT_ALIAS_LED2_GPIOS_FLAGS} }; struct k_delayed_work led_timer; @@ -444,11 +446,7 @@ static void long_press(struct k_work *work) static bool button_is_pressed(void) { - u32_t val; - - gpio_pin_read(gpio, DT_ALIAS_SW0_GPIOS_PIN, &val); - - return !val; + return gpio_pin_get(gpio, DT_ALIAS_SW0_GPIOS_PIN) > 0; } static void button_interrupt(struct device *dev, struct gpio_callback *cb, @@ -517,16 +515,24 @@ static int configure_button(void) } gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN, - (GPIO_DIR_IN | GPIO_INT | PULL_UP | EDGE)); + GPIO_INPUT | DT_ALIAS_SW0_GPIOS_FLAGS); - gpio_init_callback(&button_cb, button_interrupt, BIT(DT_ALIAS_SW0_GPIOS_PIN)); - gpio_add_callback(gpio, &button_cb); + gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN, + GPIO_INT_EDGE_BOTH); + + gpio_init_callback(&button_cb, button_interrupt, + BIT(DT_ALIAS_SW0_GPIOS_PIN)); - gpio_pin_enable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN); + gpio_add_callback(gpio, &button_cb); return 0; } +int set_led_state(u8_t id, bool state) +{ + return gpio_pin_set(leds[id].dev, leds[id].pin, state); +} + static void led_timeout(struct k_work *work) { static int led_cntr; @@ -534,7 +540,7 @@ static void led_timeout(struct k_work *work) /* Disable all LEDs */ for (i = 0; i < ARRAY_SIZE(leds); i++) { - gpio_pin_write(leds[i].dev, leds[i].pin, 1); + set_led_state(i, 0); } /* Stop after 5 iterations */ @@ -545,7 +551,7 @@ static void led_timeout(struct k_work *work) /* Select and enable current LED */ i = led_cntr++ % ARRAY_SIZE(leds); - gpio_pin_write(leds[i].dev, leds[i].pin, 0); + set_led_state(i, 1); k_delayed_work_submit(&led_timer, K_MSEC(100)); } @@ -561,9 +567,9 @@ static int configure_leds(void) return -ENODEV; } - gpio_pin_configure(leds[i].dev, leds[i].pin, GPIO_DIR_OUT); - gpio_pin_write(leds[i].dev, leds[i].pin, 1); - + gpio_pin_configure(leds[i].dev, leds[i].pin, + leds[i].flags | + GPIO_OUTPUT_INACTIVE); } k_delayed_work_init(&led_timer, led_timeout);