Skip to content
Permalink
Browse files

dts: Rename SW._GPIO_* -> DT_ALIAS_SW._GPIOS_*

We use the following commands to rename any
SW._GPIO_{CONTROLLER,PIN,FLAGS} to
DT_ALIAS_SW._GPIOS_{CONTROLLER,PIN,FLAGS}

git grep -l SW._GPIO_CONTROLLER | xargs sed -i 's/SW\(.\)_GPIO_CONTROLLER/DT_ALIAS_SW\1_GPIOS_CONTROLLER/g'
git grep -l SW._GPIO_PIN | xargs sed -i 's/SW\(.\)_GPIO_PIN/DT_ALIAS_SW\1_GPIOS_PIN/g'
git grep -l SW._GPIO_FLAGS | xargs sed -i 's/SW\(.\)_GPIO_FLAGS/DT_ALIAS_SW\1_GPIOS_FLAGS/g'

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
  • Loading branch information...
galak committed Jun 22, 2019
1 parent b7d4b00 commit 284bc9d9642ac241b6b68e675453879c4df2cd46
@@ -20,7 +20,7 @@ static int warp7_m4_pinmux_init(struct device *dev)
IOMUXC_SW_PAD_CTL_PAD_ENET1_RGMII_RD0_DSE(0);
#endif

#ifdef SW0_GPIO_PIN
#ifdef DT_ALIAS_SW0_GPIOS_PIN
IOMUXC_SW_MUX_CTL_PAD_ENET1_RGMII_RD1 =
IOMUXC_SW_MUX_CTL_PAD_ENET1_RGMII_RD1_MUX_MODE(5);
#endif
@@ -406,14 +406,15 @@ the format specified by the YAML bindings. For example:
#define DT_GPIO_KEYS_BUTTON_0_GPIOS_FLAGS 0
#define DT_GPIO_KEYS_BUTTON_0_GPIOS_PIN 6
#define DT_GPIO_KEYS_BUTTON_0_LABEL "User SW2"
#define DT_GPIO_KEYS_SW1_GPIOS_CONTROLLER DT_GPIO_KEYS_BUTTON_0_GPIOS_CONTROLLER
#define DT_GPIO_KEYS_SW1_GPIOS_FLAGS DT_GPIO_KEYS_BUTTON_0_GPIOS_FLAGS
#define DT_GPIO_KEYS_SW1_GPIOS_PIN DT_GPIO_KEYS_BUTTON_0_GPIOS_PIN
#define DT_GPIO_KEYS_SW1_LABEL DT_GPIO_KEYS_BUTTON_0_LABEL
#define SW1_GPIO_CONTROLLER DT_GPIO_KEYS_BUTTON_0_GPIOS_CONTROLLER
#define SW1_GPIO_FLAGS DT_GPIO_KEYS_BUTTON_0_GPIOS_FLAGS
#define SW1_GPIO_PIN DT_GPIO_KEYS_BUTTON_0_GPIOS_PIN
#define SW1_LABEL DT_GPIO_KEYS_BUTTON_0_LABEL
#define DT_GPIO_KEYS_SW1_GPIOS_CONTROLLER DT_GPIO_KEYS_BUTTON_0_GPIOS_CONTROLLER
#define DT_GPIO_KEYS_SW1_GPIOS_FLAGS DT_GPIO_KEYS_BUTTON_0_GPIOS_FLAGS
#define DT_GPIO_KEYS_SW1_GPIOS_PIN DT_GPIO_KEYS_BUTTON_0_GPIOS_PIN
#define DT_ALIAS_SW1_GPIOS_CONTROLLE DT_GPIO_KEYS_BUTTON_0_GPIOS_CONTROLLER
#define DT_ALIAS_SW1_GPIOS_FLAGS DT_GPIO_KEYS_BUTTON_0_GPIOS_FLAGS
#define DT_ALIAS_SW1_GPIOS_PIN DT_GPIO_KEYS_BUTTON_0_GPIOS_PIN
#define DT_ALIAS_SW1_LABEL DT_GPIO_KEYS_BUTTON_0_LABEL


Additionally, a file named ``generated_dts_board_fixups.h`` is
generated in the same directory concatenating all board-related fixup files.
@@ -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 SW0_GPIO_CONTROLLER)
- SW0_GPIO_PIN
- SW0_GPIO_NAME (or DT_ALIAS_SW0_GPIOS_CONTROLLER)
- DT_ALIAS_SW0_GPIOS_PIN

Alternatively, this could also be done by defining 'sw0' alias in the board
device tree description file.
@@ -11,42 +11,42 @@
#include <sys/printk.h>

/* change this to use another GPIO port */
#ifndef SW0_GPIO_CONTROLLER
#ifndef DT_ALIAS_SW0_GPIOS_CONTROLLER
#ifdef SW0_GPIO_NAME
#define SW0_GPIO_CONTROLLER SW0_GPIO_NAME
#define DT_ALIAS_SW0_GPIOS_CONTROLLER SW0_GPIO_NAME
#else
#error SW0_GPIO_NAME or SW0_GPIO_CONTROLLER needs to be set in board.h
#error SW0_GPIO_NAME or DT_ALIAS_SW0_GPIOS_CONTROLLER needs to be set in board.h
#endif
#endif
#define PORT SW0_GPIO_CONTROLLER
#define PORT DT_ALIAS_SW0_GPIOS_CONTROLLER

/* change this to use another GPIO pin */
#ifdef SW0_GPIO_PIN
#define PIN SW0_GPIO_PIN
#ifdef DT_ALIAS_SW0_GPIOS_PIN
#define PIN DT_ALIAS_SW0_GPIOS_PIN
#else
#error SW0_GPIO_PIN needs to be set in board.h
#error DT_ALIAS_SW0_GPIOS_PIN needs to be set in board.h
#endif

/* change to use another GPIO pin interrupt config */
#ifdef SW0_GPIO_FLAGS
#define EDGE (SW0_GPIO_FLAGS | GPIO_INT_EDGE)
#ifdef DT_ALIAS_SW0_GPIOS_FLAGS
#define EDGE (DT_ALIAS_SW0_GPIOS_FLAGS | GPIO_INT_EDGE)
#else
/*
* If SW0_GPIO_FLAGS not defined used default EDGE value.
* If DT_ALIAS_SW0_GPIOS_FLAGS not defined used default EDGE value.
* Change this to use a different interrupt trigger
*/
#define EDGE (GPIO_INT_EDGE | GPIO_INT_ACTIVE_LOW)
#endif

/* change this to enable pull-up/pull-down */
#ifndef SW0_GPIO_FLAGS
#ifdef SW0_GPIO_PIN_PUD
#define SW0_GPIO_FLAGS SW0_GPIO_PIN_PUD
#ifndef DT_ALIAS_SW0_GPIOS_FLAGS
#ifdef DT_ALIAS_SW0_GPIOS_PIN_PUD
#define DT_ALIAS_SW0_GPIOS_FLAGS DT_ALIAS_SW0_GPIOS_PIN_PUD
#else
#define SW0_GPIO_FLAGS 0
#define DT_ALIAS_SW0_GPIOS_FLAGS 0
#endif
#endif
#define PULL_UP SW0_GPIO_FLAGS
#define PULL_UP DT_ALIAS_SW0_GPIOS_FLAGS

/* Sleep time */
#define SLEEP_TIME 500
@@ -30,13 +30,13 @@ static void configure_button(void)
{
static struct gpio_callback button_cb;

gpio = device_get_binding(SW0_GPIO_CONTROLLER);
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);

gpio_pin_configure(gpio, SW0_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));

gpio_init_callback(&button_cb, button_pressed, BIT(SW0_GPIO_PIN));
gpio_init_callback(&button_cb, button_pressed, BIT(DT_ALIAS_SW0_GPIOS_PIN));

gpio_add_callback(gpio, &button_cb);
}
@@ -52,7 +52,7 @@ void board_output_number(bt_mesh_output_action_t action, u32_t number)

oob_number = number;

gpio_pin_enable_callback(gpio, SW0_GPIO_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);

mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT, K_FOREVER, &arrow, 1);
}
@@ -67,7 +67,7 @@ void board_prov_complete(void)
{ 0, 1, 1, 1, 0 });


gpio_pin_disable_callback(gpio, SW0_GPIO_PIN);
gpio_pin_disable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);

mb_display_image(disp, MB_DISPLAY_MODE_DEFAULT, K_SECONDS(10),
&arrow, 1);
@@ -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(SW0_GPIO_PIN)) {
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
k_work_submit(&button_work);
} else {
u16_t target = board_set_target();
@@ -227,21 +227,21 @@ static void configure_button(void)

k_work_init(&button_work, button_send_pressed);

gpio = device_get_binding(SW0_GPIO_CONTROLLER);
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);

gpio_pin_configure(gpio, SW0_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));
gpio_pin_configure(gpio, SW1_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));

gpio_init_callback(&button_cb, button_pressed,
BIT(SW0_GPIO_PIN) | BIT(SW1_GPIO_PIN));
BIT(DT_ALIAS_SW0_GPIOS_PIN) | BIT(DT_ALIAS_SW1_GPIOS_PIN));
gpio_add_callback(gpio, &button_cb);

gpio_pin_enable_callback(gpio, SW0_GPIO_PIN);
gpio_pin_enable_callback(gpio, SW1_GPIO_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW1_GPIOS_PIN);
}

void board_init(u16_t *addr)
@@ -395,7 +395,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
u32_t pins)
{
/* Filter out spurious presses */
if (pins & BIT(SW0_GPIO_PIN)) {
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
printk("A pressed\n");
if (k_uptime_delta(&a_timestamp) < K_MSEC(100)) {
printk("Too quick A presses\n");
@@ -423,7 +423,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,
return;
}

if (pins & BIT(SW0_GPIO_PIN)) {
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
if (select) {
pong_select_change();
return;
@@ -486,20 +486,20 @@ static void configure_buttons(void)
static struct gpio_callback button_cb;
struct device *gpio;

gpio = device_get_binding(SW0_GPIO_CONTROLLER);
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);

gpio_pin_configure(gpio, SW0_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));
gpio_pin_configure(gpio, SW1_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb, button_pressed,
BIT(SW0_GPIO_PIN) | BIT(SW1_GPIO_PIN));
BIT(DT_ALIAS_SW0_GPIOS_PIN) | BIT(DT_ALIAS_SW1_GPIOS_PIN));
gpio_add_callback(gpio, &button_cb);

gpio_pin_enable_callback(gpio, SW0_GPIO_PIN);
gpio_pin_enable_callback(gpio, SW1_GPIO_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW1_GPIOS_PIN);
}

void main(void)
@@ -57,7 +57,7 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb,

beep_active = true;

if (pins & BIT(SW0_GPIO_PIN)) {
if (pins & BIT(DT_ALIAS_SW0_GPIOS_PIN)) {
printk("A pressed\n");
if (period < PERIOD_MAX) {
period += 50U;
@@ -82,16 +82,16 @@ void main(void)
{
static struct gpio_callback button_cb;

gpio = device_get_binding(SW0_GPIO_CONTROLLER);
gpio = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);

gpio_pin_configure(gpio, SW0_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));
gpio_pin_configure(gpio, SW1_GPIO_PIN,
gpio_pin_configure(gpio, DT_ALIAS_SW1_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb, button_pressed,
BIT(SW0_GPIO_PIN) | BIT(SW1_GPIO_PIN));
BIT(DT_ALIAS_SW0_GPIOS_PIN) | BIT(DT_ALIAS_SW1_GPIOS_PIN));
gpio_add_callback(gpio, &button_cb);

pwm = device_get_binding(CONFIG_PWM_NRF5_SW_0_DEV_NAME);
@@ -100,6 +100,6 @@ void main(void)
/* Notify with a beep that we've started */
k_work_submit(&beep_work);

gpio_pin_enable_callback(gpio, SW0_GPIO_PIN);
gpio_pin_enable_callback(gpio, SW1_GPIO_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW0_GPIOS_PIN);
gpio_pin_enable_callback(gpio, DT_ALIAS_SW1_GPIOS_PIN);
}
@@ -419,10 +419,10 @@ static u8_t dev_uuid[16] = { 0xdd, 0xdd };
static uint8_t pin_to_sw(uint32_t pin_pos)
{
switch (pin_pos) {
case BIT(SW0_GPIO_PIN): return 0;
case BIT(SW1_GPIO_PIN): return 1;
case BIT(SW2_GPIO_PIN): return 2;
case BIT(SW3_GPIO_PIN): return 3;
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;
}

printk("No match for GPIO pin 0x%08x\n", pin_pos);
@@ -612,27 +612,27 @@ void main(void)
/* Initialize button count timer */
k_timer_init(&sw.button_timer, button_cnt_timer, NULL);

sw_device = device_get_binding(SW0_GPIO_CONTROLLER);
gpio_pin_configure(sw_device, SW0_GPIO_PIN,
sw_device = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio_pin_configure(sw_device, DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_PUD_PULL_UP));
gpio_pin_configure(sw_device, SW1_GPIO_PIN,
gpio_pin_configure(sw_device, DT_ALIAS_SW1_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_PUD_PULL_UP));
gpio_pin_configure(sw_device, SW2_GPIO_PIN,
gpio_pin_configure(sw_device, DT_ALIAS_SW2_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_PUD_PULL_UP));
gpio_pin_configure(sw_device, SW3_GPIO_PIN,
gpio_pin_configure(sw_device, DT_ALIAS_SW3_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_PUD_PULL_UP));
gpio_init_callback(&button_cb, button_pressed,
BIT(SW0_GPIO_PIN) | BIT(SW1_GPIO_PIN) |
BIT(SW2_GPIO_PIN) | BIT(SW3_GPIO_PIN));
BIT(DT_ALIAS_SW0_GPIOS_PIN) | BIT(DT_ALIAS_SW1_GPIOS_PIN) |
BIT(DT_ALIAS_SW2_GPIOS_PIN) | BIT(DT_ALIAS_SW3_GPIOS_PIN));
gpio_add_callback(sw_device, &button_cb);
gpio_pin_enable_callback(sw_device, SW0_GPIO_PIN);
gpio_pin_enable_callback(sw_device, SW1_GPIO_PIN);
gpio_pin_enable_callback(sw_device, SW2_GPIO_PIN);
gpio_pin_enable_callback(sw_device, SW3_GPIO_PIN);
gpio_pin_enable_callback(sw_device, DT_ALIAS_SW0_GPIOS_PIN);
gpio_pin_enable_callback(sw_device, DT_ALIAS_SW1_GPIOS_PIN);
gpio_pin_enable_callback(sw_device, DT_ALIAS_SW2_GPIOS_PIN);
gpio_pin_enable_callback(sw_device, DT_ALIAS_SW3_GPIOS_PIN);

/* Initialize LED's */
init_led(0, LED0_GPIO_CONTROLLER, LED0_GPIO_PIN);
@@ -50,39 +50,39 @@ void app_gpio_init(void)

k_work_init(&button_work, publish);

button_device[0] = device_get_binding(SW0_GPIO_CONTROLLER);
gpio_pin_configure(button_device[0], SW0_GPIO_PIN,
button_device[0] = device_get_binding(DT_ALIAS_SW0_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[0], DT_ALIAS_SW0_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_PUD_PULL_UP |
GPIO_INT_DEBOUNCE | GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb[0], button_pressed, BIT(SW0_GPIO_PIN));
gpio_init_callback(&button_cb[0], button_pressed, BIT(DT_ALIAS_SW0_GPIOS_PIN));
gpio_add_callback(button_device[0], &button_cb[0]);
gpio_pin_enable_callback(button_device[0], SW0_GPIO_PIN);
gpio_pin_enable_callback(button_device[0], DT_ALIAS_SW0_GPIOS_PIN);

button_device[1] = device_get_binding(SW1_GPIO_CONTROLLER);
gpio_pin_configure(button_device[1], SW1_GPIO_PIN,
button_device[1] = device_get_binding(DT_ALIAS_SW1_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[1], DT_ALIAS_SW1_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_PUD_PULL_UP |
GPIO_INT_DEBOUNCE | GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb[1], button_pressed, BIT(SW1_GPIO_PIN));
gpio_init_callback(&button_cb[1], button_pressed, BIT(DT_ALIAS_SW1_GPIOS_PIN));
gpio_add_callback(button_device[1], &button_cb[1]);
gpio_pin_enable_callback(button_device[1], SW1_GPIO_PIN);
gpio_pin_enable_callback(button_device[1], DT_ALIAS_SW1_GPIOS_PIN);

button_device[2] = device_get_binding(SW2_GPIO_CONTROLLER);
gpio_pin_configure(button_device[2], SW2_GPIO_PIN,
button_device[2] = device_get_binding(DT_ALIAS_SW2_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[2], DT_ALIAS_SW2_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_PUD_PULL_UP |
GPIO_INT_DEBOUNCE | GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb[2], button_pressed, BIT(SW2_GPIO_PIN));
gpio_init_callback(&button_cb[2], button_pressed, BIT(DT_ALIAS_SW2_GPIOS_PIN));
gpio_add_callback(button_device[2], &button_cb[2]);
gpio_pin_enable_callback(button_device[2], SW2_GPIO_PIN);
gpio_pin_enable_callback(button_device[2], DT_ALIAS_SW2_GPIOS_PIN);

button_device[3] = device_get_binding(SW3_GPIO_CONTROLLER);
gpio_pin_configure(button_device[3], SW3_GPIO_PIN,
button_device[3] = device_get_binding(DT_ALIAS_SW3_GPIOS_CONTROLLER);
gpio_pin_configure(button_device[3], DT_ALIAS_SW3_GPIOS_PIN,
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_PUD_PULL_UP |
GPIO_INT_DEBOUNCE | GPIO_INT_ACTIVE_LOW));
gpio_init_callback(&button_cb[3], button_pressed, BIT(SW3_GPIO_PIN));
gpio_init_callback(&button_cb[3], button_pressed, BIT(DT_ALIAS_SW3_GPIOS_PIN));
gpio_add_callback(button_device[3], &button_cb[3]);
gpio_pin_enable_callback(button_device[3], SW3_GPIO_PIN);
gpio_pin_enable_callback(button_device[3], DT_ALIAS_SW3_GPIOS_PIN);
}

0 comments on commit 284bc9d

Please sign in to comment.
You can’t perform that action at this time.