svn / mbed / trunk / PortOut.h

Revision 30, 2.1 kB (checked in by emilmont, 6 months ago)

Add additional M0 peripherals implementations, fix GCC stdio/uart

Line 
1/* mbed Microcontroller Library - PortOut
2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
3 */ 
4 
5#ifndef MBED_PORTOUT_H
6#define MBED_PORTOUT_H
7
8#include "device.h"
9
10#if DEVICE_PORTOUT
11
12#include "platform.h"
13#include "PinNames.h"
14#include "Base.h"
15
16#include "PortNames.h"
17
18namespace mbed {
19/* Class: PortOut
20 *   A multiple pin digital out
21 *
22 * Example:
23 * > // Toggle all four LEDs
24 * >
25 * > #include "mbed.h"
26 * >
27 * > // LED1 = P1.18  LED2 = P1.20  LED3 = P1.21  LED4 = P1.23
28 * > #define LED_MASK 0x00B40000
29 * >
30 * > PortOut ledport(Port1, LED_MASK);
31 * >
32 * > int main() {
33 * >     while(1) {
34 * >         ledport = LED_MASK;
35 * >         wait(1);
36 * >         ledport = 0;
37 * >         wait(1);
38 * >     }
39 * > }
40 */ 
41class PortOut {
42public:
43
44    /* Constructor: PortOut
45     *  Create an PortOut, connected to the specified port
46     *
47     * Variables:
48     *  port - Port to connect to (Port0-Port5)
49     *  mask - A bitmask to identify which bits in the port should be included (0 - ignore)
50     */ 
51    PortOut(PortName port, int mask = 0xFFFFFFFF);
52
53    /* Function: write
54     *  Write the value to the output port
55     *
56     * Variables:
57     *  value - An integer specifying a bit to write for every corresponding PortOut pin
58     */   
59    void write(int value);
60
61    /* Function: read
62     *  Read the value currently output on the port
63     *
64     * Variables:
65     *  returns - An integer with each bit corresponding to associated PortOut pin setting
66     */
67    int read();
68
69    /* Function: operator=
70     *  A shorthand for <write>
71     */   
72    PortOut& operator= (int value) { 
73        write(value);
74        return *this;
75    }
76   
77    PortOut& operator= (PortOut& rhs) { 
78        write(rhs.read());
79        return *this;
80    }
81   
82    /* Function: operator int()
83     *  A shorthand for <read>
84     */
85    operator int() { 
86        return read();
87    }
88
89private:
90#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
91    LPC_GPIO_TypeDef    *_gpio;
92#endif
93    PortName            _port;
94    uint32_t            _mask;
95};
96
97} // namespace mbed
98
99#endif
100
101#endif
Note: See TracBrowser for help on using the browser.