Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
caksoylar committed Jul 27, 2023
1 parent 4b7e54d commit 0ed02e3
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions config/boards/shields/rommana/leds.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
/*
* Copyright (c) 2020 Seagate Technology LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <errno.h>
#include <zephyr/drivers/led.h>
#include <zephyr/sys/util.h>
#include <zephyr/kernel.h>
#include <zephyr/init.h>
#include <zephyr/bluetooth/services/bas.h>
Expand All @@ -27,21 +19,27 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

static const struct device *led_dev = DEVICE_DT_GET(LED_GPIO_NODE_ID);

struct led_state {
struct led_action {
struct k_work_delayable work;
bool turn_on;
uint8_t led_idx;
bool turn_on;
};

static struct led_state red_off = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led0)), .turn_on = false};
static struct led_state red_on = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led0)), .turn_on = true};
static struct led_state grn_off = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led1)), .turn_on = false};
static struct led_state grn_on = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led1)), .turn_on = true};
static struct led_state blu_off = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led2)), .turn_on = false};
static struct led_state blu_on = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led2)), .turn_on = true};
static struct led_action red_off = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led0)),
.turn_on = false};
static struct led_action red_on = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led0)),
.turn_on = true};
static struct led_action grn_off = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led1)),
.turn_on = false};
static struct led_action grn_on = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led1)),
.turn_on = true};
static struct led_action blu_off = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led2)),
.turn_on = false};
static struct led_action blu_on = {.led_idx = DT_NODE_CHILD_IDX(DT_NODELABEL(led2)),
.turn_on = true};

static void led_work(struct k_work *work) {
struct led_state *action = CONTAINER_OF(work, struct led_state, work);
struct led_action *action = CONTAINER_OF(work, struct led_action, work);
LOG_INF("Switching led %d to state %d", action->led_idx, action->turn_on);
if (action->turn_on) {
led_on(led_dev, action->led_idx);
Expand Down

0 comments on commit 0ed02e3

Please sign in to comment.