Switching GPIO pin between input and output mode

Hi,

Could help me please?

What I need?

1) set GPIO pin as input with internal pulldown and set IRQ for Rising Edge.

In .overlay I add my pin like that:

Fullscreen
1
2
3
4
5
6
7
userpin{
compatible = "gpio-keys";
nslpin: nsl_pin{
gpios = <&gpio0 12 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
label = "No sleep line";
};
};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 Then in code I set pin as INPUT and enabled IRQ

Fullscreen
1
2
if(gpio_pin_configure_dt(&nslPin, GPIO_INPUT) < 0) while(1);
if(gpio_pin_interrupt_configure_dt(&nslPin, GPIO_INT_EDGE_RISING) != 0) while(1);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

2) In code I need sometimes to set this pin as output and set it to logical HIGH (3,3V)

So in code I disabled IRQ on this pin, set it like OUTPUT and set logical HIGH

Fullscreen
1
2
3
if(gpio_pin_interrupt_configure_dt(&nslPin, GPIO_INT_DISABLE) != 0) while(1);
if(gpio_pin_configure_dt(&nslPin, GPIO_OUTPUT) < 0) while(1);
gpio_pin_set_dt(&nslPin,1);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

3) Later on I need to set it again as in step 1 (set GPIO pin as input with internal pulldown and set IRQ for Rising Edge.)
Unfortunatelly it does not work I can always see (in the scope) the pin is in logical HIGH - what is wrong with my code?
Thank you for any help. Jan.