AnsweredAssumed Answered

Reading pins of a port in one line of code

Question asked by yazdani.saeid on Oct 14, 2015
Latest reply on Oct 14, 2015 by Clive One
I am working on project which is generated by Cube and uses HAL drivers. I require to read states of a number of pins on a port. Currently I am doing like this:

  //read PC0 to PC7 to check for state (on or off)
  report.BUTTONS_0_7.BIT_0 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_0);
  report.BUTTONS_0_7.BIT_1 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_1);
  report.BUTTONS_0_7.BIT_2 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_2);
  report.BUTTONS_0_7.BIT_3 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_3);
  report.BUTTONS_0_7.BIT_4 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_4);
  report.BUTTONS_0_7.BIT_5 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_5);
  report.BUTTONS_0_7.BIT_6 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_6);
  report.BUTTONS_0_7.BIT_7 = HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_7);

I did not find any code in HAL that allows reading a number of pins of a port simultaneously. Is there a way to read a given amount of pins from a port, or half of them or all of them?

If the HAL does not have this function, what alternative exist that would be compatible with HAL?

Thanks

Outcomes