...

Dependents:   2doejemplo Labo_TRSE_Drone

Fork of mbed by mbed official

Files at this revision

API Documentation at this revision

Comitter:
simon.ford@mbed.co.uk
Date:
Mon May 17 14:18:54 2010 +0000
Parent:
17:49a220cc26e0
Child:
19:e6be4cd80aad
Commit message:
* Digital I/O speed improved
* Added Port
* Added OpenDrain mode
* Fixes

Changed in this revision

DigitalIn.h Show annotated file Show diff for this revision Revisions of this file
DigitalInOut.h Show annotated file Show diff for this revision Revisions of this file
DigitalOut.h Show annotated file Show diff for this revision Revisions of this file
Ethernet.h Show annotated file Show diff for this revision Revisions of this file
FunctionPointer.h Show annotated file Show diff for this revision Revisions of this file
LPC1768/capi.ar Show annotated file Show diff for this revision Revisions of this file
LPC1768/cmsis_nvic.o Show annotated file Show diff for this revision Revisions of this file
LPC1768/core_cm3.o Show annotated file Show diff for this revision Revisions of this file
LPC1768/mbed.ar Show annotated file Show diff for this revision Revisions of this file
LPC1768/stackheap.o Show annotated file Show diff for this revision Revisions of this file
LPC1768/startup_LPC17xx.o Show annotated file Show diff for this revision Revisions of this file
LPC1768/system_LPC17xx.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/capi.ar Show annotated file Show diff for this revision Revisions of this file
LPC2368/cmsis_nvic.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/core_arm7.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/mbed.ar Show annotated file Show diff for this revision Revisions of this file
LPC2368/stackheap.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/system_LPC23xx.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/vector_functions.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/vector_realmonitor.o Show annotated file Show diff for this revision Revisions of this file
LPC2368/vector_table.o Show annotated file Show diff for this revision Revisions of this file
PinNames.h Show annotated file Show diff for this revision Revisions of this file
PortIn.h Show annotated file Show diff for this revision Revisions of this file
PortInOut.h Show annotated file Show diff for this revision Revisions of this file
PortNames.h Show annotated file Show diff for this revision Revisions of this file
PortOut.h Show annotated file Show diff for this revision Revisions of this file
PwmOut.h Show annotated file Show diff for this revision Revisions of this file
mbed.h Show annotated file Show diff for this revision Revisions of this file
--- a/DigitalIn.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/DigitalIn.h	Mon May 17 14:18:54 2010 +0000
@@ -53,7 +53,10 @@
      *  returns - An integer representing the state of the input pin, 
      *      0 for logical 0 and 1 for logical 1
      */
-    int read();
+    int read() {
+        return ((_gpio->FIOPIN & _mask) ? 1 : 0);
+    }
+
 
     /* Function: mode
      *  Set the input pin mode
@@ -67,7 +70,10 @@
     /* Function: operator int()
      *  An operator shorthand for <read()>
      */
-    operator int();
+    operator int() {
+        return read();
+    }
+
 #endif
 
 #ifdef MBED_RPC
@@ -77,7 +83,9 @@
 
 protected:
 
-    PinName _pin;
+    PinName             _pin;
+    LPC_GPIO_TypeDef    *_gpio;
+    uint32_t            _mask;
 
 };
 
--- a/DigitalInOut.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/DigitalInOut.h	Mon May 17 14:18:54 2010 +0000
@@ -35,7 +35,13 @@
      *  value - An integer specifying the pin output value, 
      *      0 for logical 0 and 1 (or any other non-zero value) for logical 1 
      */
-    void write(int value);
+    void write(int value) {
+        if(value) {
+            _gpio->FIOSET = _mask;
+        } else {
+            _gpio->FIOCLR = _mask;
+        }
+    }
 
     /* Function: read
      *  Return the output setting, represented as 0 or 1 (int)
@@ -44,7 +50,10 @@
      *  returns - An integer representing the output setting of the pin if it is an output, 
      *      or read the input if set as an input
      */
-    int read();
+    int read() {
+        return ((_gpio->FIOPIN & _mask) ? 1 : 0);
+    }
+
 
     /* Function: output
      *  Set as an output
@@ -60,7 +69,7 @@
      *  Set the input pin mode
      *
      * Variables:
-     *  mode - PullUp, PullDown, PullNone
+     *  mode - PullUp, PullDown, PullNone, OpenDrain
      */
     void mode(PinMode pull);
     
@@ -68,13 +77,22 @@
     /* Function: operator=
      *  A shorthand for <write>
      */
-    DigitalInOut& operator= (int v);
-    DigitalInOut& operator= (DigitalInOut& rhs);
-    
+    DigitalInOut& operator= (int value) {
+        write(value);
+        return *this;
+    }
+
+    DigitalInOut& operator= (DigitalInOut& rhs) {
+        write(rhs.read());
+        return *this;
+    }
+
     /* Function: operator int()
      *  A shorthand for <read>
      */
-    operator int();
+    operator int() {
+        return read();
+    }
 #endif
 
 #ifdef MBED_RPC
@@ -84,7 +102,9 @@
 
 protected:
 
-    PinName _pin;
+    PinName             _pin;
+    LPC_GPIO_TypeDef    *_gpio;
+    uint32_t            _mask;
 
 };
 
--- a/DigitalOut.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/DigitalOut.h	Mon May 17 14:18:54 2010 +0000
@@ -48,7 +48,13 @@
      *  value - An integer specifying the pin output value, 
      *      0 for logical 0 and 1 (or any other non-zero value) for logical 1 
      */
-    void write(int value);
+    void write(int value) {
+        if(value) {
+            _gpio->FIOSET = _mask;
+        } else {
+            _gpio->FIOCLR = _mask;
+        }
+    }
 
     /* Function: read
      *  Return the output setting, represented as 0 or 1 (int)
@@ -57,19 +63,33 @@
      *  returns - An integer representing the output setting of the pin, 
      *      0 for logical 0 and 1 for logical 1
      */
-    int read();
+    int read() {
+        return ((_gpio->FIOPIN & _mask) ? 1 : 0);
+    }
+
 
 #ifdef MBED_OPERATORS
     /* Function: operator=
      *  A shorthand for <write>
      */
-    DigitalOut& operator= (int value);
-    DigitalOut& operator= (DigitalOut& rhs);
+    DigitalOut& operator= (int value) {
+        write(value);
+        return *this;
+    }
+
+    DigitalOut& operator= (DigitalOut& rhs) {
+        write(rhs.read());
+        return *this;
+    }
+
     
     /* Function: operator int()
      *  A shorthand for <read>
      */
-    operator int();
+    operator int() {
+        return read();
+    }
+
 #endif
 
 #ifdef MBED_RPC
@@ -79,7 +99,10 @@
 
 protected:
 
-    PinName _pin;
+    PinName             _pin;
+    LPC_GPIO_TypeDef    *_gpio;
+    uint32_t            _mask;
+
 
 };
 
--- a/Ethernet.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/Ethernet.h	Mon May 17 14:18:54 2010 +0000
@@ -115,11 +115,27 @@
     void address(char *mac);
 
     /* Function: link
-     *  Returns if an ethernet link is pressent or not.
+     *  Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
      * 
      * Returns:
      *  0 - If no ethernet link is pressent.
      *  1 - If an ethernet link is pressent.
+     *
+     * Example:
+     * > // Using the Ethernet link function
+     * > #include "mbed.h"
+     * >
+     * > Ethernet eth;
+     * >
+     * > int main() {
+     * >     wait(1); // Needed after startup.
+     * >     if(eth.link()) {
+     * >         printf("online\n");
+     * >     } else {
+     * >          printf("offline\n");
+     * >     }
+     * > }
+     *
      */
     int link();
 
--- a/FunctionPointer.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/FunctionPointer.h	Mon May 17 14:18:54 2010 +0000
@@ -6,7 +6,7 @@
 #ifndef MBED_FUNCTIONPOINTER_H
 #define MBED_FUNCTIONPOINTER_H
 
-#include "string.h"
+#include <string.h>
 
 namespace mbed { 
 
Binary file LPC1768/capi.ar has changed
Binary file LPC1768/cmsis_nvic.o has changed
Binary file LPC1768/core_cm3.o has changed
Binary file LPC1768/mbed.ar has changed
Binary file LPC1768/stackheap.o has changed
Binary file LPC1768/startup_LPC17xx.o has changed
Binary file LPC1768/system_LPC17xx.o has changed
Binary file LPC2368/capi.ar has changed
Binary file LPC2368/cmsis_nvic.o has changed
Binary file LPC2368/core_arm7.o has changed
Binary file LPC2368/mbed.ar has changed
Binary file LPC2368/stackheap.o has changed
Binary file LPC2368/system_LPC23xx.o has changed
Binary file LPC2368/vector_functions.o has changed
Binary file LPC2368/vector_realmonitor.o has changed
Binary file LPC2368/vector_table.o has changed
--- a/PinNames.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/PinNames.h	Mon May 17 14:18:54 2010 +0000
@@ -86,6 +86,7 @@
     PullUp = 0
     , PullDown = 3
     , PullNone = 2
+    , OpenDrain = 4
 };
 
 #ifdef __cplusplus
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortIn.h	Mon May 17 14:18:54 2010 +0000
@@ -0,0 +1,80 @@
+/* mbed Microcontroller Library - PortInOut
+ * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
+ */ 
+ 
+#ifndef MBED_PORTIN_H
+#define MBED_PORTIN_H
+
+#include "PortNames.h"
+#include "PinNames.h"
+
+namespace mbed {
+
+/* Class: PortIn
+ *  A multiple pin digital input
+ *
+ *  Example:
+ *  > // Switch on an LED if any of mbed pins 21-26 is high
+ *  >
+ *  > #include "mbed.h"
+ *  >
+ *  > PortIn     p(Port2, 0x0000003F);   // p21-p26
+ *  > DigitalOut ind(LED4);
+ *  >
+ *  > int main() {
+ *  >     while(1) {
+ *  >         int pins = p.read();
+ *  >         if(pins) {
+ *  >             ind = 1;
+ *  >         } else {
+ *  >             ind = 0;
+ *  >         }
+ *  >     }
+ *  > }
+ */
+class PortIn {
+public:
+
+    /* Constructor: PortIn
+     *  Create an PortIn, connected to the specified port
+     *
+     * Variables:
+     *  port - Port to connect to (Port0-Port5)
+     *  mask - A bitmask to identify which bits in the port should be included (0 - ignore)
+   	 */ 
+    PortIn(PortName port, int mask = 0xFFFFFFFF);
+
+    /* Function: read
+     *  Read the value currently output on the port
+     *
+     * Variables:
+     *  returns - An integer with each bit corresponding to associated port pin setting
+     */
+    int read() {
+        return _gpio->FIOPIN & _mask;
+    }
+
+    /* Function: mode
+     *  Set the input pin mode
+     *
+     * Variables:
+     *  mode - PullUp, PullDown, PullNone, OpenDrain
+     */
+    void mode(PinMode mode);
+    
+    /* Function: operator int()
+     *  A shorthand for <read>
+     */
+    operator int() { 
+	    return read();
+    }
+
+private:
+    LPC_GPIO_TypeDef    *_gpio;
+    PortName            _port;
+    uint32_t            _mask;    
+};
+
+} // namespace mbed
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortInOut.h	Mon May 17 14:18:54 2010 +0000
@@ -0,0 +1,95 @@
+/* mbed Microcontroller Library - PortInOut
+ * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
+ */ 
+ 
+#ifndef MBED_PORTINOUT_H
+#define MBED_PORTINOUT_H
+
+#include "PortNames.h"
+#include "PinNames.h"
+
+namespace mbed {
+
+/* Class: PortInOut
+ *  A multiple pin digital in/out used to set/read multiple bi-directional pins
+ */
+class PortInOut {
+public:
+
+    /* Constructor: PortInOut
+     *  Create an PortInOut, connected to the specified port
+     *
+     * Variables:
+     *  port - Port to connect to (Port0-Port5)
+     *  mask - A bitmask to identify which bits in the port should be included (0 - ignore)
+   	 */ 
+    PortInOut(PortName port, int mask = 0xFFFFFFFF);
+
+    /* Function: write
+     *  Write the value to the output port
+     *
+     * Variables:
+     *  value - An integer specifying a bit to write for every corresponding port pin
+     */    
+    void write(int value) {
+        _gpio->FIOSET = value & _mask;
+        _gpio->FIOCLR = ~(value) & _mask;
+    }
+
+    /* Function: read
+     *  Read the value currently output on the port
+     *
+     * Variables:
+     *  returns - An integer with each bit corresponding to associated port pin setting
+     */
+    int read() {
+        return _gpio->FIOPIN & _mask;
+    }
+
+    /* Function: output
+     *  Set as an output
+     */
+    void output();
+
+    /* Function: input
+     *  Set as an input
+     */
+    void input();
+
+    /* Function: mode
+     *  Set the input pin mode
+     *
+     * Variables:
+     *  mode - PullUp, PullDown, PullNone, OpenDrain
+     */
+    void mode(PinMode mode);
+
+    /* Function: operator=
+     *  A shorthand for <write>
+     */    
+    PortInOut& operator= (int value) { 
+    	write(value);
+	    return *this;
+    }
+    
+    PortInOut& operator= (PortInOut& rhs) { 
+    	write(rhs.read());
+	    return *this;
+    }
+    
+    /* Function: operator int()
+     *  A shorthand for <read>
+     */
+    operator int() { 
+	    return read();
+    }
+
+private:
+    LPC_GPIO_TypeDef    *_gpio;
+    PortName            _port;
+    uint32_t            _mask;    
+};
+
+} // namespace mbed
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortNames.h	Mon May 17 14:18:54 2010 +0000
@@ -0,0 +1,26 @@
+/* mbed Microcontroller Library - PortName 
+ * Copyright (c) 2010 ARM Limited. All rights reserved.
+ * jward
+ */
+
+#ifndef MBED_PORTNAMES_H
+#define MBED_PORTNAMES_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef enum PortName PortName;
+enum PortName {
+    Port0 = 0
+    , Port1 = 1
+    , Port2 = 2
+    , Port3 = 3
+    , Port4 = 4
+};
+
+#ifdef __cplusplus
+}
+#endif
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PortOut.h	Mon May 17 14:18:54 2010 +0000
@@ -0,0 +1,98 @@
+/* mbed Microcontroller Library - PortOut
+ * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
+ */ 
+ 
+#ifndef MBED_PORTOUT_H
+#define MBED_PORTOUT_H
+
+#include "platform.h"
+#include "PinNames.h"
+#include "Base.h"
+
+#include "PortNames.h"
+
+namespace mbed {
+/* Class: PortOut
+ *   A multiple pin digital out
+ *
+ * Example:
+ * > // Toggle all four LEDs
+ * >
+ * > #include "mbed.h"
+ * >
+ * > // LED1 = P1.18  LED2 = P1.20  LED3 = P1.21  LED4 = P1.23
+ * > #define LED_MASK 0x00B40000
+ * >
+ * > PortOut ledport(Port1, LED_MASK);
+ * >
+ * > int main() {
+ * >     while(1) {
+ * >         ledport = LED_MASK;
+ * >         wait(1);
+ * >         ledport = 0;
+ * >         wait(1);
+ * >     }
+ * > }
+ */  
+class PortOut {
+public:
+
+    /* Constructor: PortOut
+     *  Create an PortOut, connected to the specified port
+     *
+     * Variables:
+     *  port - Port to connect to (Port0-Port5)
+     *  mask - A bitmask to identify which bits in the port should be included (0 - ignore)
+   	 */ 
+    PortOut(PortName port, int mask = 0xFFFFFFFF);
+
+    /* Function: write
+     *  Write the value to the output port
+     *
+     * Variables:
+     *  value - An integer specifying a bit to write for every corresponding PortOut pin
+     */    
+    void write(int value) {
+        _gpio->FIOSET = value & _mask;
+        _gpio->FIOCLR = ~(value) & _mask;
+    }
+
+    /* Function: read
+     *  Read the value currently output on the port
+     *
+     * Variables:
+     *  returns - An integer with each bit corresponding to associated PortOut pin setting
+     */
+    int read() {
+        return _gpio->FIOPIN & _mask;
+    }
+
+    /* Function: operator=
+     *  A shorthand for <write>
+     */    
+    PortOut& operator= (int value) { 
+    	write(value);
+	    return *this;
+    }
+    
+    PortOut& operator= (PortOut& rhs) { 
+    	write(rhs.read());
+	    return *this;
+    }
+    
+    /* Function: operator int()
+     *  A shorthand for <read>
+     */
+    operator int() { 
+	    return read();
+    }
+
+private:
+    LPC_GPIO_TypeDef    *_gpio;
+    PortName            _port; 
+    uint32_t            _mask;    
+};
+
+} // namespace mbed
+
+#endif
--- a/PwmOut.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/PwmOut.h	Mon May 17 14:18:54 2010 +0000
@@ -31,6 +31,12 @@
  * >         }
  * >     }
  * > }
+ *
+ *  Note that on the LPC1768 and LPC2368, the PWMs all share the same
+ *  period - if you change the period for one, you change it for all.
+ *  Although routines that change the period maintain the duty cycle
+ *  for its PWM, all other PWMs will require their duty cycle to be
+ *  refreshed.
  */
 class PwmOut : public Base {
 
@@ -69,32 +75,42 @@
     float read();
     
     /* Function: period
-     *  Set the PWM period, specified in seconds (float)
+     *  Set the PWM period, specified in seconds (float), keeping the
+     *  duty cycle the same.
+     *
+     *  Note:
+     *   The resolution is currently in microseconds; periods smaller than this
+     *   will be set to zero.
      */
     void period(float seconds);
 
     /* Function: period_ms
-     *  Set the PWM period, specified in milli-seconds (int)
+     *  Set the PWM period, specified in milli-seconds (int), keeping the
+     *  duty cycle the same.
      */
     void period_ms(int ms);
 
     /* Function: period_us
-     *  Set the PWM period, specified in micro-seconds (int)
+     *  Set the PWM period, specified in micro-seconds (int), keeping the
+     *  duty cycle the same.
      */
     void period_us(int us);
 
     /* Function: pulsewidth
-     *  Set the PWM pulsewidth, specified in seconds (float)
+     *  Set the PWM pulsewidth, specified in seconds (float), keeping the
+     *  period the same.
      */
     void pulsewidth(float seconds);
 
     /* Function: pulsewidth_ms
-     *  Set the PWM pulsewidth, specified in milli-seconds (int)
+     *  Set the PWM pulsewidth, specified in milli-seconds (int), keeping
+     *  the period the same.
      */
     void pulsewidth_ms(int ms);
 
     /* Function: pulsewidth_us
-     *  Set the PWM pulsewidth, specified in micro-seconds (int)
+     *  Set the PWM pulsewidth, specified in micro-seconds (int), keeping
+     *  the period the same.
      */
     void pulsewidth_us(int us);
 
--- a/mbed.h	Tue Dec 01 14:24:15 2009 +0000
+++ b/mbed.h	Mon May 17 14:18:54 2010 +0000
@@ -1,11 +1,12 @@
 /* mbed Microcontroller Library
  * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
+ * sford
  */ 
  
 #ifndef MBED_H
 #define MBED_H
 
-#define MBED_LIBRARY_VERSION 19
+#define MBED_LIBRARY_VERSION 21
  
 // Useful C libraries
 #include <stdio.h>
@@ -24,6 +25,9 @@
 #include "BusIn.h"
 #include "BusOut.h"
 #include "BusInOut.h"
+#include "PortIn.h"
+#include "PortInOut.h"
+#include "PortOut.h"
 #include "AnalogIn.h"
 #include "AnalogOut.h"
 #include "PwmOut.h"
@@ -32,6 +36,7 @@
 #include "I2C.h"
 #include "Ethernet.h"
 #include "CAN.h"
+//#include "SPI3.h"
 
 // mbed Internal components
 #include "Timer.h"
@@ -39,6 +44,8 @@
 #include "Timeout.h"
 #include "LocalFileSystem.h"
 #include "InterruptIn.h"
+//#include "rpc.h"
+//#include "rtc.h"
 #include "wait_api.h"
 #include "rtc_time.h"