Skip to content

Commit fc0a2cf

Browse files
committed
Mode added to BusIn + allow creation of NC pins
Now BusIn can also use PullUp, etc, instead of only BusInOut. If the pin is NC, it does get to the init, but all write/mode functions are disabled. This is how it used to be in the old gpio version. Quite some libraries allow users to make pins NC, and they are all locking up with the current mbed version. This is far from a perfect solution, but more a temporary fix.
1 parent d537c51 commit fc0a2cf

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

libraries/mbed/api/BusIn.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ class BusIn {
5151
* An integer with each bit corresponding to the value read from the associated DigitalIn pin
5252
*/
5353
int read();
54-
54+
55+
/** Set the input pin mode
56+
*
57+
* @param mode PullUp, PullDown, PullNone
58+
*/
59+
void mode(PinMode pull);
60+
5561
#ifdef MBED_OPERATORS
5662
/** A shorthand for read()
5763
*/

libraries/mbed/common/BusIn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ int BusIn::read() {
4949
return v;
5050
}
5151

52+
void BusIn::mode(PinMode pull) {
53+
for (int i=0; i<16; i++) {
54+
if (_pin[i] != 0) {
55+
_pin[i]->mode(pull);
56+
}
57+
}
58+
}
59+
5260
#ifdef MBED_OPERATORS
5361
BusIn::operator int() {
5462
return read();

libraries/mbed/common/gpio.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@
1818
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
1919
{
2020
gpio_init(gpio, pin);
21-
gpio_dir(gpio, PIN_INPUT);
22-
gpio_mode(gpio, mode);
21+
if (pin != NC) {
22+
gpio_dir(gpio, PIN_INPUT);
23+
gpio_mode(gpio, mode);
24+
}
2325
}
2426

2527
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
2628
{
2729
gpio_init(gpio, pin);
28-
gpio_write(gpio, value);
29-
gpio_dir(gpio, PIN_OUTPUT);
30-
gpio_mode(gpio, mode);
30+
if (pin != NC) {
31+
gpio_write(gpio, value);
32+
gpio_dir(gpio, PIN_OUTPUT);
33+
gpio_mode(gpio, mode);
34+
}
3135
}
3236

3337
void gpio_init_in(gpio_t* gpio, PinName pin) {
@@ -49,7 +53,8 @@ void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
4953
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
5054
if (direction == PIN_INPUT) {
5155
_gpio_init_in(gpio, pin, mode);
52-
gpio_write(gpio, value); // we prepare the value in case it is switched later
56+
if (pin != NC)
57+
gpio_write(gpio, value); // we prepare the value in case it is switched later
5358
} else {
5459
_gpio_init_out(gpio, pin, mode, value);
5560
}

0 commit comments

Comments
 (0)