Skip to content

Mode added to BusIn + allow creation of NC pins #247

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
Apr 14, 2014
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion libraries/mbed/api/BusIn.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ class BusIn {
* An integer with each bit corresponding to the value read from the associated DigitalIn pin
*/
int read();


/** Set the input pin mode
*
* @param mode PullUp, PullDown, PullNone
*/
void mode(PinMode pull);

#ifdef MBED_OPERATORS
/** A shorthand for read()
*/
Expand Down
8 changes: 8 additions & 0 deletions libraries/mbed/common/BusIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ int BusIn::read() {
return v;
}

void BusIn::mode(PinMode pull) {
for (int i=0; i<16; i++) {
if (_pin[i] != 0) {
_pin[i]->mode(pull);
}
}
}

#ifdef MBED_OPERATORS
BusIn::operator int() {
return read();
Expand Down
17 changes: 11 additions & 6 deletions libraries/mbed/common/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
{
gpio_init(gpio, pin);
gpio_dir(gpio, PIN_INPUT);
gpio_mode(gpio, mode);
if (pin != NC) {
gpio_dir(gpio, PIN_INPUT);
gpio_mode(gpio, mode);
}
}

static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
{
gpio_init(gpio, pin);
gpio_write(gpio, value);
gpio_dir(gpio, PIN_OUTPUT);
gpio_mode(gpio, mode);
if (pin != NC) {
gpio_write(gpio, value);
gpio_dir(gpio, PIN_OUTPUT);
gpio_mode(gpio, mode);
}
}

void gpio_init_in(gpio_t* gpio, PinName pin) {
Expand All @@ -49,7 +53,8 @@ void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
if (direction == PIN_INPUT) {
_gpio_init_in(gpio, pin, mode);
gpio_write(gpio, value); // we prepare the value in case it is switched later
if (pin != NC)
gpio_write(gpio, value); // we prepare the value in case it is switched later
} else {
_gpio_init_out(gpio, pin, mode, value);
}
Expand Down