Skip to content
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

Possible typo in Teensy LC SnoozeDigital for INPUT_PULLDOWN #116

Open
tobywf opened this issue Oct 19, 2022 · 0 comments
Open

Possible typo in Teensy LC SnoozeDigital for INPUT_PULLDOWN #116

tobywf opened this issue Oct 19, 2022 · 0 comments

Comments

@tobywf
Copy link

tobywf commented Oct 19, 2022

Snooze works great, thanks for your work. I did hit a small issue when using a Teensy LC, and trying to use INPUT_PULLDOWN for waking with SnoozeDigital (for waking when a signal goes high, basically the inverse of button_hold_wakeup).

The other HALs implement INPUT, INPUT_PULLUP, and INPUT_PULLDOWN:

if ( pin_mode == INPUT || pin_mode == INPUT_PULLUP || pin_mode == INPUT_PULLDOWN ) {
*portModeRegister( pinNumber ) = 0;
*config = PORT_PCR_MUX( 1 );
if ( pin_mode == INPUT_PULLUP ) *config |= PORT_PCR_PE | PORT_PCR_PS;// pullup
else if ( pin_mode == INPUT_PULLDOWN ) {
*config |= ( PORT_PCR_PE ); // pulldown
*config &= ~( PORT_PCR_PS );
}

if ( pin_mode == INPUT || pin_mode == INPUT_PULLUP || pin_mode == INPUT_PULLDOWN ) {
*portModeRegister( pinNumber ) = 0;
*config = PORT_PCR_MUX( 1 );
if ( pin_mode == INPUT_PULLUP ) *config |= PORT_PCR_PE | PORT_PCR_PS;// pullup
else if ( pin_mode == INPUT_PULLDOWN ) {
*config |= ( PORT_PCR_PE ); // pulldown
*config &= ~( PORT_PCR_PS );
}

if ( pin_mode == INPUT || pin_mode == INPUT_PULLUP || pin_mode == INPUT_PULLDOWN ) {
*portModeRegister( pinNumber ) = 0;
*config = PORT_PCR_MUX( 1 );
if ( pin_mode == INPUT_PULLUP ) *config |= PORT_PCR_PE | PORT_PCR_PS;// pullup
else if ( pin_mode == INPUT_PULLDOWN ) {
*config |= ( PORT_PCR_PE ); // pulldown
*config &= ~( PORT_PCR_PS );
}

It looks like INPUT_PULLDOWN was intended to work with the Teensy LC?

if ( pin_mode == INPUT || pin_mode == INPUT_PULLUP ) {// setup pin mode/type/interrupt
*portModeRegister( pinNumber ) &= ~digitalPinToBitMask( pinNumber );
*config = PORT_PCR_MUX( 1 );
if ( pin_mode == INPUT_PULLUP ) {
*config = PORT_PCR_MUX( 1 ) | PORT_PCR_PE | PORT_PCR_PS;// pullup
}
else if ( pin_mode == INPUT_PULLDOWN ) {
*config |= ( PORT_PCR_PE ); // pulldown
*config &= ~( PORT_PCR_PS );
}

After I modified line 88 to match the other HALs, waking seemed to work fine. So it seems like an omission, especially given the else if on line 94. I also looked in the datasheet and didn't find anything that would indicate INPUT_PULLDOWN is different in any way? If there's a a reason INPUT_PULLDOWN really isn't supported, it would be good to document that. In either case, I can cut a PR if you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant