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

(Suggestion) Add function for configuring pullup/down on inputs #327

Open
jglim opened this issue Jun 25, 2024 · 0 comments
Open

(Suggestion) Add function for configuring pullup/down on inputs #327

jglim opened this issue Jun 25, 2024 · 0 comments

Comments

@jglim
Copy link

jglim commented Jun 25, 2024

Hello!

While interfacing the ch32v003 with a rotary encoder, I could not find a quick and "easy" way to configure the input pins as pullups, so I wrote this snippet:

#define FUN_INPUT_PULLUP 1
#define FUN_INPUT_PULLDOWN 0

#define funInputPullUpDown( pin, mode ) { GpioOf( pin )->OUTDR = (GpioOf( pin )->OUTDR & ~(1 << (pin & 0xf))) | (mode << (pin & 0xf)); }

It can be used like this:

// configure a pin (PC5 in this case) into an input that uses pullup/down 
funPinMode(PC5, GPIO_Speed_In | GPIO_CNF_IN_PUPD);

// actually enable the pullup
funInputPullUpDown(PC5, FUN_INPUT_PULLUP);

...
// read the state
funDigitalRead(PC5);

I've opened this issue to share this as I thought it might come in handy. If it looks like something that could be added to ch32v003fun.h, I'll be glad to send a PR.


On a tangent, I ordered a bunch of boards for those encoders which turned up today, and they just work because of ch32v003fun. Thank you cnlohr and other contributors for making such a useful project!

image

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