Re: Syntax in dts file for defining a GPIO output based on nxp,kinetis-gpio.yaml #defines
Andrei Gansari
Hello,
Yes, my example was hardcoded in regard to port and pin number. Your example makes them configurable via dts, while code remains the same.
I only have to point another thing: the generated macros name will remain the same in other dts configurations if you keep the same name across dts (in the example: _test {} ).
Regards, Andrei
From: devel@... <devel@...>
On Behalf Of Bo.Kragelund via Lists.Zephyrproject.Org
Sent: Thursday, March 28, 2019 5:06 PM To: devel@... Cc: devel@... Subject: Re: [Zephyr-devel] Syntax in dts file for defining a GPIO output based on nxp,kinetis-gpio.yaml #defines
Hello Andrei, _test { compatible = "gpio-xxx"; test_pin { gpios = <&gpiob 22 0>; label = "My test pin"; }; };
/* test_pin */ #define DT_GPIO_OUT_TEST_PIN_GPIO_CONTROLLER "GPIO_1" #define DT_GPIO_OUT_TEST_PIN_GPIO_FLAGS 0 #define DT_GPIO_OUT_TEST_PIN_GPIO_PIN 22 #define DT_GPIO_OUT_TEST_PIN_LABEL "My test pin"
We don't use alias because we want to see in the code, that the defines comes from dts.
gpio_pin_configure(wdt_device, DT_GPIO_OUT_TEST_PIN_GPIO_PIN, GPIO_DIR_OUT | DT_GPIO_OUT_TEST_PIN_GPIO_FLAGS); gpio_pin_write(wdt_device, DT_GPIO_OUT_TEST_PIN_GPIO_PIN, 1);
I guess this is a way to do it, if you want to keep your code independant of pin numbers etc.
|
|