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