Skip to content

[samd] fixing issue #28 #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions cores/arduino/wiring_digital.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,45 +69,66 @@ void pinMode( uint32_t ulPin, uint32_t ulMode )
}
}

void digitalWrite( uint32_t ulPin, uint32_t ulVal )
void digitalWrite(uint32_t ulPin, uint32_t ulVal)
{
// Handle the case the pin isn't usable as PIO
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
uint32_t ulGPIOPin=g_APinDescription[ulPin].ulPin;
PortGroup* port=&(PORT->Group[g_APinDescription[ulPin].ulPort]);

// Handle the case the pin is invalid
if (ulPin >= PINS_COUNT)
{
return ;
}

// Enable pull-up resistor
PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ;

switch ( ulVal )
// Test if pin is set to INPUT mode, then activate pull-up according to ulVal
if (port->DIR.reg & (1ul<<ulGPIOPin) != 0)
{
case LOW:
PORT->Group[g_APinDescription[ulPin].ulPort].OUTCLR.reg = (1ul << g_APinDescription[ulPin].ulPin) ;
break ;

default:
PORT->Group[g_APinDescription[ulPin].ulPort].OUTSET.reg = (1ul << g_APinDescription[ulPin].ulPin) ;
break ;
switch (ulVal)
{
case LOW:
// Disable pull-up resistor
port->PINCFG[ulGPIOPin].bit.PULLEN=0;
break;

case HIGH:
default:
// Enable pull-up resistor
port->PINCFG[ulGPIOPin].bit.PULLEN=1;
break;
}
}
else // pin is set to OUTPUT mode, we output the requested voltage level
{
switch (ulVal)
{
case LOW:
port->OUTCLR.reg=(1ul<<ulGPIOPin);
break;

case HIGH:
default:
port->OUTSET.reg=(1ul<<ulGPIOPin);
break;
}
}

return ;
}

int digitalRead( uint32_t ulPin )
{
// Handle the case the pin isn't usable as PIO
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
// Handle the case the pin is invalid
if (ulPin >= PINS_COUNT)
{
return LOW ;
return LOW;
}

if ( (PORT->Group[g_APinDescription[ulPin].ulPort].IN.reg & (1ul << g_APinDescription[ulPin].ulPin)) != 0 )
{
return HIGH ;
return HIGH;
}

return LOW ;
return LOW;
}

#ifdef __cplusplus
Expand Down