diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 45c68856..07c78080 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -52,6 +52,8 @@ target_sources_ifdef(CONFIG_ZMK_KSCAN_MOCK_DRIVER app PRIVATE src/kscan_mock.c) target_sources_ifdef(CONFIG_ZMK_KSCAN_COMPOSITE_DRIVER app PRIVATE src/kscan_composite.c) target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c) target_sources_ifdef(CONFIG_ZMK_BLE app PRIVATE src/hog.c) +target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c) +target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c) target_sources(app PRIVATE src/endpoints.c) target_sources(app PRIVATE src/main.c) diff --git a/app/Kconfig b/app/Kconfig index 997409ef..df768b31 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -138,6 +138,30 @@ config ZMK_ACTION_MOD_TAP endmenu +menu "ZMK Lighting" + +menuconfig ZMK_RGB_UNDERGLOW + bool "RGB Adressable LED Underglow" + select LED_STRIP + +if ZMK_RGB_UNDERGLOW + +config ZMK_RGB_UNDERGLOW_HUE_STEP + int "RGB underglow hue step in degrees of 360" + default 10 + +config ZMK_RGB_UNDERGLOW_SAT_STEP + int "RGB underglow sturation step in percent" + default 10 + +config ZMK_RGB_UNDERGLOW_BRT_STEP + int "RGB underglow brightness step in percent" + default 10 + +endif + +endmenu + config HEAP_MEM_POOL_SIZE default 1024 diff --git a/app/boards/arm/nice_nano/nice_nano.dts b/app/boards/arm/nice_nano/nice_nano.dts index 8c010692..7c676e3e 100644 --- a/app/boards/arm/nice_nano/nice_nano.dts +++ b/app/boards/arm/nice_nano/nice_nano.dts @@ -52,16 +52,6 @@ scl-pin = <20>; }; -/* TODO: Needs testing */ -&spi0 { - compatible = "nordic,nrf-spi"; - /* Cannot be used together with i2c0. */ - /* status = "okay"; */ - sck-pin = <45>; - mosi-pin = <10>; - miso-pin = <43>; -}; - &uart0 { compatible = "nordic,nrf-uarte"; status = "okay"; diff --git a/app/src/behaviors/behavior_rgb_underglow.c b/app/src/behaviors/behavior_rgb_underglow.c new file mode 100644 index 00000000..9239f370 --- /dev/null +++ b/app/src/behaviors/behavior_rgb_underglow.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 Nick Winans + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT zmk_behavior_rgb_underglow + +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +struct behavior_rgb_underglow_config { }; +struct behavior_rgb_underglow_data { }; + +static int behavior_rgb_underglow_init(struct device *dev) +{ + return 0; +} diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c new file mode 100644 index 00000000..5b71aae5 --- /dev/null +++ b/app/src/rgb_underglow.c @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020 Nick Winans + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include + +#include +#include +#include + +LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); + +#define STRIP_LABEL DT_LABEL(DT_ALIAS(led_strip)) +#define STRIP_NUM_PIXELS DT_PROP(DT_ALIAS(led_strip), chain_length) + +#define DELAY_TIME K_MSEC(50) + +#define RGB(_r, _g, _b) { .r = (_r), .g = (_g), .b = (_b) } + +static const struct led_rgb colors[] = { + RGB(0x0f, 0x00, 0x00), /* red */ + RGB(0x00, 0x0f, 0x00), /* green */ + RGB(0x00, 0x00, 0x0f), /* blue */ +}; + +struct led_rgb pixels[STRIP_NUM_PIXELS]; + +static void zmk_rgb_underglow_start() +{ + struct device *strip; + size_t cursor = 0, color = 0; + int rc; + + strip = device_get_binding(STRIP_LABEL); + if (strip) { + LOG_INF("Found LED strip device %s", STRIP_LABEL); + } else { + LOG_ERR("LED strip device %s not found", STRIP_LABEL); + return; + } + + LOG_INF("Displaying pattern on strip"); + while (1) { + memset(&pixels, 0x00, sizeof(pixels)); + memcpy(&pixels[cursor], &colors[color], sizeof(struct led_rgb)); + rc = led_strip_update_rgb(strip, pixels, STRIP_NUM_PIXELS); + + if (rc) { + LOG_ERR("couldn't update strip: %d", rc); + } + + cursor++; + if (cursor >= STRIP_NUM_PIXELS) { + cursor = 0; + color++; + if (color == ARRAY_SIZE(colors)) { + color = 0; + } + } + + k_sleep(DELAY_TIME); + } +} + +static int zmk_rgb_underglow_init(struct device *_arg) +{ + zmk_rgb_underglow_start(); + + return 0; +} + +SYS_INIT(zmk_rgb_underglow_init, + APPLICATION, + CONFIG_APPLICATION_INIT_PRIORITY);