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,

    Try adding 

    #include <soc.h>
    to the file where you have this:
    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 = NRF_DT_GPIOS_TO_PSEL(DT_ALIAS(bkey), gpios),
    };
Children
Related