mbed library sources

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Mon Apr 14 11:30:06 2014 +0100
Parent:
159:3b23f6d9ecb9
Child:
161:cb07f9f831b7
Commit message:
Synchronized with git revision 65be1ee4a1e5212e696a4d8cab05bfc0522bb81f

Full URL: https://github.com/mbedmicro/mbed/commit/65be1ee4a1e5212e696a4d8cab05bfc0522bb81f/

Mode added to BusIn + allow creation of NC pins

Changed in this revision

api/BusIn.h Show annotated file Show diff for this revision Revisions of this file
common/BusIn.cpp Show annotated file Show diff for this revision Revisions of this file
common/gpio.c Show annotated file Show diff for this revision Revisions of this file
--- a/api/BusIn.h	Mon Apr 14 10:30:07 2014 +0100
+++ b/api/BusIn.h	Mon Apr 14 11:30:06 2014 +0100
@@ -51,7 +51,13 @@
      *   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()
      */
--- a/common/BusIn.cpp	Mon Apr 14 10:30:07 2014 +0100
+++ b/common/BusIn.cpp	Mon Apr 14 11:30:06 2014 +0100
@@ -49,6 +49,14 @@
     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();
--- a/common/gpio.c	Mon Apr 14 10:30:07 2014 +0100
+++ b/common/gpio.c	Mon Apr 14 11:30:06 2014 +0100
@@ -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) {
@@ -49,7 +53,8 @@
 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);
     }