Skip to content

Commit 4270ce3

Browse files
committed
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)`
1 parent 6a524ad commit 4270ce3

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

api/Common.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef enum {
2020
OUTPUT = 0x1,
2121
INPUT_PULLUP = 0x2,
2222
INPUT_PULLDOWN = 0x3,
23+
OUPUT_OPENDRAIN = 0x4
2324
} PinMode;
2425

2526
typedef enum {

0 commit comments

Comments
 (0)