Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ build
# West files
.west
deps

# Custom workspace configuration
.vscode
7 changes: 7 additions & 0 deletions l2-task1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.20.0)

set(KCONFIG_ROOT ${CMAKE_CURRENT_LIST_DIR}/Kconfig.projbuild)
find_package(Zephyr REQUIRED)
project(my_zephyr_app)

target_sources(app PRIVATE src/main.cpp)
9 changes: 9 additions & 0 deletions l2-task1/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source "Kconfig.zephyr"

menu "Application options"

config BLINKY_SLEEP_MS
int "Time in ms between LED toggle"
default 500

endmenu
2 changes: 2 additions & 0 deletions l2-task1/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_GPIO=y
CONFIG_LOG=y
28 changes: 28 additions & 0 deletions l2-task1/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

/* The devicetree node identifier for the "led0" alias. */
#define LED_NODE DT_ALIAS(led0)

static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED_NODE, gpios);

LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);

int main(void)
{
bool led_state = true;

if (!gpio_is_ready_dt(&led)) return 0;

if (gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE) < 0) return 0;

while (1) {
if (gpio_pin_toggle_dt(&led) < 0) return 0;

led_state = !led_state;
LOG_INF("LED state: %s", led_state ? "ON" : "OFF");
k_msleep(CONFIG_BLINKY_SLEEP_MS);
}
return 0;
}