Add new button on nrf5340 Audio DK fail

Hello,

I want to add an extra button on nrf5340 Audio DK.

I use P1.14 as the pin of this new button and set it in the overlay file.

/ {
	buttons {
			compatible = "gpio-keys";
			button6: button_6 {
					gpios = <&gpio1 14 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
					label = "Push button 6";
			};
	};
	aliases {
		bkey = &button6;
	};
};

The default buttons use DT_GPIO_PIN to get the pin cell value, but according to the settings in gpio.h, DT_GPIO_PIN is only used by the PIO of gpio0, not including the P1.14 I use.

So I use DT_GPIO_PIN_BY_IDX to read the pin cell value of the new button, the following is my code:

/** @brief List of buttons and associated metadata
 */
enum button_pin_names {
	BUTTON_VOLUME_DOWN = DT_GPIO_PIN(DT_ALIAS(sw0), gpios),
	BUTTON_VOLUME_UP = DT_GPIO_PIN(DT_ALIAS(sw1), gpios),
	BUTTON_PLAY_PAUSE = DT_GPIO_PIN(DT_ALIAS(sw2), gpios),
	BUTTON_4 = DT_GPIO_PIN(DT_ALIAS(sw3), gpios),
	BUTTON_5 = DT_GPIO_PIN(DT_ALIAS(sw4), gpios),
	BUTTON_6 = DT_GPIO_PIN_BY_IDX(DT_ALIAS(bkey), gpios, 1),
};

Then I get an error during building: identifier "DT_N_S_buttons_S_button_6_P_gpios_IDX_1_VAL_pin" is undefined

But if I use DT_GPIO_PIN instead or modify the idx parameter of DT_GPIO_PIN_BY_IDX to 0, the build will succeed without error.

I'm not quite sure where the problem is, if I want to use the PIO of gpio1, is there anything else I need to modify?

Parents Reply
  • Hi,

    It works.Thank you very much.

    But after I add BUTTON_6 to my button configure and flash to the nrf5340 audio dk board,it occurrs error:

    Here is the code I add:

    const static struct btn_config btn_cfg[] = {
    	{
    		.btn_name = STRINGIFY(BUTTON_VOLUME_DOWN),
    		.btn_pin = BUTTON_VOLUME_DOWN,
    		.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw0), gpios),
    	},
    	{
    		.btn_name = STRINGIFY(BUTTON_VOLUME_UP),
    		.btn_pin = BUTTON_VOLUME_UP,
    		.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw1), gpios),
    	},
    	{
    		.btn_name = STRINGIFY(BUTTON_PLAY_PAUSE),
    		.btn_pin = BUTTON_PLAY_PAUSE,
    		.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw2), gpios),
    	},
    	{
    		.btn_name = STRINGIFY(BUTTON_4),
    		.btn_pin = BUTTON_4,
    		.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw3), gpios),
    	},
    	{
    		.btn_name = STRINGIFY(BUTTON_5),
    		.btn_pin = BUTTON_5,
    		.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(sw4), gpios),
    	},
    	{
    		.btn_name = STRINGIFY(BUTTON_6),
    		.btn_pin = BUTTON_6,
    		.btn_cfg_mask = DT_GPIO_FLAGS(DT_ALIAS(bkey), gpios),
    	}
    };

    How to enable this pin?

Children
Related