Skip to content
Snippets Groups Projects
Commit bf454d85 authored by Sandeep Mistry's avatar Sandeep Mistry
Browse files

Clean up port, pin, and pin mask duplication in digitalWrite

parent 0f3f80a1
No related branches found
No related tags found
No related merge requests found
......@@ -82,19 +82,23 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal )
return ;
}
if ( (PORT->Group[g_APinDescription[ulPin].ulPort].DIRSET.reg & (1ul << g_APinDescription[ulPin].ulPin)) == 0 ) {
EPortType port = g_APinDescription[ulPin].ulPort;
uint32_t pin = g_APinDescription[ulPin].ulPin;
uint32_t pinMask = (1ul << pin);
if ( (PORT->Group[port].DIRSET.reg & pinMask) == 0 ) {
// the pin is not an output, disable pull-up if val is LOW, otherwise enable pull-up
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].bit.PULLEN = (ulVal != LOW) ;
PORT->Group[port].PINCFG[pin].bit.PULLEN = (ulVal != LOW) ;
}
switch ( ulVal )
{
case LOW:
PORT->Group[g_APinDescription[ulPin].ulPort].OUTCLR.reg = (1ul << g_APinDescription[ulPin].ulPin) ;
PORT->Group[port].OUTCLR.reg = pinMask;
break ;
default:
PORT->Group[g_APinDescription[ulPin].ulPort].OUTSET.reg = (1ul << g_APinDescription[ulPin].ulPin) ;
PORT->Group[port].OUTSET.reg = pinMask;
break ;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment