samples: Convert DT_ALIAS_* to new DT_ALIAS() macro

Convert DT_ALIAS_* defines to use DT_ALIAS() plus other macros from
include/devicetree.h.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-04-29 12:27:19 -05:00 committed by Kumar Gala
parent cdd629cda2
commit 4e93b77552
36 changed files with 426 additions and 365 deletions

View file

@ -15,12 +15,13 @@
#include <device.h>
#include <drivers/pwm.h>
#if defined(DT_ALIAS_PWM_LED0_PWMS_CONTROLLER) && defined(DT_ALIAS_PWM_LED0_PWMS_CHANNEL)
#if DT_NODE_HAS_PROP(DT_ALIAS(pwm_led0), pwms) && \
DT_PHA_HAS_CELL(DT_ALIAS(pwm_led0), pwms, channel)
/* get the defines from dt (based on alias 'pwm-led0') */
#define PWM_DRIVER DT_ALIAS_PWM_LED0_PWMS_CONTROLLER
#define PWM_CHANNEL DT_ALIAS_PWM_LED0_PWMS_CHANNEL
#ifdef DT_ALIAS_PWM_LED0_PWMS_FLAGS
#define PWM_FLAGS DT_ALIAS_PWM_LED0_PWMS_FLAGS
#define PWM_DRIVER DT_PWMS_LABEL(DT_ALIAS(pwm_led0))
#define PWM_CHANNEL DT_PWMS_CHANNEL(DT_ALIAS(pwm_led0))
#if DT_PHA_HAS_CELL(DT_ALIAS(pwm_led0), pwms, flags)
#define PWM_FLAGS DT_PWMS_FLAGS(DT_ALIAS(pwm_led0))
#else
#define PWM_FLAGS 0
#endif

View file

@ -18,8 +18,8 @@ have defined the SW0_* variables.
To use this sample, you will require a board that defines the user switch in its
header file. The :file:`board.h` must define the following variables:
- SW0_GPIO_NAME (or DT_ALIAS_SW0_GPIOS_CONTROLLER)
- DT_ALIAS_SW0_GPIOS_PIN
- SW0_GPIO_NAME (or DT_GPIO_LABEL(DT_ALIAS(sw0), gpios))
- DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
Alternatively, this could also be done by defining 'sw0' alias in the board
devicetree description file.

View file

@ -13,14 +13,14 @@
#define SLEEP_TIME_MS 1
#ifdef DT_ALIAS_SW0_GPIOS_FLAGS
#define SW0_FLAGS DT_ALIAS_SW0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, flags)
#define SW0_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
#else
#define SW0_FLAGS 0
#endif
#ifdef DT_ALIAS_LED0_GPIOS_FLAGS
#define LED0_FLAGS DT_ALIAS_LED0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(led0), gpios, flags)
#define LED0_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
#else
#define LED0_FLAGS 0
#endif
@ -38,59 +38,63 @@ void main(void)
struct device *dev_button;
int ret;
dev_button = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
dev_button = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
if (dev_button == NULL) {
printk("Error: didn't find %s device\n",
DT_ALIAS_SW0_GPIOS_CONTROLLER);
DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
return;
}
ret = gpio_pin_configure(dev_button, DT_ALIAS_SW0_GPIOS_PIN,
ret = gpio_pin_configure(dev_button, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
SW0_FLAGS | GPIO_INPUT);
if (ret != 0) {
printk("Error %d: failed to configure pin %d '%s'\n",
ret, DT_ALIAS_SW0_GPIOS_PIN, DT_ALIAS_SW0_LABEL);
ret, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
DT_LABEL(DT_ALIAS(sw0)));
return;
}
ret = gpio_pin_interrupt_configure(dev_button, DT_ALIAS_SW0_GPIOS_PIN,
ret = gpio_pin_interrupt_configure(dev_button,
DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
if (ret != 0) {
printk("Error %d: failed to configure interrupt on pin %d '%s'\n",
ret, DT_ALIAS_SW0_GPIOS_PIN, DT_ALIAS_SW0_LABEL);
ret, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
DT_LABEL(DT_ALIAS(sw0)));
return;
}
gpio_init_callback(&button_cb_data, button_pressed,
BIT(DT_ALIAS_SW0_GPIOS_PIN));
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)));
gpio_add_callback(dev_button, &button_cb_data);
#ifdef DT_ALIAS_LED0_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
struct device *dev_led;
dev_led = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
dev_led = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
if (dev_led == NULL) {
printk("Error: didn't find %s device\n",
DT_ALIAS_LED0_GPIOS_CONTROLLER);
DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
return;
}
ret = gpio_pin_configure(dev_led, DT_ALIAS_LED0_GPIOS_PIN,
ret = gpio_pin_configure(dev_led, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
LED0_FLAGS | GPIO_OUTPUT);
if (ret != 0) {
printk("Error %d: failed to configure pin %d '%s'\n",
ret, DT_ALIAS_LED0_GPIOS_PIN, DT_ALIAS_LED0_LABEL);
ret, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
DT_LABEL(DT_ALIAS(led0)));
return;
}
#endif
printk("Press %s on the board\n", DT_ALIAS_SW0_LABEL);
printk("Press %s on the board\n", DT_LABEL(DT_ALIAS(sw0)));
while (1) {
#ifdef DT_ALIAS_LED0_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
bool val;
val = gpio_pin_get(dev_button, DT_ALIAS_SW0_GPIOS_PIN);
gpio_pin_set(dev_led, DT_ALIAS_LED0_GPIOS_PIN, val);
val = gpio_pin_get(dev_button, DT_GPIO_PIN(DT_ALIAS(sw0), gpios));
gpio_pin_set(dev_led, DT_GPIO_PIN(DT_ALIAS(led0), gpios), val);
k_msleep(SLEEP_TIME_MS);
#endif
}

View file

@ -15,12 +15,13 @@
#include <device.h>
#include <drivers/pwm.h>
#if defined(DT_ALIAS_PWM_LED0_PWMS_CONTROLLER) && defined(DT_ALIAS_PWM_LED0_PWMS_CHANNEL)
#if DT_NODE_HAS_PROP(DT_ALIAS(pwm_led0), pwms) && \
DT_PHA_HAS_CELL(DT_ALIAS(pwm_led0), pwms, channel)
/* get the defines from dt (based on alias 'pwm-led0') */
#define PWM_DRIVER DT_ALIAS_PWM_LED0_PWMS_CONTROLLER
#define PWM_CHANNEL DT_ALIAS_PWM_LED0_PWMS_CHANNEL
#ifdef DT_ALIAS_PWM_LED0_PWMS_FLAGS
#define PWM_FLAGS DT_ALIAS_PWM_LED0_PWMS_FLAGS
#define PWM_DRIVER DT_PWMS_LABEL(DT_ALIAS(pwm_led0))
#define PWM_CHANNEL DT_PWMS_CHANNEL(DT_ALIAS(pwm_led0))
#if DT_PHA_HAS_CELL(DT_ALIAS(pwm_led0), pwms, flags)
#define PWM_FLAGS DT_PWMS_FLAGS(DT_ALIAS(pwm_led0))
#else
#define PWM_FLAGS 0
#endif

View file

@ -15,33 +15,33 @@
#include <device.h>
#include <drivers/pwm.h>
#if defined(DT_ALIAS_RED_PWM_LED_PWMS_CONTROLLER) && \
defined(DT_ALIAS_RED_PWM_LED_PWMS_CHANNEL) && \
defined(DT_ALIAS_GREEN_PWM_LED_PWMS_CONTROLLER) && \
defined(DT_ALIAS_GREEN_PWM_LED_PWMS_CHANNEL) && \
defined(DT_ALIAS_BLUE_PWM_LED_PWMS_CONTROLLER) && \
defined(DT_ALIAS_BLUE_PWM_LED_PWMS_CHANNEL)
#if DT_NODE_HAS_PROP(DT_ALIAS(red_pwm_led), pwms) && \
DT_PHA_HAS_CELL(DT_ALIAS(red_pwm_led), pwms, channel) && \
DT_NODE_HAS_PROP(DT_ALIAS(green_pwm_led), pwms) && \
DT_PHA_HAS_CELL(DT_ALIAS(green_pwm_led), pwms, channel) && \
DT_NODE_HAS_PROP(DT_ALIAS(blue_pwm_led), pwms) && \
DT_PHA_HAS_CELL(DT_ALIAS(blue_pwm_led), pwms, channel)
/* Get the defines from dt (based on aliases 'red-pwm-led', 'green-pwm-led' &
* 'blue-pwm-led')
*/
#define PWM_DEV0 DT_ALIAS_RED_PWM_LED_PWMS_CONTROLLER
#define PWM_CH0 DT_ALIAS_RED_PWM_LED_PWMS_CHANNEL
#ifdef DT_ALIAS_RED_PWM_LED_PWMS_FLAGS
#define PWM_FLAGS0 DT_ALIAS_RED_PWM_LED_PWMS_FLAGS
#define PWM_DEV0 DT_PWMS_LABEL(DT_ALIAS(red_pwm_led))
#define PWM_CH0 DT_PWMS_CHANNEL(DT_ALIAS(red_pwm_led))
#if DT_PHA_HAS_CELL(DT_ALIAS(red_pwm_led), pwms, flags)
#define PWM_FLAGS0 DT_PWMS_FLAGS(DT_ALIAS(red_pwm_led))
#else
#define PWM_FLAGS0 0
#endif
#define PWM_DEV1 DT_ALIAS_GREEN_PWM_LED_PWMS_CONTROLLER
#define PWM_CH1 DT_ALIAS_GREEN_PWM_LED_PWMS_CHANNEL
#ifdef DT_ALIAS_GREEN_PWM_LED_PWMS_FLAGS
#define PWM_FLAGS1 DT_ALIAS_GREEN_PWM_LED_PWMS_FLAGS
#define PWM_DEV1 DT_PWMS_LABEL(DT_ALIAS(green_pwm_led))
#define PWM_CH1 DT_PWMS_CHANNEL(DT_ALIAS(green_pwm_led))
#if DT_PHA_HAS_CELL(DT_ALIAS(green_pwm_led), pwms, flags)
#define PWM_FLAGS1 DT_PWMS_FLAGS(DT_ALIAS(green_pwm_led))
#else
#define PWM_FLAGS1 0
#endif
#define PWM_DEV2 DT_ALIAS_BLUE_PWM_LED_PWMS_CONTROLLER
#define PWM_CH2 DT_ALIAS_BLUE_PWM_LED_PWMS_CHANNEL
#ifdef DT_ALIAS_BLUE_PWM_LED_PWMS_FLAGS
#define PWM_FLAGS2 DT_ALIAS_BLUE_PWM_LED_PWMS_FLAGS
#define PWM_DEV2 DT_PWMS_LABEL(DT_ALIAS(blue_pwm_led))
#define PWM_CH2 DT_PWMS_CHANNEL(DT_ALIAS(blue_pwm_led))
#if DT_PHA_HAS_CELL(DT_ALIAS(blue_pwm_led), pwms, flags)
#define PWM_FLAGS2 DT_PWMS_FLAGS(DT_ALIAS(blue_pwm_led))
#else
#define PWM_FLAGS2 0
#endif

View file

@ -15,7 +15,7 @@
#include <device.h>
#include <drivers/pwm.h>
#ifndef DT_ALIAS_PWM_0_LABEL
#if !DT_HAS_NODE(DT_ALIAS(pwm_0))
#error "Choose supported board or add new board for the application"
#endif
@ -38,7 +38,7 @@ void main(void)
printk("PWM demo app-servo control\n");
pwm_dev = device_get_binding(DT_ALIAS_PWM_0_LABEL);
pwm_dev = device_get_binding(DT_LABEL(DT_ALIAS(pwm_0)));
if (!pwm_dev) {
printk("Cannot find PWM device!\n");
return;

View file

@ -25,14 +25,14 @@ struct printk_data_t {
K_FIFO_DEFINE(printk_fifo);
#ifdef DT_ALIAS_LED0_GPIOS_FLAGS
#define LED0_FLAGS DT_ALIAS_LED0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(led0), gpios, flags)
#define LED0_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
#else
#define LED0_FLAGS 0
#endif
#ifdef DT_ALIAS_LED1_GPIOS_FLAGS
#define LED1_FLAGS DT_ALIAS_LED1_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(led1), gpios, flags)
#define LED1_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led1), gpios)
#else
#define LED1_FLAGS 0
#endif
@ -82,9 +82,9 @@ void blink(const struct led *led, u32_t sleep_ms, u32_t id)
void blink1(void)
{
const struct led led1 = {
.gpio_dev_name = DT_ALIAS_LED0_GPIOS_CONTROLLER,
.gpio_pin_name = DT_ALIAS_LED0_LABEL,
.gpio_pin = DT_ALIAS_LED0_GPIOS_PIN,
.gpio_dev_name = DT_GPIO_LABEL(DT_ALIAS(led0), gpios),
.gpio_pin_name = DT_LABEL(DT_ALIAS(led0)),
.gpio_pin = DT_GPIO_PIN(DT_ALIAS(led0), gpios),
.gpio_flags = GPIO_OUTPUT | LED0_FLAGS,
};
@ -94,9 +94,9 @@ void blink1(void)
void blink2(void)
{
const struct led led2 = {
.gpio_dev_name = DT_ALIAS_LED1_GPIOS_CONTROLLER,
.gpio_pin_name = DT_ALIAS_LED1_LABEL,
.gpio_pin = DT_ALIAS_LED1_GPIOS_PIN,
.gpio_dev_name = DT_GPIO_LABEL(DT_ALIAS(led1), gpios),
.gpio_pin_name = DT_LABEL(DT_ALIAS(led1)),
.gpio_pin = DT_GPIO_PIN(DT_ALIAS(led1), gpios),
.gpio_flags = GPIO_OUTPUT | LED1_FLAGS,
};

View file

@ -30,14 +30,15 @@ static void configure_button(void)
{
static struct gpio_callback button_cb;
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW0_GPIOS_FLAGS);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INPUT | DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios));
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb, button_pressed, BIT(DT_ALIAS_SW0_GPIOS_PIN));
gpio_init_callback(&button_cb, button_pressed,
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)));
gpio_add_callback(gpio, &button_cb);
}
@ -53,7 +54,7 @@ void board_output_number(bt_mesh_output_action_t action, u32_t number)
oob_number = number;
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT, K_FOREVER, &arrow, 1);
@ -69,7 +70,7 @@ void board_prov_complete(void)
{ 0, 1, 1, 1, 0 });
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_DISABLE);
mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT, K_SECONDS(10),

View file

@ -46,7 +46,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
{
struct mb_display *disp = mb_display_get();
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
if (pins & BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios))) {
k_work_submit(&button_work);
} else {
u16_t target = board_set_target();
@ -228,20 +228,21 @@ static void configure_button(void)
k_work_init(&button_work, button_send_pressed);
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW0_GPIOS_FLAGS);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INPUT | DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios));
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW1_GPIOS_FLAGS);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
GPIO_INPUT | DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios));
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb, button_pressed,
BIT(DT_ALIAS_SW0_GPIOS_PIN) | BIT(DT_ALIAS_SW1_GPIOS_PIN));
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) |
BIT(DT_GPIO_PIN(DT_ALIAS(sw1), gpios)));
gpio_add_callback(gpio, &button_cb);
}

View file

@ -27,8 +27,8 @@
LOG_MODULE_REGISTER(button_svc);
#define BUT_PORT DT_ALIAS_SW0_GPIOS_CONTROLLER
#define BUT_PIN DT_ALIAS_SW0_GPIOS_PIN
#define BUT_PORT DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
#define BUT_PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
extern struct bt_conn *conn;
extern struct bt_gatt_service_static stsensor_svc[];
@ -72,10 +72,11 @@ int button_init(void)
}
ret = gpio_pin_configure(button_dev, BUT_PIN,
DT_ALIAS_SW0_GPIOS_FLAGS | GPIO_INPUT);
DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios) |
GPIO_INPUT);
if (ret != 0) {
LOG_ERR("Error %d: failed to configure pin %d '%s'\n",
ret, BUT_PIN, DT_ALIAS_SW0_LABEL);
ret, BUT_PIN, DT_LABEL(DT_ALIAS(sw0)));
return ret;
}
@ -87,7 +88,7 @@ int button_init(void)
GPIO_INT_EDGE_TO_ACTIVE);
if (ret != 0) {
LOG_ERR("Error %d: failed to configure interrupt on pin "
"%d '%s'\n", ret, BUT_PIN, DT_ALIAS_SW0_LABEL);
"%d '%s'\n", ret, BUT_PIN, DT_LABEL(DT_ALIAS(sw0)));
return ret;
}
but_val = 0;

View file

@ -20,8 +20,8 @@
LOG_MODULE_REGISTER(led_svc);
#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER
#define LED DT_ALIAS_LED0_GPIOS_PIN
#define LED_PORT DT_GPIO_LABEL(DT_ALIAS(led0), gpios)
#define LED DT_GPIO_PIN(DT_ALIAS(led0), gpios)
struct device *led_dev;
bool led_state;
@ -47,10 +47,10 @@ int led_init(void)
ret = gpio_pin_configure(led_dev, LED,
GPIO_OUTPUT_ACTIVE
| DT_ALIAS_LED0_GPIOS_FLAGS);
| DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
if (ret < 0) {
LOG_ERR("Error %d: failed to configure pin %d '%s'\n",
ret, LED, DT_ALIAS_LED0_LABEL);
ret, LED, DT_LABEL(DT_ALIAS(led0)));
return ret;
}

View file

@ -50,39 +50,45 @@ void signal_sampling_started(void)
{
static struct device *led0, *led1;
led0 = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
gpio_pin_configure(led0, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_OUTPUT_ACTIVE | DT_ALIAS_LED0_GPIOS_FLAGS);
led0 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
gpio_pin_configure(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
GPIO_OUTPUT_ACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
led1 = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
gpio_pin_configure(led1, DT_ALIAS_LED1_GPIOS_PIN,
GPIO_OUTPUT_INACTIVE | DT_ALIAS_LED1_GPIOS_FLAGS);
led1 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led1), gpios));
gpio_pin_configure(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios),
GPIO_OUTPUT_INACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led1), gpios));
}
void signal_sampling_stopped(void)
{
static struct device *led0, *led1;
led0 = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
gpio_pin_configure(led0, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_OUTPUT_ACTIVE | DT_ALIAS_LED0_GPIOS_FLAGS);
led0 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
gpio_pin_configure(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
GPIO_OUTPUT_ACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
led1 = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
gpio_pin_configure(led1, DT_ALIAS_LED1_GPIOS_PIN,
GPIO_OUTPUT_ACTIVE | DT_ALIAS_LED1_GPIOS_FLAGS);
led1 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led1), gpios));
gpio_pin_configure(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios),
GPIO_OUTPUT_ACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led1), gpios));
}
void signal_print_stopped(void)
{
static struct device *led0, *led1;
led0 = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
gpio_pin_configure(led0, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_OUTPUT_INACTIVE | DT_ALIAS_LED0_GPIOS_FLAGS);
led0 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
gpio_pin_configure(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
GPIO_OUTPUT_INACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
led1 = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
gpio_pin_configure(led1, DT_ALIAS_LED1_GPIOS_PIN,
GPIO_OUTPUT_ACTIVE | DT_ALIAS_LED1_GPIOS_FLAGS);
led1 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led1), gpios));
gpio_pin_configure(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios),
GPIO_OUTPUT_ACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led1), gpios));
}
void *rx_block[NUM_MS];

View file

@ -133,16 +133,18 @@ void main(void)
}
#endif
led0 = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
gpio_pin_configure(led0, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_OUTPUT_ACTIVE | DT_ALIAS_LED0_GPIOS_FLAGS);
led0 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
gpio_pin_configure(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
GPIO_OUTPUT_ACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
led1 = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
gpio_pin_configure(led1, DT_ALIAS_LED1_GPIOS_PIN,
GPIO_OUTPUT_INACTIVE | DT_ALIAS_LED1_GPIOS_FLAGS);
led1 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led1), gpios));
gpio_pin_configure(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios),
GPIO_OUTPUT_INACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led1), gpios));
for (i = 0; i < 5; i++) {
gpio_pin_set(led1, DT_ALIAS_LED1_GPIOS_PIN, on);
gpio_pin_set(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios), on);
k_sleep(K_MSEC(200));
on = (on == 1) ? 0 : 1;
}

View file

@ -115,7 +115,7 @@ void main(void)
{
static struct gpio_callback line_sensors;
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
i2c_dev = device_get_binding(I2C_DEV);
/* Setup gpio to read data from digital line sensors of the robot */
gpio_pin_configure(gpio, EXT_P13_GPIO_PIN, GPIO_INPUT);

View file

@ -394,7 +394,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
u32_t pins)
{
/* Filter out spurious presses */
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
if (pins & BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios))) {
printk("A pressed\n");
if (k_uptime_delta(&a_timestamp) < K_MSEC(100)) {
printk("Too quick A presses\n");
@ -422,7 +422,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
return;
}
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
if (pins & BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios))) {
if (select) {
pong_select_change();
return;
@ -485,22 +485,22 @@ static void configure_buttons(void)
static struct gpio_callback button_cb_data;
struct device *gpio;
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
DT_ALIAS_SW0_GPIOS_FLAGS | GPIO_INPUT);
gpio_pin_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
DT_ALIAS_SW1_GPIOS_FLAGS | GPIO_INPUT);
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios) | GPIO_INPUT);
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios) | GPIO_INPUT);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb_data, button_pressed,
BIT(DT_ALIAS_SW0_GPIOS_PIN) |
BIT(DT_ALIAS_SW1_GPIOS_PIN));
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) |
BIT(DT_GPIO_PIN(DT_ALIAS(sw1), gpios)));
gpio_add_callback(gpio, &button_cb_data);
}

View file

@ -57,7 +57,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
beep_active = true;
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
if (pins & BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios))) {
printk("A pressed\n");
if (period < PERIOD_MAX) {
period += 50U;
@ -82,22 +82,22 @@ void main(void)
{
static struct gpio_callback button_cb_data;
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
DT_ALIAS_SW0_GPIOS_FLAGS | GPIO_INPUT);
gpio_pin_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
DT_ALIAS_SW1_GPIOS_FLAGS | GPIO_INPUT);
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios) | GPIO_INPUT);
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios) | GPIO_INPUT);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb_data, button_pressed,
BIT(DT_ALIAS_SW0_GPIOS_PIN) |
BIT(DT_ALIAS_SW1_GPIOS_PIN));
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) |
BIT(DT_GPIO_PIN(DT_ALIAS(sw1), gpios)));
pwm = device_get_binding(DT_LABEL(DT_INST(0, nordic_nrf_sw_pwm)));

View file

@ -179,10 +179,10 @@ struct onoff_state {
*/
static struct onoff_state onoff_state[] = {
{ .led_gpio_pin = DT_ALIAS_LED0_GPIOS_PIN },
{ .led_gpio_pin = DT_ALIAS_LED1_GPIOS_PIN },
{ .led_gpio_pin = DT_ALIAS_LED2_GPIOS_PIN },
{ .led_gpio_pin = DT_ALIAS_LED3_GPIOS_PIN },
{ .led_gpio_pin = DT_GPIO_PIN(DT_ALIAS(led0), gpios) },
{ .led_gpio_pin = DT_GPIO_PIN(DT_ALIAS(led1), gpios) },
{ .led_gpio_pin = DT_GPIO_PIN(DT_ALIAS(led2), gpios) },
{ .led_gpio_pin = DT_GPIO_PIN(DT_ALIAS(led3), gpios) },
};
/*
@ -416,10 +416,10 @@ static u8_t dev_uuid[16] = { 0xdd, 0xdd };
static uint8_t pin_to_sw(uint32_t pin_pos)
{
switch (pin_pos) {
case BIT(DT_ALIAS_SW0_GPIOS_PIN): return 0;
case BIT(DT_ALIAS_SW1_GPIOS_PIN): return 1;
case BIT(DT_ALIAS_SW2_GPIOS_PIN): return 2;
case BIT(DT_ALIAS_SW3_GPIOS_PIN): return 3;
case BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)): return 0;
case BIT(DT_GPIO_PIN(DT_ALIAS(sw1), gpios)): return 1;
case BIT(DT_GPIO_PIN(DT_ALIAS(sw2), gpios)): return 2;
case BIT(DT_GPIO_PIN(DT_ALIAS(sw3), gpios)): return 3;
}
printk("No match for GPIO pin 0x%08x\n", pin_pos);
@ -608,37 +608,51 @@ void main(void)
/* Initialize button count timer */
k_timer_init(&sw.button_timer, button_cnt_timer, NULL);
sw_device = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio_pin_configure(sw_device, DT_ALIAS_SW0_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW0_GPIOS_FLAGS);
gpio_pin_configure(sw_device, DT_ALIAS_SW1_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW1_GPIOS_FLAGS);
gpio_pin_configure(sw_device, DT_ALIAS_SW2_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW2_GPIOS_FLAGS);
gpio_pin_configure(sw_device, DT_ALIAS_SW3_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW3_GPIOS_FLAGS);
gpio_pin_interrupt_configure(sw_device, DT_ALIAS_SW0_GPIOS_PIN,
sw_device = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
gpio_pin_configure(sw_device, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INPUT |
DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios));
gpio_pin_configure(sw_device, DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
GPIO_INPUT |
DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios));
gpio_pin_configure(sw_device, DT_GPIO_PIN(DT_ALIAS(sw2), gpios),
GPIO_INPUT |
DT_GPIO_FLAGS(DT_ALIAS(sw2), gpios));
gpio_pin_configure(sw_device, DT_GPIO_PIN(DT_ALIAS(sw3), gpios),
GPIO_INPUT |
DT_GPIO_FLAGS(DT_ALIAS(sw3), gpios));
gpio_pin_interrupt_configure(sw_device,
DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure(sw_device, DT_ALIAS_SW1_GPIOS_PIN,
gpio_pin_interrupt_configure(sw_device,
DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure(sw_device, DT_ALIAS_SW2_GPIOS_PIN,
gpio_pin_interrupt_configure(sw_device,
DT_GPIO_PIN(DT_ALIAS(sw2), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_pin_interrupt_configure(sw_device, DT_ALIAS_SW3_GPIOS_PIN,
gpio_pin_interrupt_configure(sw_device,
DT_GPIO_PIN(DT_ALIAS(sw3), gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb, button_pressed,
BIT(DT_ALIAS_SW0_GPIOS_PIN) | BIT(DT_ALIAS_SW1_GPIOS_PIN) |
BIT(DT_ALIAS_SW2_GPIOS_PIN) | BIT(DT_ALIAS_SW3_GPIOS_PIN));
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) |
BIT(DT_GPIO_PIN(DT_ALIAS(sw1), gpios)) |
BIT(DT_GPIO_PIN(DT_ALIAS(sw2), gpios)) |
BIT(DT_GPIO_PIN(DT_ALIAS(sw3), gpios)));
gpio_add_callback(sw_device, &button_cb);
/* Initialize LED's */
init_led(0, DT_ALIAS_LED0_GPIOS_CONTROLLER, DT_ALIAS_LED0_GPIOS_PIN,
DT_ALIAS_LED0_GPIOS_FLAGS);
init_led(1, DT_ALIAS_LED1_GPIOS_CONTROLLER, DT_ALIAS_LED1_GPIOS_PIN,
DT_ALIAS_LED1_GPIOS_FLAGS);
init_led(2, DT_ALIAS_LED2_GPIOS_CONTROLLER, DT_ALIAS_LED2_GPIOS_PIN,
DT_ALIAS_LED2_GPIOS_FLAGS);
init_led(3, DT_ALIAS_LED3_GPIOS_CONTROLLER, DT_ALIAS_LED3_GPIOS_PIN,
DT_ALIAS_LED3_GPIOS_FLAGS);
init_led(0, DT_GPIO_LABEL(DT_ALIAS(led0), gpios),
DT_GPIO_PIN(DT_ALIAS(led0), gpios),
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
init_led(1, DT_GPIO_LABEL(DT_ALIAS(led1), gpios),
DT_GPIO_PIN(DT_ALIAS(led1), gpios),
DT_GPIO_FLAGS(DT_ALIAS(led1), gpios));
init_led(2, DT_GPIO_LABEL(DT_ALIAS(led2), gpios),
DT_GPIO_PIN(DT_ALIAS(led2), gpios),
DT_GPIO_FLAGS(DT_ALIAS(led2), gpios));
init_led(3, DT_GPIO_LABEL(DT_ALIAS(led3), gpios),
DT_GPIO_PIN(DT_ALIAS(led3), gpios),
DT_GPIO_FLAGS(DT_ALIAS(led3), gpios));
/* Initialize the Bluetooth Subsystem */
err = bt_enable(bt_ready);

View file

@ -21,72 +21,90 @@ static void button_pressed(struct device *dev,
k_work_submit(&button_work);
}
#define LED0_NODE DT_ALIAS(led0)
#define LED1_NODE DT_ALIAS(led1)
#define LED2_NODE DT_ALIAS(led2)
#define LED3_NODE DT_ALIAS(led3)
#define SW0_NODE DT_ALIAS(sw0)
#define SW1_NODE DT_ALIAS(sw1)
#define SW2_NODE DT_ALIAS(sw2)
#define SW3_NODE DT_ALIAS(sw3)
void app_gpio_init(void)
{
static struct gpio_callback button_cb[4];
/* LEDs configuration & setting */
led_device[0] = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
gpio_pin_configure(led_device[0], DT_ALIAS_LED0_GPIOS_PIN,
DT_ALIAS_LED0_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
led_device[0] = device_get_binding(DT_GPIO_LABEL(LED0_NODE, gpios));
gpio_pin_configure(led_device[0], DT_GPIO_PIN(LED0_NODE, gpios),
DT_GPIO_FLAGS(LED0_NODE, gpios) |
GPIO_OUTPUT_INACTIVE);
#ifndef ONE_LED_ONE_BUTTON_BOARD
led_device[1] = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
gpio_pin_configure(led_device[1], DT_ALIAS_LED1_GPIOS_PIN,
DT_ALIAS_LED1_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
led_device[1] = device_get_binding(DT_GPIO_LABEL(LED1_NODE, gpios));
gpio_pin_configure(led_device[1], DT_GPIO_PIN(LED1_NODE, gpios),
DT_GPIO_FLAGS(LED1_NODE, gpios) |
GPIO_OUTPUT_INACTIVE);
led_device[2] = device_get_binding(DT_ALIAS_LED2_GPIOS_CONTROLLER);
gpio_pin_configure(led_device[2], DT_ALIAS_LED2_GPIOS_PIN,
DT_ALIAS_LED2_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
led_device[2] = device_get_binding(DT_GPIO_LABEL(LED2_NODE, gpios));
gpio_pin_configure(led_device[2], DT_GPIO_PIN(LED2_NODE, gpios),
DT_GPIO_FLAGS(LED2_NODE, gpios) |
GPIO_OUTPUT_INACTIVE);
led_device[3] = device_get_binding(DT_ALIAS_LED3_GPIOS_CONTROLLER);
gpio_pin_configure(led_device[3], DT_ALIAS_LED3_GPIOS_PIN,
DT_ALIAS_LED3_GPIOS_FLAGS | GPIO_OUTPUT_INACTIVE);
led_device[3] = device_get_binding(DT_GPIO_LABEL(LED3_NODE, gpios));
gpio_pin_configure(led_device[3], DT_GPIO_PIN(LED3_NODE, gpios),
DT_GPIO_FLAGS(LED3_NODE, gpios) |
GPIO_OUTPUT_INACTIVE);
#endif
/* Buttons configuration & setting */
k_work_init(&button_work, publish);
button_device[0] = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[0], DT_ALIAS_SW0_GPIOS_PIN,
button_device[0] = device_get_binding(DT_GPIO_LABEL(SW0_NODE, gpios));
gpio_pin_configure(button_device[0], DT_GPIO_PIN(SW0_NODE, gpios),
GPIO_INPUT | GPIO_INT_DEBOUNCE |
DT_ALIAS_SW0_GPIOS_FLAGS);
gpio_pin_interrupt_configure(button_device[0], DT_ALIAS_SW0_GPIOS_PIN,
DT_GPIO_FLAGS(SW0_NODE, gpios));
gpio_pin_interrupt_configure(button_device[0],
DT_GPIO_PIN(SW0_NODE, gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb[0], button_pressed,
BIT(DT_ALIAS_SW0_GPIOS_PIN));
BIT(DT_GPIO_PIN(SW0_NODE, gpios)));
gpio_add_callback(button_device[0], &button_cb[0]);
#ifndef ONE_LED_ONE_BUTTON_BOARD
button_device[1] = device_get_binding(DT_ALIAS_SW1_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[1], DT_ALIAS_SW1_GPIOS_PIN,
button_device[1] = device_get_binding(DT_GPIO_LABEL(SW1_NODE, gpios));
gpio_pin_configure(button_device[1], DT_GPIO_PIN(SW1_NODE, gpios),
GPIO_INPUT | GPIO_INT_DEBOUNCE |
DT_ALIAS_SW1_GPIOS_FLAGS);
gpio_pin_interrupt_configure(button_device[1], DT_ALIAS_SW1_GPIOS_PIN,
DT_GPIO_FLAGS(SW1_NODE, gpios));
gpio_pin_interrupt_configure(button_device[1],
DT_GPIO_PIN(SW1_NODE, gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb[1], button_pressed,
BIT(DT_ALIAS_SW1_GPIOS_PIN));
BIT(DT_GPIO_PIN(SW1_NODE, gpios)));
gpio_add_callback(button_device[1], &button_cb[1]);
button_device[2] = device_get_binding(DT_ALIAS_SW2_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[2], DT_ALIAS_SW2_GPIOS_PIN,
button_device[2] = device_get_binding(DT_GPIO_LABEL(SW2_NODE, gpios));
gpio_pin_configure(button_device[2], DT_GPIO_PIN(SW2_NODE, gpios),
GPIO_INPUT | GPIO_INT_DEBOUNCE |
DT_ALIAS_SW2_GPIOS_FLAGS);
gpio_pin_interrupt_configure(button_device[2], DT_ALIAS_SW2_GPIOS_PIN,
DT_GPIO_FLAGS(SW2_NODE, gpios));
gpio_pin_interrupt_configure(button_device[2],
DT_GPIO_PIN(SW2_NODE, gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb[2], button_pressed,
BIT(DT_ALIAS_SW2_GPIOS_PIN));
BIT(DT_GPIO_PIN(SW2_NODE, gpios)));
gpio_add_callback(button_device[2], &button_cb[2]);
button_device[3] = device_get_binding(DT_ALIAS_SW3_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[3], DT_ALIAS_SW3_GPIOS_PIN,
button_device[3] = device_get_binding(DT_GPIO_LABEL(SW3_NODE, gpios));
gpio_pin_configure(button_device[3], DT_GPIO_PIN(SW3_NODE, gpios),
GPIO_INPUT | GPIO_INT_DEBOUNCE |
DT_ALIAS_SW3_GPIOS_FLAGS);
gpio_pin_interrupt_configure(button_device[3], DT_ALIAS_SW3_GPIOS_PIN,
DT_GPIO_FLAGS(SW3_NODE, gpios));
gpio_pin_interrupt_configure(button_device[3],
DT_GPIO_PIN(SW3_NODE, gpios),
GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&button_cb[3], button_pressed,
BIT(DT_ALIAS_SW3_GPIOS_PIN));
BIT(DT_GPIO_PIN(SW3_NODE, gpios)));
gpio_add_callback(button_device[3], &button_cb[3]);
#endif
}

View file

@ -94,7 +94,7 @@ static void light_default_status_init(void)
void update_vnd_led_gpio(void)
{
#ifndef ONE_LED_ONE_BUTTON_BOARD
gpio_pin_set(led_device[1], DT_ALIAS_LED1_GPIOS_PIN,
gpio_pin_set(led_device[1], DT_GPIO_PIN(DT_ALIAS(led1), gpios),
vnd_user_data.current == STATE_ON);
#endif
}
@ -109,12 +109,13 @@ void update_led_gpio(void)
printk("power-> %d, color-> %d\n", power, color);
gpio_pin_set(led_device[0], DT_ALIAS_LED0_GPIOS_PIN,
gpio_pin_set(led_device[0], DT_GPIO_PIN(DT_ALIAS(led0), gpios),
ctl->light->current);
#ifndef ONE_LED_ONE_BUTTON_BOARD
gpio_pin_set(led_device[2], DT_ALIAS_LED2_GPIOS_PIN, power < 50);
gpio_pin_set(led_device[3], DT_ALIAS_LED3_GPIOS_PIN, color < 50);
gpio_pin_set(led_device[2], DT_GPIO_PIN(DT_ALIAS(led2), gpios),
power < 50);
gpio_pin_set(led_device[3], DT_GPIO_PIN(DT_ALIAS(led3), gpios),
color < 50);
#endif
}

View file

@ -22,7 +22,8 @@ void publish(struct k_work *work)
int err = 0;
#ifndef ONE_LED_ONE_BUTTON_BOARD
if (gpio_pin_get(button_device[0], DT_ALIAS_SW0_GPIOS_PIN) == 1) {
if (gpio_pin_get(button_device[0],
DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) == 1) {
#if defined(ONOFF)
bt_mesh_model_msg_init(root_models[3].pub->msg,
BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK);
@ -44,8 +45,8 @@ void publish(struct k_work *work)
net_buf_simple_add_u8(vnd_models[0].pub->msg, tid++);
err = bt_mesh_model_publish(&vnd_models[0]);
#endif
} else if (gpio_pin_get(button_device[1], DT_ALIAS_SW1_GPIOS_PIN) ==
1) {
} else if (gpio_pin_get(button_device[1],
DT_GPIO_PIN(DT_ALIAS(sw1), gpios)) == 1) {
#if defined(ONOFF)
bt_mesh_model_msg_init(root_models[3].pub->msg,
BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK);
@ -67,8 +68,8 @@ void publish(struct k_work *work)
net_buf_simple_add_u8(vnd_models[0].pub->msg, tid++);
err = bt_mesh_model_publish(&vnd_models[0]);
#endif
} else if (gpio_pin_get(button_device[2], DT_ALIAS_SW2_GPIOS_PIN) ==
1) {
} else if (gpio_pin_get(button_device[2],
DT_GPIO_PIN(DT_ALIAS(sw2), gpios)) == 1) {
#if defined(GENERIC_LEVEL)
bt_mesh_model_msg_init(root_models[5].pub->msg,
BT_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK);
@ -138,8 +139,8 @@ void publish(struct k_work *work)
net_buf_simple_add_u8(root_models[16].pub->msg, tid++);
err = bt_mesh_model_publish(&root_models[16]);
#endif
} else if (gpio_pin_get(button_device[3], DT_ALIAS_SW3_GPIOS_PIN) ==
1) {
} else if (gpio_pin_get(button_device[3],
DT_GPIO_PIN(DT_ALIAS(sw3), gpios)) == 1) {
#if defined(GENERIC_LEVEL)
bt_mesh_model_msg_init(root_models[5].pub->msg,
BT_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK);
@ -207,7 +208,8 @@ void publish(struct k_work *work)
#endif
}
#else
if (gpio_pin_get(button_device[0], DT_ALIAS_SW0_GPIOS_PIN) == 1) {
if (gpio_pin_get(button_device[0],
DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) == 1) {
#if defined(ONOFF)
static u8_t state = STATE_ON;

View file

@ -12,8 +12,8 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(nrfx_sample, LOG_LEVEL_INF);
#define INPUT_PIN DT_ALIAS_SW0_GPIOS_PIN
#define OUTPUT_PIN DT_ALIAS_LED0_GPIOS_PIN
#define INPUT_PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#define OUTPUT_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
static void button_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{

View file

@ -47,8 +47,8 @@ struct font_info {
#define STAT_COUNT 128
#ifdef DT_ALIAS_SW0_GPIOS_FLAGS
#define PULL_UP DT_ALIAS_SW0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, flags)
#define PULL_UP DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
#else
#define PULL_UP 0
#endif
@ -67,12 +67,15 @@ static struct {
gpio_pin_t pin;
gpio_flags_t flags;
} leds[] = {
{ .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}
{ .name = DT_GPIO_LABEL(DT_ALIAS(led0), gpios),
.pin = DT_GPIO_PIN(DT_ALIAS(led0), gpios),
.flags = DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)},
{ .name = DT_GPIO_LABEL(DT_ALIAS(led1), gpios),
.pin = DT_GPIO_PIN(DT_ALIAS(led1), gpios),
.flags = DT_GPIO_FLAGS(DT_ALIAS(led1), gpios)},
{ .name = DT_GPIO_LABEL(DT_ALIAS(led2), gpios),
.pin = DT_GPIO_PIN(DT_ALIAS(led2), gpios),
.flags = DT_GPIO_FLAGS(DT_ALIAS(led2), gpios)}
};
struct k_delayed_work led_timer;
@ -446,7 +449,7 @@ static void long_press(struct k_work *work)
static bool button_is_pressed(void)
{
return gpio_pin_get(gpio, DT_ALIAS_SW0_GPIOS_PIN) > 0;
return gpio_pin_get(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios)) > 0;
}
static void button_interrupt(struct device *dev, struct gpio_callback *cb,
@ -476,7 +479,7 @@ static void button_interrupt(struct device *dev, struct gpio_callback *cb,
case SCREEN_STATS:
return;
case SCREEN_MAIN:
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
if (pins & BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios))) {
u32_t uptime = k_uptime_get_32();
static u32_t bad_count, press_ts;
@ -509,19 +512,19 @@ static int configure_button(void)
{
static struct gpio_callback button_cb;
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios));
if (!gpio) {
return -ENODEV;
}
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
GPIO_INPUT | DT_ALIAS_SW0_GPIOS_FLAGS);
gpio_pin_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INPUT | DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios));
gpio_pin_interrupt_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
GPIO_INT_EDGE_BOTH);
gpio_init_callback(&button_cb, button_interrupt,
BIT(DT_ALIAS_SW0_GPIOS_PIN));
BIT(DT_GPIO_PIN(DT_ALIAS(sw0), gpios)));
gpio_add_callback(gpio, &button_cb);

View file

@ -251,23 +251,25 @@ void main(void)
int i, on = 1;
int cnt = 1;
led0 = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
gpio_pin_configure(led0, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_OUTPUT_ACTIVE | DT_ALIAS_LED0_GPIOS_FLAGS);
led0 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
gpio_pin_configure(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios),
GPIO_OUTPUT_ACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
led1 = device_get_binding(DT_ALIAS_LED1_GPIOS_CONTROLLER);
gpio_pin_configure(led1, DT_ALIAS_LED1_GPIOS_PIN,
GPIO_OUTPUT_INACTIVE | DT_ALIAS_LED1_GPIOS_FLAGS);
led1 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led1), gpios));
gpio_pin_configure(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios),
GPIO_OUTPUT_INACTIVE |
DT_GPIO_FLAGS(DT_ALIAS(led1), gpios));
for (i = 0; i < 6; i++) {
gpio_pin_set(led0, DT_ALIAS_LED0_GPIOS_PIN, on);
gpio_pin_set(led1, DT_ALIAS_LED1_GPIOS_PIN, !on);
gpio_pin_set(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios), on);
gpio_pin_set(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios), !on);
k_sleep(K_MSEC(100));
on = (on == 1) ? 0 : 1;
}
gpio_pin_set(led0, DT_ALIAS_LED0_GPIOS_PIN, 0);
gpio_pin_set(led1, DT_ALIAS_LED1_GPIOS_PIN, 1);
gpio_pin_set(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios), 0);
gpio_pin_set(led1, DT_GPIO_PIN(DT_ALIAS(led1), gpios), 1);
printk("SensorTile.box test!!\n");

View file

@ -15,9 +15,9 @@
#include <driverlib/ioc.h>
#define PORT DT_ALIAS_SW0_GPIOS_CONTROLLER
#define PIN DT_ALIAS_SW0_GPIOS_PIN
#define PULL_UP DT_ALIAS_SW0_GPIOS_FLAGS
#define PORT DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
#define PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#define PULL_UP DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
#define BUSY_WAIT_S 5U
#define SLEEP_US 2000U

View file

@ -81,7 +81,8 @@ void change_led(struct zcan_frame *msg, void *led_dev_param)
{
struct device *led_dev = (struct device *)led_dev_param;
#if defined(DT_ALIAS_LED0_GPIOS_PIN) && defined(DT_ALIAS_LED0_GPIOS_CONTROLLER)
#if DT_PHA_HAS_CELL(DT_ALIAS(led0), gpios, pin) && \
DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
if (!led_dev_param) {
printk("No LED GPIO device\n");
@ -90,10 +91,10 @@ void change_led(struct zcan_frame *msg, void *led_dev_param)
switch (msg->data[0]) {
case SET_LED:
gpio_pin_set(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 1);
gpio_pin_set(led_dev, DT_GPIO_PIN(DT_ALIAS(led0), gpios), 1);
break;
case RESET_LED:
gpio_pin_set(led_dev, DT_ALIAS_LED0_GPIOS_PIN, 0);
gpio_pin_set(led_dev, DT_GPIO_PIN(DT_ALIAS(led0), gpios), 0);
break;
}
#else
@ -206,15 +207,18 @@ void main(void)
can_configure(can_dev, CAN_LOOPBACK_MODE, 125000);
#endif
#if defined(DT_ALIAS_LED0_GPIOS_PIN) && defined(DT_ALIAS_LED0_GPIOS_CONTROLLER)
led_gpio_dev = device_get_binding(DT_ALIAS_LED0_GPIOS_CONTROLLER);
#if DT_PHA_HAS_CELL(DT_ALIAS(led0), gpios, pin) && \
DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
led_gpio_dev = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios));
if (!led_gpio_dev) {
printk("LED: Device driver not found.\n");
return;
}
ret = gpio_pin_configure(led_gpio_dev, DT_ALIAS_LED0_GPIOS_PIN,
GPIO_OUTPUT_HIGH | DT_ALIAS_LED0_GPIOS_FLAGS);
ret = gpio_pin_configure(led_gpio_dev,
DT_GPIO_PIN(DT_ALIAS(led0), gpios),
GPIO_OUTPUT_HIGH |
DT_GPIO_FLAGS(DT_ALIAS(led0), gpios));
if (ret < 0) {
printk("Error setting LED pin to output mode [%d]", ret);
}

View file

@ -10,7 +10,7 @@
#include <device.h>
#include <drivers/i2c.h>
#define I2C_DEV DT_ALIAS_I2C_0_LABEL
#define I2C_DEV DT_LABEL(DT_ALIAS(i2c_0))
/**
* @file Sample app using the Fujitsu MB85RC256V FRAM through ARC I2C.

View file

@ -29,7 +29,7 @@
#define GPIO_CLK_PIN 19
#define GPIO_NAME "GPIO_"
#define GPIO_DRV_NAME DT_ALIAS_GPIO_0_LABEL
#define GPIO_DRV_NAME DT_LABEL(DT_ALIAS(gpio_0))
#define APA102C_START_FRAME 0x00000000
#define APA102C_END_FRAME 0xFFFFFFFF

View file

@ -18,8 +18,8 @@ LOG_MODULE_REGISTER(main);
#include <drivers/spi.h>
#include <sys/util.h>
#define STRIP_LABEL DT_ALIAS_LED_STRIP_LABEL
#define STRIP_NUM_PIXELS DT_ALIAS_LED_STRIP_CHAIN_LENGTH
#define STRIP_LABEL DT_LABEL(DT_ALIAS(led_strip))
#define STRIP_NUM_PIXELS DT_PROP(DT_ALIAS(led_strip), chain_length)
#define DELAY_TIME K_MSEC(50)

View file

@ -176,7 +176,7 @@ static void monitor_temperature_func(void *dummy1, void *dummy2, void *dummy3)
void main(void)
{
#ifdef DT_ALIAS_PECI_0_LABEL
#if DT_HAS_NODE(DT_ALIAS(peci_0))
int ret;
#endif
@ -186,8 +186,8 @@ void main(void)
monitor_temperature_func, NULL, NULL, NULL, PRIORITY,
K_INHERIT_PERMS, K_FOREVER);
#ifdef DT_ALIAS_PECI_0_LABEL
peci_dev = device_get_binding(DT_ALIAS_PECI_0_LABEL);
#if DT_HAS_NODE(DT_ALIAS(peci_0))
peci_dev = device_get_binding(DT_LABEL(DT_ALIAS(peci_0)));
if (!peci_dev) {
printk("Err: PECI device not found\n");
return;

View file

@ -143,7 +143,7 @@ void main(void)
printk("fujitsu FRAM example application\n");
spi = device_get_binding(DT_ALIAS_SPI_1_LABEL);
spi = device_get_binding(DT_LABEL(DT_ALIAS(spi_1)));
if (!spi) {
printk("Could not find SPI driver\n");
return;

View file

@ -51,10 +51,10 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#define ENDPOINT_LEN 32
#ifdef DT_ALIAS_LED0_GPIOS_CONTROLLER
#define LED_GPIO_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER
#define LED_GPIO_PIN DT_ALIAS_LED0_GPIOS_PIN
#define LED_GPIO_FLAGS DT_ALIAS_LED0_GPIOS_FLAGS
#if DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
#define LED_GPIO_PORT DT_GPIO_LABEL(DT_ALIAS(led0), gpios)
#define LED_GPIO_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define LED_GPIO_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
#else
#define LED_GPIO_PORT "(fail)"
#define LED_GPIO_PIN 0

View file

@ -16,42 +16,42 @@
LOG_MODULE_REGISTER(main);
/* change this to use another GPIO port */
#ifdef DT_ALIAS_SW0_GPIOS_CONTROLLER
#define PORT0 DT_ALIAS_SW0_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw0), gpios)
#define PORT0 DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_CONTROLLER needs to be set
#error DT_GPIO_LABEL(DT_ALIAS(sw0), gpios) needs to be set
#endif
/* change this to use another GPIO pin */
#ifdef DT_ALIAS_SW0_GPIOS_PIN
#define PIN0 DT_ALIAS_SW0_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, pin)
#define PIN0 DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_PIN needs to be set
#error DT_GPIO_PIN(DT_ALIAS(sw0), gpios) needs to be set
#endif
/* The switch pin pull-up/down flags */
#ifdef DT_ALIAS_SW0_GPIOS_FLAGS
#define PIN0_FLAGS DT_ALIAS_SW0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, flags)
#define PIN0_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_FLAGS needs to be set
#error DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios) needs to be set
#endif
/* If second button exists, use it as right-click. */
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#define PIN1 DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
#define PIN1 DT_GPIO_PIN(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW1_GPIOS_CONTROLLER
#define PORT1 DT_ALIAS_SW1_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw1), gpios)
#define PORT1 DT_GPIO_LABEL(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW1_GPIOS_FLAGS
#define PIN1_FLAGS DT_ALIAS_SW1_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, flags)
#define PIN1_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios)
#endif
#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER
#define LED DT_ALIAS_LED0_GPIOS_PIN
#define LED_FLAGS DT_ALIAS_LED0_GPIOS_FLAGS
#define LED_PORT DT_GPIO_LABEL(DT_ALIAS(led0), gpios)
#define LED DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define LED_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
#ifdef CONFIG_FXOS8700
#include <drivers/sensor.h>
@ -93,7 +93,7 @@ static void left_button(struct device *gpio, struct gpio_callback *cb,
}
}
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
static void right_button(struct device *gpio, struct gpio_callback *cb,
u32_t pins)
{
@ -217,7 +217,7 @@ void main(void)
return;
}
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
if (callbacks_configure(device_get_binding(PORT1), PIN1, PIN1_FLAGS,
&right_button, &callback[1], &def_val[1])) {
LOG_ERR("Failed configuring right button callback.");

View file

@ -21,22 +21,22 @@ LOG_MODULE_REGISTER(app);
#error CANopen CAN interface not set
#endif
#ifdef DT_ALIAS_GREEN_LED_GPIOS_CONTROLLER
#define LED_GREEN_PORT DT_ALIAS_GREEN_LED_GPIOS_CONTROLLER
#define LED_GREEN_PIN DT_ALIAS_GREEN_LED_GPIOS_PIN
#define LED_GREEN_FLAGS DT_ALIAS_GREEN_LED_GPIOS_FLAGS
#if DT_NODE_HAS_PROP(DT_ALIAS(green_led), gpios)
#define LED_GREEN_PORT DT_GPIO_LABEL(DT_ALIAS(green_led), gpios)
#define LED_GREEN_PIN DT_GPIO_PIN(DT_ALIAS(green_led), gpios)
#define LED_GREEN_FLAGS DT_GPIO_FLAGS(DT_ALIAS(green_led), gpios)
#endif
#ifdef DT_ALIAS_RED_LED_GPIOS_CONTROLLER
#define LED_RED_PORT DT_ALIAS_RED_LED_GPIOS_CONTROLLER
#define LED_RED_PIN DT_ALIAS_RED_LED_GPIOS_PIN
#define LED_RED_FLAGS DT_ALIAS_RED_LED_GPIOS_FLAGS
#if DT_NODE_HAS_PROP(DT_ALIAS(red_led), gpios)
#define LED_RED_PORT DT_GPIO_LABEL(DT_ALIAS(red_led), gpios)
#define LED_RED_PIN DT_GPIO_PIN(DT_ALIAS(red_led), gpios)
#define LED_RED_FLAGS DT_GPIO_FLAGS(DT_ALIAS(red_led), gpios)
#endif
#ifdef DT_ALIAS_SW0_GPIOS_CONTROLLER
#define BUTTON_PORT DT_ALIAS_SW0_GPIOS_CONTROLLER
#define BUTTON_PIN DT_ALIAS_SW0_GPIOS_PIN
#define BUTTON_FLAGS DT_ALIAS_SW0_GPIOS_FLAGS
#if DT_NODE_HAS_PROP(DT_ALIAS(sw0), gpios)
#define BUTTON_PORT DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
#define BUTTON_PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#define BUTTON_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
static struct gpio_callback button_callback;
#endif

View file

@ -17,58 +17,58 @@
#define LOG_LEVEL LOG_LEVEL_DBG
LOG_MODULE_REGISTER(main);
#ifdef DT_ALIAS_SW0_GPIOS_CONTROLLER
#define PORT0 DT_ALIAS_SW0_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw0), gpios)
#define PORT0 DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_CONTROLLER needs to be set
#error DT_GPIO_LABEL(DT_ALIAS(sw0), gpios) needs to be set
#endif
#ifdef DT_ALIAS_SW0_GPIOS_PIN
#define PIN0 DT_ALIAS_SW0_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, pin)
#define PIN0 DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_PIN needs to be set
#error DT_GPIO_PIN(DT_ALIAS(sw0), gpios) needs to be set
#endif
#ifdef DT_ALIAS_SW0_GPIOS_FLAGS
#define PIN0_FLAGS DT_ALIAS_SW0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, flags)
#define PIN0_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_FLAGS needs to be set
#error DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios) needs to be set
#endif
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#define PIN1 DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
#define PIN1 DT_GPIO_PIN(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW1_GPIOS_CONTROLLER
#define PORT1 DT_ALIAS_SW1_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw1), gpios)
#define PORT1 DT_GPIO_LABEL(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW1_GPIOS_FLAGS
#define PIN1_FLAGS DT_ALIAS_SW1_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, flags)
#define PIN1_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW2_GPIOS_PIN
#define PIN2 DT_ALIAS_SW2_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin)
#define PIN2 DT_GPIO_PIN(DT_ALIAS(sw2), gpios)
#endif
#ifdef DT_ALIAS_SW2_GPIOS_CONTROLLER
#define PORT2 DT_ALIAS_SW2_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw2), gpios)
#define PORT2 DT_GPIO_LABEL(DT_ALIAS(sw2), gpios)
#endif
#ifdef DT_ALIAS_SW2_GPIOS_FLAGS
#define PIN2_FLAGS DT_ALIAS_SW2_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, flags)
#define PIN2_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw2), gpios)
#endif
#ifdef DT_ALIAS_SW3_GPIOS_PIN
#define PIN3 DT_ALIAS_SW3_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, pin)
#define PIN3 DT_GPIO_PIN(DT_ALIAS(sw3), gpios)
#endif
#ifdef DT_ALIAS_SW3_GPIOS_CONTROLLER
#define PORT3 DT_ALIAS_SW3_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw3), gpios)
#define PORT3 DT_GPIO_LABEL(DT_ALIAS(sw3), gpios)
#endif
#ifdef DT_ALIAS_SW3_GPIOS_FLAGS
#define PIN3_FLAGS DT_ALIAS_SW3_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, flags)
#define PIN3_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw3), gpios)
#endif
/* Event FIFO */
@ -501,7 +501,7 @@ static void btn0(struct device *gpio, struct gpio_callback *cb, u32_t pins)
k_sem_give(&evt_sem);
}
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
static void btn1(struct device *gpio, struct gpio_callback *cb, u32_t pins)
{
struct app_evt_t *ev = app_evt_alloc();
@ -512,7 +512,7 @@ static void btn1(struct device *gpio, struct gpio_callback *cb, u32_t pins)
}
#endif
#ifdef DT_ALIAS_SW2_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin)
static void btn2(struct device *gpio, struct gpio_callback *cb, u32_t pins)
{
struct app_evt_t *ev = app_evt_alloc();
@ -523,7 +523,7 @@ static void btn2(struct device *gpio, struct gpio_callback *cb, u32_t pins)
}
#endif
#ifdef DT_ALIAS_SW3_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, pin)
static void btn3(struct device *gpio, struct gpio_callback *cb, u32_t pins)
{
struct app_evt_t *ev = app_evt_alloc();
@ -598,7 +598,7 @@ void main(void)
return;
}
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
if (callbacks_configure(device_get_binding(PORT1), PIN1, PIN1_FLAGS,
&btn1, &callback[1])) {
LOG_ERR("Failed configuring button 1 callback.");
@ -606,7 +606,7 @@ void main(void)
}
#endif
#ifdef DT_ALIAS_SW2_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin)
if (callbacks_configure(device_get_binding(PORT2), PIN2, PIN2_FLAGS,
&btn2, &callback[2])) {
LOG_ERR("Failed configuring button 2 callback.");
@ -614,7 +614,7 @@ void main(void)
}
#endif
#ifdef DT_ALIAS_SW3_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, pin)
if (callbacks_configure(device_get_binding(PORT3), PIN3, PIN3_FLAGS,
&btn3, &callback[3])) {
LOG_ERR("Failed configuring button 3 callback.");

View file

@ -25,14 +25,14 @@ GPIO button in your board.
To use this sample, you will require a board that defines the user switch in its
header file. The :file:`board.h` must define the following variables:
- DT_ALIAS_SW0_GPIOS_CONTROLLER
- DT_ALIAS_SW0_GPIOS_PIN
- DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
- DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
The following variables are optional and depend on available board buttons:
- For right-button: DT_ALIAS_SW1_GPIOS_CONTROLLER, DT_ALIAS_SW1_GPIOS_PIN
- For X-axis: DT_ALIAS_SW2_GPIOS_CONTROLLER, DT_ALIAS_SW2_GPIOS_PIN
- For Y-axis: DT_ALIAS_SW3_GPIOS_CONTROLLER, DT_ALIAS_SW3_GPIOS_PIN
- For right-button: DT_GPIO_LABEL(DT_ALIAS(sw1), gpios), DT_GPIO_PIN(DT_ALIAS(sw1), gpios)
- For X-axis: DT_GPIO_LABEL(DT_ALIAS(sw2), gpios), DT_GPIO_PIN(DT_ALIAS(sw2), gpios)
- For Y-axis: DT_GPIO_LABEL(DT_ALIAS(sw3), gpios), DT_GPIO_PIN(DT_ALIAS(sw3), gpios)
Building and Running
********************

View file

@ -15,68 +15,68 @@
LOG_MODULE_REGISTER(main);
/* change this to use another GPIO port */
#ifdef DT_ALIAS_SW0_GPIOS_CONTROLLER
#define PORT0 DT_ALIAS_SW0_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw0), gpios)
#define PORT0 DT_GPIO_LABEL(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_CONTROLLER needs to be set
#error DT_GPIO_LABEL(DT_ALIAS(sw0), gpios) needs to be set
#endif
/* change this to use another GPIO pin */
#ifdef DT_ALIAS_SW0_GPIOS_PIN
#define PIN0 DT_ALIAS_SW0_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, pin)
#define PIN0 DT_GPIO_PIN(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_PIN needs to be set
#error DT_GPIO_PIN(DT_ALIAS(sw0), gpios) needs to be set
#endif
/* The switch pin pull-up/down flags */
#ifdef DT_ALIAS_SW0_GPIOS_FLAGS
#define PIN0_FLAGS DT_ALIAS_SW0_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, flags)
#define PIN0_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios)
#else
#error DT_ALIAS_SW0_GPIOS_FLAGS needs to be set
#error DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios) needs to be set
#endif
/* If second button exists, use it as right-click. */
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#define PIN1 DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
#define PIN1 DT_GPIO_PIN(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW1_GPIOS_CONTROLLER
#define PORT1 DT_ALIAS_SW1_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw1), gpios)
#define PORT1 DT_GPIO_LABEL(DT_ALIAS(sw1), gpios)
#endif
#ifdef DT_ALIAS_SW1_GPIOS_FLAGS
#define PIN1_FLAGS DT_ALIAS_SW1_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, flags)
#define PIN1_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios)
#endif
/* If third button exists, use it as X axis movement. */
#ifdef DT_ALIAS_SW2_GPIOS_PIN
#define PIN2 DT_ALIAS_SW2_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin)
#define PIN2 DT_GPIO_PIN(DT_ALIAS(sw2), gpios)
#endif
#ifdef DT_ALIAS_SW2_GPIOS_CONTROLLER
#define PORT2 DT_ALIAS_SW2_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw2), gpios)
#define PORT2 DT_GPIO_LABEL(DT_ALIAS(sw2), gpios)
#endif
#ifdef DT_ALIAS_SW2_GPIOS_FLAGS
#define PIN2_FLAGS DT_ALIAS_SW2_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, flags)
#define PIN2_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw2), gpios)
#endif
/* If fourth button exists, use it as Y axis movement. */
#ifdef DT_ALIAS_SW3_GPIOS_PIN
#define PIN3 DT_ALIAS_SW3_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, pin)
#define PIN3 DT_GPIO_PIN(DT_ALIAS(sw3), gpios)
#endif
#ifdef DT_ALIAS_SW3_GPIOS_CONTROLLER
#define PORT3 DT_ALIAS_SW3_GPIOS_CONTROLLER
#if DT_NODE_HAS_PROP(DT_ALIAS(sw3), gpios)
#define PORT3 DT_GPIO_LABEL(DT_ALIAS(sw3), gpios)
#endif
#ifdef DT_ALIAS_SW3_GPIOS_FLAGS
#define PIN3_FLAGS DT_ALIAS_SW3_GPIOS_FLAGS
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, flags)
#define PIN3_FLAGS DT_GPIO_FLAGS(DT_ALIAS(sw3), gpios)
#endif
#define LED_PORT DT_ALIAS_LED0_GPIOS_CONTROLLER
#define LED DT_ALIAS_LED0_GPIOS_PIN
#define LED_FLAGS DT_ALIAS_LED0_GPIOS_FLAGS
#define LED_PORT DT_GPIO_LABEL(DT_ALIAS(led0), gpios)
#define LED DT_GPIO_PIN(DT_ALIAS(led0), gpios)
#define LED_FLAGS DT_GPIO_FLAGS(DT_ALIAS(led0), gpios)
static const u8_t hid_report_desc[] = HID_MOUSE_REPORT_DESC(2);
@ -133,7 +133,7 @@ static void left_button(struct device *gpio, struct gpio_callback *cb,
}
}
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
static void right_button(struct device *gpio, struct gpio_callback *cb,
u32_t pins)
{
@ -167,7 +167,7 @@ static void right_button(struct device *gpio, struct gpio_callback *cb,
}
#endif
#ifdef DT_ALIAS_SW2_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin)
static void x_move(struct device *gpio, struct gpio_callback *cb, u32_t pins)
{
int ret;
@ -191,7 +191,7 @@ static void x_move(struct device *gpio, struct gpio_callback *cb, u32_t pins)
}
#endif
#ifdef DT_ALIAS_SW3_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, pin)
static void y_move(struct device *gpio, struct gpio_callback *cb, u32_t pins)
{
int ret;
@ -290,7 +290,7 @@ void main(void)
return;
}
#ifdef DT_ALIAS_SW1_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin)
if (callbacks_configure(device_get_binding(PORT1), PIN1, PIN1_FLAGS,
&right_button, &callback[1], &def_val[1])) {
LOG_ERR("Failed configuring right button callback.");
@ -298,7 +298,7 @@ void main(void)
}
#endif
#ifdef DT_ALIAS_SW2_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin)
if (callbacks_configure(device_get_binding(PORT2), PIN2, PIN2_FLAGS,
&x_move, &callback[2], &def_val[2])) {
LOG_ERR("Failed configuring X axis movement callback.");
@ -306,7 +306,7 @@ void main(void)
}
#endif
#ifdef DT_ALIAS_SW3_GPIOS_PIN
#if DT_PHA_HAS_CELL(DT_ALIAS(sw3), gpios, pin)
if (callbacks_configure(device_get_binding(PORT3), PIN3, PIN3_FLAGS,
&y_move, &callback[3], &def_val[3])) {
LOG_ERR("Failed configuring Y axis movement callback.");