diff --git a/snippets/button/code.txt b/snippets/button/code.txt index 2e9bf00..02bdc32 100644 --- a/snippets/button/code.txt +++ b/snippets/button/code.txt @@ -1,3 +1,30 @@ +#include +#include +#include +#include +#include + +#define SLEEP_TIME_MS 1 + +/* + * Get button configuration from the devicetree sw0 alias. This is mandatory. + */ +#define SW0_NODE DT_ALIAS(sw0) +#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) +#error "Unsupported board: sw0 devicetree alias is not defined" +#endif +static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, + {0}); +static struct gpio_callback button_cb_data; + +/* + * The led0 devicetree alias is optional. If present, we'll use it + * to turn on the LED whenever the button is pressed. + */ +static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, + {0}); + + void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { diff --git a/snippets/button/imports.txt b/snippets/button/imports.txt deleted file mode 100644 index 3795edf..0000000 --- a/snippets/button/imports.txt +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include -#include - -#define SLEEP_TIME_MS 1 - -/* - * Get button configuration from the devicetree sw0 alias. This is mandatory. - */ -#define SW0_NODE DT_ALIAS(sw0) -#if !DT_NODE_HAS_STATUS(SW0_NODE, okay) -#error "Unsupported board: sw0 devicetree alias is not defined" -#endif -static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios, - {0}); -static struct gpio_callback button_cb_data; - -/* - * The led0 devicetree alias is optional. If present, we'll use it - * to turn on the LED whenever the button is pressed. - */ -static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios, - {0}); diff --git a/snippets/led/code.txt b/snippets/led/code.txt index 7b91bfb..7fc034d 100644 --- a/snippets/led/code.txt +++ b/snippets/led/code.txt @@ -1,3 +1,12 @@ +/* --------- */ +/* LED */ +/* --------- */ + +/* Imports / Declarations */ +#include +#define LED0_NODE DT_ALIAS(led0) + +/* Functions */ int blink_led(void) { int ret; @@ -18,4 +27,15 @@ int blink_led(void) { k_msleep(1000); } return 0; -} \ No newline at end of file +} + +/* +Example: + +int main(void) +{ + blink_led(); + + return 0; +} +*/ \ No newline at end of file diff --git a/snippets/led/imports.txt b/snippets/led/imports.txt deleted file mode 100644 index 40066b9..0000000 --- a/snippets/led/imports.txt +++ /dev/null @@ -1,2 +0,0 @@ -#include -#define LED0_NODE DT_ALIAS(led0) \ No newline at end of file