Yes, the function returns immediately: We read the button states on the systick interrupt, at 1kHz. We debounce there, requiring the button to read as pressed or released for 20 cycles before setting the corresponding flag that gets picked up at the start of the run loop. Then getButtonState() returns those flags.