zephyr-configurator/snippets/led/code.txt

64 lines
1.0 KiB
Plaintext
Raw Normal View History

2023-08-03 12:44:16 +00:00
/* --------------------------- */
/* LED */
/* --------------------------- */
2023-08-03 11:05:59 +00:00
/* Imports / Declarations */
2023-08-03 12:44:16 +00:00
#include <zephyr/kernel.h>
2023-08-03 11:05:59 +00:00
#include <zephyr/drivers/gpio.h>
2023-08-03 12:44:16 +00:00
/* The devicetree node identifier for the "led0" alias. */
2023-08-03 11:05:59 +00:00
#define LED0_NODE DT_ALIAS(led0)
2023-08-03 12:44:16 +00:00
/*
* 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);
2023-08-03 11:05:59 +00:00
/* Functions */
2023-08-03 12:44:16 +00:00
int initialize_led(void) {
2023-08-03 06:20:34 +00:00
int ret;
2023-08-03 12:44:16 +00:00
if (!gpio_is_ready_dt(&led)) {
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
if (ret < 0) {
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;
2023-08-03 11:05:59 +00:00
}
/*
Example:
int main(void)
{
2023-08-03 12:44:16 +00:00
initialize_led();
blink_led(10000); # Millis
2023-08-03 11:05:59 +00:00
return 0;
}
2023-08-04 08:27:09 +00:00
*/
/* --------------------------- */
/* LED End */
/* --------------------------- */