Skip to content

Add a new 'OUTPUT_OPENDRAIN' pinmode for platforms. #157

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

Merged
merged 1 commit into from
Oct 1, 2021
Merged
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
Add a new 'OUTPUT_OPENDRAIN' pinmode for platforms.
Not every MCU offers open drain pins, but some do. This change
means that they'll no longer have to play games to implement an
API-compatible pinMode() function that offers open drain.

Fixes #155

If you're reading this commit message because you need to add another
pin mode to this enum, the hacky trivial workaround is to do something
like this in your core:

```
// This typedef is used to extend the PinMode typedef enum
// in the ArduinoAPI, since they don't have contants
typedef enum {
        INPUT_ANALOG = 99 , // We assume that the Arduino core will never have 99 PinModes
        OUTPUT_OPEN_DRAIN   // It'd be cleaner to be able to count the size of that enum
} PinModeExtension;
```

Because PinMode is an enum and not a proper type, the compiler will
let the user pass either a PinMode or a PinModeExtension to your
pinMode() function, even though the signature is
`void pinMode(pin_size_t ulPin, PinMode ulMode)`
  • Loading branch information
obra committed Sep 30, 2021
commit df98331bf41cd3b47ae78a156449cac18cca67f7
9 changes: 5 additions & 4 deletions api/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ typedef enum {
} PinStatus;

typedef enum {
INPUT = 0x0,
OUTPUT = 0x1,
INPUT_PULLUP = 0x2,
INPUT_PULLDOWN = 0x3,
INPUT = 0x0,
OUTPUT = 0x1,
INPUT_PULLUP = 0x2,
INPUT_PULLDOWN = 0x3,
OUTPUT_OPENDRAIN = 0x4,
} PinMode;

typedef enum {
Expand Down