Skip to content

Commit 65554c1

Browse files
committed
Extend GPIO mode
Fix stm32duino#275 Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 7ccbccb commit 65554c1

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

Diff for: cores/arduino/wiring_constants.h

+14-12
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ using std::max;
4242

4343
#endif // __cplusplus
4444

45-
#define HIGH 0x1
46-
#define LOW 0x0
47-
48-
#define INPUT 0x0
49-
#define OUTPUT 0x1
50-
#define INPUT_PULLUP 0x2
51-
#define INPUT_PULLDOWN 0x3
45+
/* Official Arduino */
46+
#define INPUT 0x0
47+
#define OUTPUT 0x1
48+
#define INPUT_PULLUP 0x2
49+
/* STM32 extension */
50+
#define INPUT_FLOATING INPUT
51+
#define INPUT_PULLDOWN 0x3
52+
#define INPUT_ANALOG 0x4
53+
#define OUTPUT_OPEN_DRAIN 0x5
5254

5355
#define PI 3.1415926535897932384626433832795
5456
#define HALF_PI 1.5707963267948966192313216916398
@@ -65,11 +67,11 @@ enum BitOrder {
6567
MSBFIRST = 1
6668
};
6769

68-
// LOW 0
69-
// HIGH 1
70-
#define CHANGE 2
71-
#define FALLING 3
72-
#define RISING 4
70+
#define LOW 0x0
71+
#define HIGH 0x1
72+
#define CHANGE 0x2
73+
#define FALLING 0x3
74+
#define RISING 0x4
7375

7476
#define DEFAULT 1
7577
#define EXTERNAL 0

Diff for: cores/arduino/wiring_digital.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void pinMode(uint32_t ulPin, uint32_t ulMode)
4848
}
4949

5050
switch (ulMode) {
51-
case INPUT:
51+
case INPUT: /* INPUT_FLOATING */
5252
pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
5353
break;
5454
case INPUT_PULLUP:
@@ -57,10 +57,17 @@ void pinMode(uint32_t ulPin, uint32_t ulMode)
5757
case INPUT_PULLDOWN:
5858
pin_function(p, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, 0));
5959
break;
60+
case INPUT_ANALOG:
61+
pin_function(p, STM_PIN_DATA(STM_MODE_ANALOG, GPIO_NOPULL, 0));
62+
break;
6063
case OUTPUT:
6164
pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
6265
break;
66+
case OUTPUT_OPEN_DRAIN:
67+
pin_function(p, STM_PIN_DATA(STM_MODE_OUTPUT_OD, GPIO_NOPULL, 0));
68+
break;
6369
default:
70+
Error_Handler();
6471
break;
6572
}
6673
set_pin_configured(p, g_digPinConfigured);

0 commit comments

Comments
 (0)