AnsweredAssumed Answered

uint32_t Buttons_GetState (void) explanation?

Question asked by Aditya Mall on May 16, 2018
Latest reply on May 17, 2018 by Aditya Mall

Hi All,

Just saw the BSP for buttons on Keil, came across this, can anyone explain how this actually works when one presses the button.

 

Apparently if one was supposed to press button say at pin 13 in this case, GPIOC->IDR 13th bit would be set to 1 and in this case wouldn't the if condition become false? If it is false then return value of (val) = 0 ? 

 

#define USER 1

 

uint32_t Buttons_GetState (void)

{

   uint32_t val = 0;

   if ((GPIOC->IDR & (1ul << 13)) == 0)

   {
      /* USER button */
      val |= USER;
   }

   return (val);
}

Outcomes