This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Can any1 explain why we are using LEDS_CONFIGURE(LEDS_MASK) function in main program but leds_mask in the definition?

  • @brief Function for application main entry. */ int main(void) { // Configure LED-pins as outputs. LEDS_CONFIGURE(LEDS_MASK);

    // Toggle LEDs. while (true) { for (int i = 0; i < LEDS_NUMBER; i++) { LEDS_INVERT(1 << leds_list[i]); nrf_delay_ms(500); } } }

but in the definition it uses both leds_mask as well as LEDS_MASK

#define LEDS_CONFIGURE(leds_mask) do { uint32_t pin;
for (pin = 0; pin < 32; pin++)
if ( (leds_mask) & (1 << pin) )
nrf_gpio_cfg_output(pin); } while (0)

#define LEDS_ON(leds_mask) do { NRF_GPIO->OUTCLR = (leds_mask) & (LEDS_MASK & LEDS_INV_MASK);
NRF_GPIO->OUTSET = (leds_mask) & (LEDS_MASK & ~LEDS_INV_MASK); } while (0)

Parents
  • LEDS_CONFIGURE macro basically sets the pins specified in leds_mask to become GPIO output.

    LEDS_ON turns the pins on if the pins were previously configured by setting NRF_GPIO with mask bits.

    because you specified the pins to configure with LEDS_MASK previously, this macro serves as a check to guard you against setting pins were not configured, hence leds_mask & (LEDS_MASK & LEDS_INV_MASK).

Reply
  • LEDS_CONFIGURE macro basically sets the pins specified in leds_mask to become GPIO output.

    LEDS_ON turns the pins on if the pins were previously configured by setting NRF_GPIO with mask bits.

    because you specified the pins to configure with LEDS_MASK previously, this macro serves as a check to guard you against setting pins were not configured, hence leds_mask & (LEDS_MASK & LEDS_INV_MASK).

Children
  • I have a doubt in its operation. for example: in pca10028.h the values of Led1,Led2,Led3 and Led4 is 21,22,23,24 respectively.

    Also it is given that BSP_LED_0_MASK is (1<< BSP _ LED_0) which means 1 is shifted 21 times left as the value of BSP_LED_0 is 21.Similarly for other 3 also! Then finally it defines LEDS_MASK as (BSP_LED_0_MASK | BSP_LED_1_MASK | BSP_LED_2_MASK | BSP_LED_3_MASK).

    My question is Does it means that i should do the OR operation for these 4 values and the final result is assigned to LEDS_MASK ?

  • LEDS_MASK is defined as you mentioned, which means it is a constant for pca10028 board. When you call LEDS_CONFIGURE(LEDS_MASK);, it configures all four LED pins from their default state to GPIO output pins.

    Because macro functions are defined, you can just use them and never need to do it yourself.

    For example,

    • if you call LEDS_ON(0x00200000); /* The value of BSP_LED_0 */, LED_0 will be turned on

    • if you call LEDS_ON(0x00400000); /* The value of BSP_LED_1 */, LED_1 will be turned on

    • if you call LEDS_ON(0x00800000); /* The value of BSP_LED_2 */, LED_1 will be turned on

    • if you call LEDS_ON(0x01000000); /* The value of BSP_LED_3 */, LED_1 will be turned on

    • if you call LEDS_ON(0x00600000); /* The value of BSP_LED_0 OR BSP_LED_1 */, LED_0 and LED_1 will be turned on

    • if you call LEDS_ON(0x00E00000); /* The value of BSP_LED_0 OR BSP_LED_1 OR BSP_LED_2 */, LED_0, LED_1, and LED_2 will be turned on

    • if you call LEDS_ON(0x01E00000); /* The value of BSP_LED_0 OR BSP_LED_1 OR BSP_LED_2 OR BSP_LED_3 */, LED_0, LED_1, LED_2, and LED_3 will be turned on

Related