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