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).

  • 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 ?

Reply
  • 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 ?

Children
No Data
Related