How do i alter my Current code to read directly from the IDR register : <p>Modify the code for <strong>ReadJoystick()</strong> to read the <strong>IDR register</strong> directly for the ports associated
with the joystick inputs. The aim is to minimise the number of reads to the register. The code in
the template makes an individual call for each of the inputs pins, even though some of the pins are
on the same ports.
You can refer to the HAL code for inspiration. Use the defined values in the HAL for addressing
registers rather than creating new ones.</p>

<p>Example Code Given to Me</p>

<pre><code>GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
{
    GPIO_PinState bitstatus;
     /* Check the parameters */
    assert_param(IS_GPIO_PIN(GPIO_Pin));
if ((GPIOx-&gt;IDR &amp; GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
{
    bitstatus = GPIO_PIN_SET;
}
else
{
    bitstatus = GPIO_PIN_RESET;
}
return bitstatus;
</code></pre>

<p>}</p>

<hr>

<p><strong>Code I require to Alter</strong></p>

<p>// REPLACE THE FOLLOW CODE WITH YOUR SOLUTION </p>

<pre><code>uint8_t
ReadJoystick ()
{
  uint8_t JoystickPosition = 0;

  // Get current joystick value
  if (HAL_GPIO_ReadPin (JOY_A_GPIO_Port, JOY_A_Pin) == GPIO_PIN_RESET)
  {
    JoystickPosition = 'L';
  }
  else if (HAL_GPIO_ReadPin (JOY_B_GPIO_Port, JOY_B_Pin) == 
GPIO_PIN_RESET)
  {
JoystickPosition = 'U';
  }
  else if (HAL_GPIO_ReadPin (JOY_C_GPIO_Port, JOY_C_Pin) == 
 GPIO_PIN_RESET)
   {
     JoystickPosition = 'D';
   }
   else if (HAL_GPIO_ReadPin (JOY_D_GPIO_Port, JOY_D_Pin) == 
 GPIO_PIN_RESET)
    {
      JoystickPosition = 'R';
    }
   else if (HAL_GPIO_ReadPin (JOY_CTR_GPIO_Port, JOY_CTR_Pin) == 
GPIO_PIN_RESET)
  {
    JoystickPosition = 'C';
  }

  return JoystickPosition;
 }
</code></pre>

<p>So I Understand that my current code is reading each pin although i've been asked to alter this to read directly from the IDR register. I'm really new to embedded systems programming and just looking for someone to guide me with altering this code</p>
