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