raiden00pl commented on pull request #1788:
URL: https://github.com/apache/incubator-nuttx/pull/1788#issuecomment-692848202


   What about a new function like this:
   
   ```
   #define PSEL_PIN_SHIFT       (0)
   #define PSEL_PORT_SHIFT      (5)
   #define PSEL_CONNECTED_SHIFT (0 << 31)
   
   uint32_t nrf52_gpio_psel(nrf52_pinset_t pinset)
   {
     uint32_t psel = 0;
     int      pin  = 0;
     int      port = 0;
   
     if ((pinset & GPIO_FUNC_MASK) != GPIO_DISABLED)
       {
         /* Pin not connected - set reset value */
   
         psel = 0xffffffff;
       }
     else
       {
         /* Pin connected - configure pin and port */
   
         pin  = GPIO_PIN_DECODE(pinset);
         port = GPIO_PORT_DECODE(pinset);
   
         psel = 0;
         psel |= pin << PSEL_PIN_SHIFT;
         psel |= port << PSEL_PORT_SHIFT;
       }
   
       return psel;
   }
   
   ```
   
   and then we can replace all PSEL configuration logic with that.
   
   ```
     regval = nrf52_gpio_psel(priv->sck_pin);
     if (regval == 0xffffffff)
     {
      /* Unsupported */
       DEBUGASSERT(0);
     }
     nrf52_spi_putreg(priv, NRF52_SPIM_PSELSCK_OFFSET, regval);
   
     regval = nrf52_gpio_psel(priv->miso_pin);
     nrf52_spi_putreg(priv, NRF52_SPIM_PSELMISO_OFFSET, regval);
   ```
   
   
   This will simplify the code and will be a more general solution, easy to 
adapt for other peripherals.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to