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