-
-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Add open-drain GPIO support. #15282
Add open-drain GPIO support. #15282
Changes from 5 commits
0c6a4c8
8defc7b
2aa121b
bc81f52
cb6e057
d33a2d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,12 @@ typedef ioline_t pin_t; | |
|
||
/* Operation of GPIO by pin. */ | ||
|
||
#define setPinInput(pin) palSetLineMode(pin, PAL_MODE_INPUT) | ||
#define setPinInputHigh(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLUP) | ||
#define setPinInputLow(pin) palSetLineMode(pin, PAL_MODE_INPUT_PULLDOWN) | ||
#define setPinOutput(pin) palSetLineMode(pin, PAL_MODE_OUTPUT_PUSHPULL) | ||
#define setPinInput(pin) palSetLineMode((pin), PAL_MODE_INPUT) | ||
#define setPinInputHigh(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLUP) | ||
#define setPinInputLow(pin) palSetLineMode((pin), PAL_MODE_INPUT_PULLDOWN) | ||
#define setPinOutputPushPull(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_PUSHPULL) | ||
#define setPinOutputOpenDrain(pin) palSetLineMode((pin), PAL_MODE_OUTPUT_OPENDRAIN) | ||
#define setPinOutput(pin) setPinOutputPushPull(pin) | ||
|
||
#define writePinHigh(pin) palSetLine(pin) | ||
#define writePinLow(pin) palClearLine(pin) | ||
|
@@ -41,10 +43,10 @@ typedef uint16_t port_data_t; | |
|
||
#define readPort(pin) palReadPort(PAL_PORT(pin)) | ||
|
||
#define setPortBitInput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT) | ||
#define setPortBitInputHigh(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLUP) | ||
#define setPortBitInputLow(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_INPUT_PULLDOWN) | ||
#define setPortBitOutput(pin, bit) palSetPadMode(PAL_PORT(pin), bit, PAL_MODE_OUTPUT_PUSHPULL) | ||
#define setPortBitInput(pin, bit) palSetPadMode(PAL_PORT(pin), (bit), PAL_MODE_INPUT) | ||
#define setPortBitInputHigh(pin, bit) palSetPadMode(PAL_PORT(pin), (bit), PAL_MODE_INPUT_PULLUP) | ||
#define setPortBitInputLow(pin, bit) palSetPadMode(PAL_PORT(pin), (bit), PAL_MODE_INPUT_PULLDOWN) | ||
#define setPortBitOutput(pin, bit) palSetPadMode(PAL_PORT(pin), (bit), PAL_MODE_OUTPUT_PUSHPULL) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, looks like the implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on Discord, given that it's not in use anywhere but one keyboard, and it has its own implementation of the port-based GPIO functions, the port-related operations have been removed for the time being until we work out a proper solution for them. |
||
|
||
#define writePortBitLow(pin, bit) palClearLine(PAL_LINE(PAL_PORT(pin), bit)) | ||
#define writePortBitHigh(pin, bit) palSetLine(PAL_LINE(PAL_PORT(pin), bit)) | ||
#define writePortBitLow(pin, bit) palClearLine(PAL_LINE(PAL_PORT(pin), (bit))) | ||
#define writePortBitHigh(pin, bit) palSetLine(PAL_LINE(PAL_PORT(pin), (bit))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it is possible to implement an open-drain output on AVR — set the PORTx bit to 0, then write the inverted output value to the DDRx bit. The problem is that it requires either some conditional code in the
writePin()
implementation, or a separate set of macros likewriteOpenDrainPin()
,writeOpenDrainPinHigh()
,writeOpenDrainPinLow()
(with bad consequences if you use a wrong kind of macro for the chosen pin mode).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but nobody has asked for it, and nobody's using it. Figured it'd be a problem for another day.