/ {
    zephyr,user {
        io-channels = <&adc 0>;
    };

    pwmleds {
        compatible = "pwm-leds";
        pwm_led0: pwm_led_0 {
            pwms = <&pwm0 0 PWM_MSEC(1) PWM_POLARITY_INVERTED>;  // inverted polarity
            label = "PWM LED0";
        };
        pwm_led1: pwm_led_1 {
            pwms = <&pwm0 1 PWM_MSEC(1) PWM_POLARITY_INVERTED>;  // inverted polarity
            label = "PWM LED1";
        };
        pwm_buzzer: pwm_buzzer_0 {
            pwms = <&pwm0 2 PWM_MSEC(1) PWM_POLARITY_INVERTED>;
            label = "PWM Buzzer";
        };
    };
    leds {
        compatible = "gpio-leds";
        led0: led_0 {
            gpios = <&gpio0 16 GPIO_ACTIVE_LOW>;
            label = "Custom LED on P0.16";
        };
    };

    buttons {
        compatible = "gpio-keys";
        button0: button_0 {
            gpios = <&gpio0 20 (GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH)>;
            label = "User Button";
        };
    };
    
 
    aliases {
        led0 = &led0;
        pwm-led0 = &pwm_led0;  // Standard Zephyr PWM LED alias
        pwm-led1 = &pwm_led1;
        pwm-buzzer = &pwm_buzzer;
        pushbutton0 = &button0;
    };
};

&rtc0 {
    status = "okay";
    prescaler = <255>;  // Set max prescaler for lowest power
    interrupts = <16 1>;  // Set RTC0 interrupt to priority 1
    compatible = "nordic,nrf-rtc";  // Add this line
    clock-frequency = <32768>;      // Add this line
    reg = <0x4000b000 0x1000>;      // RTC0 register address
    cc-num = <3>;                   // Number of compare channels
};

// Disable unused hardware
&uart0 {
    status = "disabled";
};

&i2c0 {
    status = "disabled";
};

&spi0 {
    status = "disabled";
};

&adc {
    status = "okay";
    compatible = "nordic,nrf-saadc";    
    #address-cells = <1>;
    #size-cells = <0>;

    /* Add this line to ensure the ADC is active */
//    interrupts = <20 1>;  // Replace with the correct interrupt number for ADC

    channel@0 {
        reg = <0>;
        zephyr,gain = "ADC_GAIN_1_6";
        zephyr,reference = "ADC_REF_INTERNAL";
        zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
        zephyr,input-positive = <NRF_SAADC_AIN4>; // P0.28
        zephyr,resolution = <12>;
    };
};

&pwm0 {
    status = "okay";
    pinctrl-0 = <&pwm0_default>;
    pinctrl-1 = <&pwm0_sleep>;
    pinctrl-names = "default", "sleep";
    interrupts = <28 1>;
    interrupt-names = "pwm0";
};

&pinctrl {
    pwm0_default: pwm0_default {
        group1 {
            psels = <NRF_PSEL(PWM_OUT0, 0, 30)>,  // LED_GREEN on P0.30
                   <NRF_PSEL(PWM_OUT1, 0, 16)>,   // LED_RED on P0.16
                   <NRF_PSEL(PWM_OUT2, 0, 12)>;   // Buzzer on P0.12
            nordic,invert;  // Invert output for active-low LEDs and buzzer
        };
    };

    pwm0_sleep: pwm0_sleep {
        group1 {
            psels = <NRF_PSEL(PWM_OUT0, 0, 30)>,  // LED_GREEN on P0.30
                   <NRF_PSEL(PWM_OUT1, 0, 16)>,   // LED_RED on P0.16
                   <NRF_PSEL(PWM_OUT2, 0, 12)>;   // Buzzer on P0.12
            low-power-enable;
        };
    };
};



&ccm {
    status = "disabled";
};

&ecb {
    status = "disabled";
};

&rng {
    status = "okay";
};

&temp {
    status = "disabled";
};

&wdt {
    status = "disabled";
};

&swi2 {
    status = "disabled";
};

&swi4 {
    status = "disabled";
};

&swi3 {
    status = "disabled";
};

&swi5 {
    status = "disabled";
};

&rtc0 {
    status = "disabled";
};

&rtc1 {
    status = "disabled";
};
