Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created August 7, 2025 10:49
Show Gist options
  • Save hidsh/5e401ca316a802a97c848881d9ace1cb to your computer and use it in GitHub Desktop.
Save hidsh/5e401ca316a802a97c848881d9ace1cb to your computer and use it in GitHub Desktop.
An Arduino-style "Blinky" patching to ZMK firmware (zmk-firmware/zmk/app/src/main.c)
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/settings/settings.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL);
#if IS_ENABLED(CONFIG_ZMK_DISPLAY)
#include <zmk/display.h>
#include <lvgl.h>
#endif
// pseudo arduino: begin vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#include <zephyr/drivers/gpio.h> // GPIO_XXXX
#define LED0_NODE DT_ALIAS(led0) // red
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
#define pinMode gpio_pin_configure_dt
#define digitalWrite gpio_pin_set_dt
void setup(void) {
pinMode(&led, GPIO_OUTPUT_ACTIVE);
}
void loop(void) {
digitalWrite(&led, 1); // HIGH
k_msleep(500);
digitalWrite(&led, 0); // LOW
k_msleep(500);
}
// pseudo arduino: end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
int main(void) {
LOG_INF("Welcome to ZMK!\n");
// pseudo arduino: begin vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
setup();
while (1) {
loop();
}
// pseudo arduino: end ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#if IS_ENABLED(CONFIG_SETTINGS)
settings_subsys_init();
settings_load();
#endif
#ifdef CONFIG_ZMK_DISPLAY
zmk_display_init();
#if IS_ENABLED(CONFIG_ARCH_POSIX)
// Workaround for an SDL display issue:
// https://github.com/zephyrproject-rtos/zephyr/issues/71410
while (1) {
lv_task_handler();
k_sleep(K_MSEC(10));
}
#endif
#endif /* CONFIG_ZMK_DISPLAY */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment