ArminJo / DigistumpArduino

Improved version of Digistump avr core for Arduino
194 stars 37 forks source link

pinMode(Pin,INPUT) does not disable internal pullup #52

Closed stre425 closed 1 year ago

stre425 commented 1 year ago

Bug Report

Board

IDE

Example from the core libraries to reproduce the issue

Version

Current behavior

If the internal pullup for input is activated once by using pinMode(pin,INPUT_PULLUP); it keeps being activated after reconfiguring to a normal INPUT (pinMode(pin,INPUT). Libaries like ADCTouch which reconfigure the pullup resistor therefore don't show the expected behaviour. ATTinycore explicitly disables pullups when setting pinMode(pin,INPUT)

Expected behavior

pinMode(pin,INPUT) should disable the internal pullup independent of the current setting.

Arduino Reference: pinMode

The expected behavior should be achievable by changing the INPUT block of the pinMode function in wiring_digital.c but I'm not sure if this could cause other issues

if (mode == INPUT) { 
        uint8_t oldSREG = SREG;
        cli();
        *reg &= ~bit;
                *out &= ~bit;  //disable internal pullup
        SREG = oldSREG;