Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Need clear understanding about CAF example project

I am working on nrf52840 and using v2.7.0 SDK. in led_state_def.h (i modified it a little)

static const struct led_effect led_effect[] = {
    [LED_EFFECT_ID_OFF] = LED_EFFECT_LED_OFF(),
    [LED_EFFECT_ID_BLINK] = LED_EFFECT_LED_BLINK(2000, LED_COLOR(10, 255, 10)),
    [LED_EFFECT_ID_BREATH] = LED_EFFECT_LED_BREATH(2000, LED_COLOR(255, 255, 255)),
    [LED_EFFECT_ID_CLOCK] = LED_EFFECT_LED_CLOCK(3, LED_COLOR(255, 255, 255)),
    [LED_EFFECT_ID_BLINK_SLOW] = LED_EFFECT_LED_BLINK(10000, LED_COLOR(255,255,255)),
    [LED_EFFECT_ID_BLINK_FAST] = LED_EFFECT_LED_BLINK(50, LED_COLOR(255,255,255))

};

I dont understand the role of LED_COLOR() here. Seems like it is for RGB Led but for dev kit we have single color led. i am kind of confused because in this example overlay file have 4 pwm pins so why each pin has its own individual LED_COLOR() with 3 values. Should not it has only one value maybe telling duty cycle between 0-255 for a single pin? How is it working?

What if i want to use this program with RGB LED, i understand i can connect 3 pwm0-2 given in overlay to R, G, B of my tri color led , but again why 3 different values for each pin in LED_COLOR()?

Thanks.
Parents
  • Hello,

    I think you should study the application sample in:

    NCS\nrf\applications\nrf_desktop

    And look there how it is used. But again, I am not convinced that this is the easiest way to control some RGB leds. 

    If you look at how the led_state_def.h is being used in led_state.c (ncs\nrf\samples\caf\src\modules\led_state.c), these gpios are set in the file:

    nrf\samples\caf\boards\<board_name>.overlay, and the pwmleds1, pwmleds2 and pwmleds3, which I believe is what you are asking.

    Best regards,

    Edvin

  • Thanks, i got some idea and i was able to understand how this example works with CAF LED as PWM. But now there is an option to change LED PWM to LED GPIO. after doing that i am not sure what all changes overlay file would need for this LED GPIO CAF. Here is my sample but it does not work at all: 

     / {
        gpio_leds {
            compatible = "gpio-leds";
            status = "okay";

            led4: led_4 {
                gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
                label = "LED 4";
            };

            led5: led_5 {
                gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
                label = "LED 5";
            };

            led6: led_6 {
                gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
                label = "LED 6";
            };
        };
    };




    &gpio0 {
        status = "okay";
    };
    &gpio1 {
        status = "okay";
    };

    Then i debug the code and in leds.c file led[] has no instance of gpios that i setup. Any idea on this? thanks
Reply
  • Thanks, i got some idea and i was able to understand how this example works with CAF LED as PWM. But now there is an option to change LED PWM to LED GPIO. after doing that i am not sure what all changes overlay file would need for this LED GPIO CAF. Here is my sample but it does not work at all: 

     / {
        gpio_leds {
            compatible = "gpio-leds";
            status = "okay";

            led4: led_4 {
                gpios = <&gpio1 2 GPIO_ACTIVE_LOW>;
                label = "LED 4";
            };

            led5: led_5 {
                gpios = <&gpio1 3 GPIO_ACTIVE_LOW>;
                label = "LED 5";
            };

            led6: led_6 {
                gpios = <&gpio1 4 GPIO_ACTIVE_LOW>;
                label = "LED 6";
            };
        };
    };




    &gpio0 {
        status = "okay";
    };
    &gpio1 {
        status = "okay";
    };

    Then i debug the code and in leds.c file led[] has no instance of gpios that i setup. Any idea on this? thanks
Children
Related