Skip to content

Commit cec0c0e

Browse files
committed
Extend GPIO mode
Fix #275 Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 97d2f08 commit cec0c0e

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
@@ -41,13 +41,15 @@ using std::max;
4141

4242
#endif // __cplusplus
4343

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

5254
#define PI 3.1415926535897932384626433832795
5355
#define HALF_PI 1.5707963267948966192313216916398
@@ -64,11 +66,11 @@ enum BitOrder {
6466
MSBFIRST = 1
6567
};
6668

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

7375
#define DEFAULT 1
7476
#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)