Automatically add code to main.c
All checks were successful
Build & Publish / build (push) Successful in 8m36s

This commit is contained in:
2023-08-03 14:44:16 +02:00
parent 555419f701
commit cfe0381610
6 changed files with 79 additions and 41 deletions

View File

@@ -1,32 +1,48 @@
/* --------- */
/* LED */
/* --------- */
/* --------------------------- */
/* LED */
/* --------------------------- */
/* Imports / Declarations */
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)
/*
* A build error on this line means your board is unsupported.
* See the sample documentation for information on how to fix this.
*/
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
/* Functions */
int blink_led(void) {
int initialize_led(void) {
int ret;
if (!gpio_is_ready_dt(&led)) {
return 0;
}
if (!gpio_is_ready_dt(&led)) {
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
return 0;
}
}
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
return 0;
}
k_msleep(1000);
}
return 0;
int blink_led(int blink_delay) {
int ret;
while (1) {
ret = gpio_pin_toggle_dt(&led);
if (ret < 0) {
return 0;
}
k_msleep(blink_delay);
}
return 0;
}
/*
@@ -34,7 +50,8 @@ Example:
int main(void)
{
blink_led();
initialize_led();
blink_led(10000); # Millis
return 0;
}

1
snippets/led/config.txt Normal file
View File

@@ -0,0 +1 @@
CONFIG_GPIO=y