mbed libraries for KL25Z
PortIn.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 - PortInOut |
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_PORTIN_H |
emilmont | 0:8024c367e29f | 6 | #define MBED_PORTIN_H |
emilmont | 0:8024c367e29f | 7 | |
emilmont | 0:8024c367e29f | 8 | #include "device.h" |
emilmont | 0:8024c367e29f | 9 | |
emilmont | 0:8024c367e29f | 10 | #if DEVICE_PORTIN |
emilmont | 0:8024c367e29f | 11 | |
emilmont | 0:8024c367e29f | 12 | #include "PortNames.h" |
emilmont | 0:8024c367e29f | 13 | #include "PinNames.h" |
emilmont | 0:8024c367e29f | 14 | |
emilmont | 0:8024c367e29f | 15 | namespace mbed { |
emilmont | 0:8024c367e29f | 16 | |
emilmont | 0:8024c367e29f | 17 | /* Class: PortIn |
emilmont | 0:8024c367e29f | 18 | * A multiple pin digital input |
emilmont | 0:8024c367e29f | 19 | * |
emilmont | 0:8024c367e29f | 20 | * Example: |
emilmont | 0:8024c367e29f | 21 | * > // Switch on an LED if any of mbed pins 21-26 is high |
emilmont | 0:8024c367e29f | 22 | * > |
emilmont | 0:8024c367e29f | 23 | * > #include "mbed.h" |
emilmont | 0:8024c367e29f | 24 | * > |
emilmont | 0:8024c367e29f | 25 | * > PortIn p(Port2, 0x0000003F); // p21-p26 |
emilmont | 0:8024c367e29f | 26 | * > DigitalOut ind(LED4); |
emilmont | 0:8024c367e29f | 27 | * > |
emilmont | 0:8024c367e29f | 28 | * > int main() { |
emilmont | 0:8024c367e29f | 29 | * > while(1) { |
emilmont | 0:8024c367e29f | 30 | * > int pins = p.read(); |
emilmont | 0:8024c367e29f | 31 | * > if(pins) { |
emilmont | 0:8024c367e29f | 32 | * > ind = 1; |
emilmont | 0:8024c367e29f | 33 | * > } else { |
emilmont | 0:8024c367e29f | 34 | * > ind = 0; |
emilmont | 0:8024c367e29f | 35 | * > } |
emilmont | 0:8024c367e29f | 36 | * > } |
emilmont | 0:8024c367e29f | 37 | * > } |
emilmont | 0:8024c367e29f | 38 | */ |
emilmont | 0:8024c367e29f | 39 | class PortIn { |
emilmont | 0:8024c367e29f | 40 | public: |
emilmont | 0:8024c367e29f | 41 | |
emilmont | 0:8024c367e29f | 42 | /* Constructor: PortIn |
emilmont | 0:8024c367e29f | 43 | * Create an PortIn, connected to the specified port |
emilmont | 0:8024c367e29f | 44 | * |
emilmont | 0:8024c367e29f | 45 | * Variables: |
emilmont | 0:8024c367e29f | 46 | * port - Port to connect to (Port0-Port5) |
emilmont | 0:8024c367e29f | 47 | * mask - A bitmask to identify which bits in the port should be included (0 - ignore) |
emilmont | 0:8024c367e29f | 48 | */ |
emilmont | 0:8024c367e29f | 49 | PortIn(PortName port, int mask = 0xFFFFFFFF); |
emilmont | 0:8024c367e29f | 50 | |
emilmont | 0:8024c367e29f | 51 | /* Function: read |
emilmont | 0:8024c367e29f | 52 | * Read the value currently output on the port |
emilmont | 0:8024c367e29f | 53 | * |
emilmont | 0:8024c367e29f | 54 | * Variables: |
emilmont | 0:8024c367e29f | 55 | * returns - An integer with each bit corresponding to associated port pin setting |
emilmont | 0:8024c367e29f | 56 | */ |
emilmont | 0:8024c367e29f | 57 | int read(); |
emilmont | 0:8024c367e29f | 58 | |
emilmont | 0:8024c367e29f | 59 | /* Function: mode |
emilmont | 0:8024c367e29f | 60 | * Set the input pin mode |
emilmont | 0:8024c367e29f | 61 | * |
emilmont | 0:8024c367e29f | 62 | * Variables: |
emilmont | 0:8024c367e29f | 63 | * mode - PullUp, PullDown, PullNone, OpenDrain |
emilmont | 0:8024c367e29f | 64 | */ |
emilmont | 0:8024c367e29f | 65 | void mode(PinMode mode); |
emilmont | 0:8024c367e29f | 66 | |
emilmont | 0:8024c367e29f | 67 | /* Function: operator int() |
emilmont | 0:8024c367e29f | 68 | * A shorthand for <read> |
emilmont | 0:8024c367e29f | 69 | */ |
emilmont | 0:8024c367e29f | 70 | operator int() { |
emilmont | 0:8024c367e29f | 71 | return read(); |
emilmont | 0:8024c367e29f | 72 | } |
emilmont | 0:8024c367e29f | 73 | |
emilmont | 0:8024c367e29f | 74 | private: |
emilmont | 0:8024c367e29f | 75 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
emilmont | 0:8024c367e29f | 76 | LPC_GPIO_TypeDef *_gpio; |
emilmont | 0:8024c367e29f | 77 | #endif |
emilmont | 0:8024c367e29f | 78 | PortName _port; |
emilmont | 0:8024c367e29f | 79 | uint32_t _mask; |
emilmont | 0:8024c367e29f | 80 | }; |
emilmont | 0:8024c367e29f | 81 | |
emilmont | 0:8024c367e29f | 82 | } // namespace mbed |
emilmont | 0:8024c367e29f | 83 | |
emilmont | 0:8024c367e29f | 84 | #endif |
emilmont | 0:8024c367e29f | 85 | |
emilmont | 0:8024c367e29f | 86 | #endif |