Skip to content

Instantly share code, notes, and snippets.

@mcrosson
Created December 31, 2020 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcrosson/79fcda86ce301d0ba607b71b7223f5f1 to your computer and use it in GitHub Desktop.
Save mcrosson/79fcda86ce301d0ba607b71b7223f5f1 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2020 The ZMK Contributors
* SPDX-License-Identifier: MIT
*/
/dts-v1/;
#include <nordic/nrf52840_qiaa.dtsi>
/ {
model = "nRF52840-MDK Dongle Dev Kit";
compatible = "makerdiary,nrf52840_mdk_dongle";
chosen {
zephyr,code-partition = &code_partition;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
};
leds {
compatible = "gpio-leds";
led_green: led_green {
gpios = <&gpio0 22 GPIO_ACTIVE_LOW>;
label = "Green LED";
};
led_red: led_red {
gpios = <&gpio0 23 GPIO_ACTIVE_LOW>;
label = "Red LED";
};
led_blue: led_blue {
gpios = <&gpio0 24 GPIO_ACTIVE_LOW>;
label = "Blue LED";
};
};
pwmleds {
compatible = "pwm-leds";
pwm_led_green: pwm_led_green {
pwms = <&pwm0 22>;
label = "Green PWM LED";
};
pwm_led_red: pwm_led_red {
pwms = <&pwm0 23>;
label = "Red PWM LED";
};
pwm_led_blue: pwm_led_blue {
pwms = <&pwm0 24>;
label = "Blue PWM LED";
};
};
buttons {
compatible = "gpio-keys";
button0: button0 {
gpios = <&gpio0 18 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
label = "Push button switch 0";
};
};
/* These aliases are provided for compatibility with samples */
aliases {
led-green = &led_green;
led-red = &led_red;
led-blue = &led_blue;
pwm-led-green = &pwm_led_green;
pwm-led-red = &pwm_led_red;
pwm-led-blue = &pwm_led_blue;
};
};
&adc {
status = "okay";
};
&gpiote {
status = "okay";
};
&gpio0 {
status = "okay";
};
&gpio1 {
status = "okay";
};
&flash0 {
/*
* For more information, see:
* http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html
*/
partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;
sd_partition: partition@0 {
label = "mbr";
reg = <0x00000000 0x00001000>;
};
code_partition: partition@1000 {
label = "code_partition";
reg = <0x00001000 0x000d3000>;
};
/*
* The flash starting at 0x000d4000 and ending at
* 0x000f3fff is reserved for use by the application.
*/
/*
* Storage partition will be used by FCB/LittleFS/NVS
* if enabled.
*/
storage_partition: partition@d4000 {
label = "storage";
reg = <0x000d4000 0x00020000>;
};
boot_partition: partition@f4000 {
label = "adafruit_boot";
reg = <0x000f4000 0x0000c000>;
};
};
};
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>
/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS 1000
/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led-blue)
#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0 DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led devicetree alias is not defined"
#define LED0 ""
#define PIN 0
#define FLAGS 0
#endif
void main(void)
{
const struct device *dev;
bool led_is_on = true;
int ret;
dev = device_get_binding(LED0);
if (dev == NULL) {
return;
}
ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT | FLAGS);
if (ret < 0) {
return;
}
while (1) {
gpio_pin_set(dev, PIN, (int)true);
led_is_on = !led_is_on;
k_msleep(SLEEP_TIME_MS);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment