This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to add a new LED in zstack

Other Parts Discussed in Thread: CC2590, CC2592

The zstack define LED in hal_board_cfg as below

/* 1 - Green */
#define LED1_BV           BV(0)
#define LED1_SBIT         P1_0
#define LED1_DDR          P1DIR
#define LED1_POLARITY     ACTIVE_LOW

#if defined (HAL_BOARD_CC2530EB_REV17)
  /* 2 - Red */
  #define LED2_BV           BV(1)
  #define LED2_SBIT         P1_1
  #define LED2_DDR          P1DIR
  #define LED2_POLARITY     ACTIVE_LOW

  /* 3 - Yellow */
  #define LED3_BV           BV(4)
  #define LED3_SBIT         P1_4
  #define LED3_DDR          P1DIR
  #define LED3_POLARITY     ACTIVE_LOW

#endif

  but actually there only one LED is work  if we have use HAL_PA_PLA。 

  so i want to define a new LED in P15,

  could you please show me the way how to config a new LED?

  and please don't change the define as P11 To P15 ,just use LED2 same again。。。it was not work ,because that HAL_BOARD_CC2530EB_REV17 is collide with HAL_PA_PLA

  • When define HAL_PA_LNA or HAL_PA_LNA_CC2590, CC25530 will use P1.1 and P1.4 to control PA. It conflicts with default LED2 and LED3. If you have other pins to control LED2 and LED3. You can define HAL_NUM_LEDS to 3 and define the following LED related settings to available IO.

    For example, if LED2 can use P1.2 and LED3 uses P1.3

    /* LED2 P1.2*/
    #define LED2_BV BV(2)
    #define LED2_SBIT P1_2
    #define LED2_DDR P1DIR
    #define LED2_POLARITY ACTIVE_HIGH

    /* LED3 P1.3 */
    #define LED3_BV BV(3)
    #define LED3_SBIT P1_3
    #define LED3_DDR P1DIR
    #define LED3_POLARITY ACTIVE_HIGH

  • Yes , Chen 

               but it is not as simple as you said,just change the PIN define。

               have you seen the marco define of board

               i think there should be two steps Setting at least :

    •            HAL_BOARD_INIT()     setting

    #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || \
          defined (HAL_PA_LNA_CC2590)

    #define HAL_BOARD_INIT()                                         \
    {                                                                \
      uint16 i;                                                      \
                                                                     \
      SLEEPCMD &= ~OSC_PD;                       /* turn on 16MHz RC and 32MHz XOSC */                \
      while (!(SLEEPSTA & XOSC_STB));            /* wait for 32MHz XOSC stable */                     \
      asm("NOP");                                /* chip bug workaround */                            \
      for (i=0; i<504; i++) asm("NOP");          /* Require 63us delay for all revs */                \
      CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
      while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */   \
      SLEEPCMD |= OSC_PD;                        /* turn off 16MHz RC */                              \
                                                                     \
      /* Turn on cache prefetch mode */                              \
      PREFETCH_ENABLE();                                             \
                                                                     \
      LED1_DDR |= (LED1_BV | LED2_BV);                              \
                                                                     \
      /* Set PA/LNA HGM control P0_7 */                              \
      P0DIR |= BV(7);                                                \
                                                                     \
      /* configure tristates */                                      \
      P0INP |= PUSH2_BV;                                             \
                                                                     \
      /* setup RF frontend if necessary */                           \
      HAL_BOARD_RF_FRONTEND_SETUP();                                 \
    }

    • LED function setting

    #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || \
          defined (HAL_PA_LNA_CC2590)
      #define HAL_TURN_OFF_LED1()       st( LED1_SBIT = LED1_POLARITY (0); )
      #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
      #define HAL_TURN_OFF_LED3()       HAL_TURN_OFF_LED1()
      #define HAL_TURN_OFF_LED4()       HAL_TURN_OFF_LED1()

      #define HAL_TURN_ON_LED1()        st( LED1_SBIT = LED1_POLARITY (1); )
      #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
      #define HAL_TURN_ON_LED3()        HAL_TURN_ON_LED1()
      #define HAL_TURN_ON_LED4()        HAL_TURN_ON_LED1()

      #define HAL_TOGGLE_LED1()         st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
      #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
      #define HAL_TOGGLE_LED3()         HAL_TOGGLE_LED1()
      #define HAL_TOGGLE_LED4()         HAL_TOGGLE_LED1()

      #define HAL_STATE_LED1()          (LED1_POLARITY (LED1_SBIT))
      #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
      #define HAL_STATE_LED3()          HAL_STATE_LED1()
      #define HAL_STATE_LED4()          HAL_STATE_LED1()

    #endif

    do you agree?? and could you please correct me if i wrong ,

    Always thanks your powerful care!

  • Yes, I agree with you.

  • But ,i don't agree with myself ,because i have a new discovery。。。。

             it seems that there is nothing do with the HAL_NUM_LEDS,

             whether i set HAL_NUM_LEDS to 1 or to 2 , or any others。

             the new LED_2(defined  a new PIN) was always working ....

            so Why  ~~~~~~

  • If you set  HAL_NUM_LEDS to 1, you have to not define the followings:

      #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
      #define HAL_TURN_OFF_LED3()       st( LED3_SBIT = LED3_POLARITY (0); )
      #define HAL_TURN_OFF_LED4()       HAL_TURN_OFF_LED1()

      #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
      #define HAL_TURN_ON_LED3()        st( LED3_SBIT = LED3_POLARITY (1); )
      #define HAL_TURN_ON_LED4()        HAL_TURN_ON_LED1()

      #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
      #define HAL_TOGGLE_LED3()         st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
      #define HAL_TOGGLE_LED4()         HAL_TOGGLE_LED1()

      #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
      #define HAL_STATE_LED3()          (LED3_POLARITY (LED3_SBIT))
      #define HAL_STATE_LED4()          HAL_STATE_LED1()

  • Hi Chen

             maybe you use different zstack with me, the version of zstack which i used was1.21, the LED function define was like that :

            we use code under the blue define one, and the red code  was renew with me 。

            and i want to told you is  there is nothing change when i set HAL_NUM_LEDS to 1,or 2 。。。

           

    /* ----------- LED's ---------- */
    #if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && \
        !defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_SE2431L) && \
        !defined (HAL_PA_LNA_CC2592)
      #define HAL_TURN_OFF_LED1()       st( LED1_SBIT = LED1_POLARITY (0); )
      #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
      #define HAL_TURN_OFF_LED3()       st( LED3_SBIT = LED3_POLARITY (0); )
      #define HAL_TURN_OFF_LED4()       HAL_TURN_OFF_LED1()

      #define HAL_TURN_ON_LED1()        st( LED1_SBIT = LED1_POLARITY (1); )
      #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
      #define HAL_TURN_ON_LED3()        st( LED3_SBIT = LED3_POLARITY (1); )
      #define HAL_TURN_ON_LED4()        HAL_TURN_ON_LED1()

      #define HAL_TOGGLE_LED1()         st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
      #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
      #define HAL_TOGGLE_LED3()         st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
      #define HAL_TOGGLE_LED4()         HAL_TOGGLE_LED1()

      #define HAL_STATE_LED1()          (LED1_POLARITY (LED1_SBIT))
      #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
      #define HAL_STATE_LED3()          (LED3_POLARITY (LED3_SBIT))
      #define HAL_STATE_LED4()          HAL_STATE_LED1()
         
    #elif defined (HAL_PA_LNA_SE2431L) || defined (HAL_PA_LNA_CC2592)
      #define HAL_TURN_OFF_LED3()       st( LED3_SBIT = LED3_POLARITY (0); )
      #define HAL_TURN_OFF_LED1()       HAL_TURN_OFF_LED3()
      #define HAL_TURN_OFF_LED2()       HAL_TURN_OFF_LED3()
      #define HAL_TURN_OFF_LED4()       HAL_TURN_OFF_LED3()

      #define HAL_TURN_ON_LED3()        st( LED3_SBIT = LED3_POLARITY (1); )
      #define HAL_TURN_ON_LED1()        HAL_TURN_ON_LED3()
      #define HAL_TURN_ON_LED2()        HAL_TURN_ON_LED3()
      #define HAL_TURN_ON_LED4()        HAL_TURN_ON_LED3()

      #define HAL_TOGGLE_LED3()         st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
      #define HAL_TOGGLE_LED1()         HAL_TOGGLE_LED3()
      #define HAL_TOGGLE_LED2()         HAL_TOGGLE_LED3()
      #define HAL_TOGGLE_LED4()         HAL_TOGGLE_LED3()

      #define HAL_STATE_LED3()          (LED3_POLARITY (LED3_SBIT))
      #define HAL_STATE_LED1()          HAL_STATE_LED3()    
      #define HAL_STATE_LED2()          HAL_STATE_LED3()
      #define HAL_STATE_LED4()          HAL_STATE_LED3()

    #elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || \
          defined (HAL_PA_LNA_CC2590)
      #define HAL_TURN_OFF_LED1()       st( LED1_SBIT = LED1_POLARITY (0); )
      #define HAL_TURN_OFF_LED2()       st( LED2_SBIT = LED2_POLARITY (0); )
      #define HAL_TURN_OFF_LED3()       HAL_TURN_OFF_LED1()
      #define HAL_TURN_OFF_LED4()       HAL_TURN_OFF_LED1()

      #define HAL_TURN_ON_LED1()        st( LED1_SBIT = LED1_POLARITY (1); )
      #define HAL_TURN_ON_LED2()        st( LED2_SBIT = LED2_POLARITY (1); )
      #define HAL_TURN_ON_LED3()        HAL_TURN_ON_LED1()
      #define HAL_TURN_ON_LED4()        HAL_TURN_ON_LED1()

      #define HAL_TOGGLE_LED1()         st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
      #define HAL_TOGGLE_LED2()         st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
      #define HAL_TOGGLE_LED3()         HAL_TOGGLE_LED1()
      #define HAL_TOGGLE_LED4()         HAL_TOGGLE_LED1()

      #define HAL_STATE_LED1()          (LED1_POLARITY (LED1_SBIT))
      #define HAL_STATE_LED2()          (LED2_POLARITY (LED2_SBIT))
      #define HAL_STATE_LED3()          HAL_STATE_LED1()
      #define HAL_STATE_LED4()          HAL_STATE_LED1()

    #endif

  • I mean if you set HAL_NUM_LEDS to 1, you should disable the LED2 related define. Otherwise, LED2 would still work.

  • i know what do you mean,

    but i just want tell you is ,i have already set the HAL_NUM_LEDS to 1, but  the LED2 was still work。

  • It is not enough to set the HAL_NUM_LEDS to 1. You have to disable the LED2 related define.

  • so ,i said  that HAL_NUM_LEDS is nothing relate enable the LED2

    when i finish enable the LED2 related define, the LED2 will be work  no matter what is the value of HAL_NUM_LEDS

  • As I know, yes. You can search HAL_NUM_LEDS in source code and would see it.