Add my_led

This commit is contained in:
hangpersonal committed 2026-10-08 00:09:26 -07:00
1 parent a6c62e56d8
commit c8fe95e63b
5 files changed
+86

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.20.0)
# Locate the Zephyr build system as a CMake package
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
# Project name
project(my_led)
# Add source files belong to this application
target_sources(app PRIVATE src/main.c)
+21
View File
@@ -0,0 +1,21 @@
/ {
custom_led0: custom_led0 {
compatible = "custom-led";
custom-gpios = <&gpioe 13 GPIO_ACTIVE_HIGH>;
my-delay-ms = <1000>; /* Optional, equals 500 by default */
};
aliases {
myled = &custom_led0;
};
};
&clk_hse {
clock-frequency = <DT_FREQ_M(25)>;
};
&pll {
div-m = <25>;
mul-n = <336>;
div-p = <2>;
div-q = <7>;
};
+14
View File
@@ -0,0 +1,14 @@
compatible: custom-led
description: Example custom node describing a single LED GPIO and a blink delay.
properties:
custom-gpios:
type: phandle-array
required: true
description: My LED GPIO.
my-delay-ms:
type: int
required: false
default: 500
description: Blink delay in milliseconds.
+6
View File
@@ -0,0 +1,6 @@
CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_ADC=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_CONSOLE=y
CONFIG_PRINTK=y
+35
View File
@@ -0,0 +1,35 @@
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#define LED_NODE DT_ALIAS(myled)
#define BLINK_DELAY_MS DT_PROP(LED_NODE, my_delay_ms)
const struct gpio_dt_spec led =
GPIO_DT_SPEC_GET(LED_NODE, custom_gpios);
int main(void) {
int ret;
if (!device_is_ready(led.port)) {
printk("LED GPIO device not ready\n");
return 0;
}
ret = gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
if (ret != 0) {
printk("Failed to configure LED: %d\n", ret);
return 0;
}
printk("Blinking with delay %d ms\n", BLINK_DELAY_MS);
while (1) {
gpio_pin_toggle_dt(&led);
k_sleep(K_MSEC(BLINK_DELAY_MS));
}
return 0;
}