This is my quadcopter prototype software, still in development!
quadv3/mbed/PortIn.h@1:ac68f0368a77, 2013-07-23 (annotated)
- Committer:
- Anaesthetix
- Date:
- Tue Jul 23 14:01:42 2013 +0000
- Revision:
- 1:ac68f0368a77
- Parent:
- 0:978110f7f027
Other accelerometer added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:978110f7f027 | 1 | /* mbed Microcontroller Library - PortInOut |
Anaesthetix | 0:978110f7f027 | 2 | * Copyright (c) 2006-2011 ARM Limited. All rights reserved. |
Anaesthetix | 0:978110f7f027 | 3 | */ |
Anaesthetix | 0:978110f7f027 | 4 | |
Anaesthetix | 0:978110f7f027 | 5 | #ifndef MBED_PORTIN_H |
Anaesthetix | 0:978110f7f027 | 6 | #define MBED_PORTIN_H |
Anaesthetix | 0:978110f7f027 | 7 | |
Anaesthetix | 0:978110f7f027 | 8 | #include "device.h" |
Anaesthetix | 0:978110f7f027 | 9 | |
Anaesthetix | 0:978110f7f027 | 10 | #if DEVICE_PORTIN |
Anaesthetix | 0:978110f7f027 | 11 | |
Anaesthetix | 0:978110f7f027 | 12 | #include "PortNames.h" |
Anaesthetix | 0:978110f7f027 | 13 | #include "PinNames.h" |
Anaesthetix | 0:978110f7f027 | 14 | |
Anaesthetix | 0:978110f7f027 | 15 | namespace mbed { |
Anaesthetix | 0:978110f7f027 | 16 | |
Anaesthetix | 0:978110f7f027 | 17 | /* Class: PortIn |
Anaesthetix | 0:978110f7f027 | 18 | * A multiple pin digital input |
Anaesthetix | 0:978110f7f027 | 19 | * |
Anaesthetix | 0:978110f7f027 | 20 | * Example: |
Anaesthetix | 0:978110f7f027 | 21 | * > // Switch on an LED if any of mbed pins 21-26 is high |
Anaesthetix | 0:978110f7f027 | 22 | * > |
Anaesthetix | 0:978110f7f027 | 23 | * > #include "mbed.h" |
Anaesthetix | 0:978110f7f027 | 24 | * > |
Anaesthetix | 0:978110f7f027 | 25 | * > PortIn p(Port2, 0x0000003F); // p21-p26 |
Anaesthetix | 0:978110f7f027 | 26 | * > DigitalOut ind(LED4); |
Anaesthetix | 0:978110f7f027 | 27 | * > |
Anaesthetix | 0:978110f7f027 | 28 | * > int main() { |
Anaesthetix | 0:978110f7f027 | 29 | * > while(1) { |
Anaesthetix | 0:978110f7f027 | 30 | * > int pins = p.read(); |
Anaesthetix | 0:978110f7f027 | 31 | * > if(pins) { |
Anaesthetix | 0:978110f7f027 | 32 | * > ind = 1; |
Anaesthetix | 0:978110f7f027 | 33 | * > } else { |
Anaesthetix | 0:978110f7f027 | 34 | * > ind = 0; |
Anaesthetix | 0:978110f7f027 | 35 | * > } |
Anaesthetix | 0:978110f7f027 | 36 | * > } |
Anaesthetix | 0:978110f7f027 | 37 | * > } |
Anaesthetix | 0:978110f7f027 | 38 | */ |
Anaesthetix | 0:978110f7f027 | 39 | class PortIn { |
Anaesthetix | 0:978110f7f027 | 40 | public: |
Anaesthetix | 0:978110f7f027 | 41 | |
Anaesthetix | 0:978110f7f027 | 42 | /* Constructor: PortIn |
Anaesthetix | 0:978110f7f027 | 43 | * Create an PortIn, connected to the specified port |
Anaesthetix | 0:978110f7f027 | 44 | * |
Anaesthetix | 0:978110f7f027 | 45 | * Variables: |
Anaesthetix | 0:978110f7f027 | 46 | * port - Port to connect to (Port0-Port5) |
Anaesthetix | 0:978110f7f027 | 47 | * mask - A bitmask to identify which bits in the port should be included (0 - ignore) |
Anaesthetix | 0:978110f7f027 | 48 | */ |
Anaesthetix | 0:978110f7f027 | 49 | PortIn(PortName port, int mask = 0xFFFFFFFF); |
Anaesthetix | 0:978110f7f027 | 50 | |
Anaesthetix | 0:978110f7f027 | 51 | /* Function: read |
Anaesthetix | 0:978110f7f027 | 52 | * Read the value currently output on the port |
Anaesthetix | 0:978110f7f027 | 53 | * |
Anaesthetix | 0:978110f7f027 | 54 | * Variables: |
Anaesthetix | 0:978110f7f027 | 55 | * returns - An integer with each bit corresponding to associated port pin setting |
Anaesthetix | 0:978110f7f027 | 56 | */ |
Anaesthetix | 0:978110f7f027 | 57 | int read(); |
Anaesthetix | 0:978110f7f027 | 58 | |
Anaesthetix | 0:978110f7f027 | 59 | /* Function: mode |
Anaesthetix | 0:978110f7f027 | 60 | * Set the input pin mode |
Anaesthetix | 0:978110f7f027 | 61 | * |
Anaesthetix | 0:978110f7f027 | 62 | * Variables: |
Anaesthetix | 0:978110f7f027 | 63 | * mode - PullUp, PullDown, PullNone, OpenDrain |
Anaesthetix | 0:978110f7f027 | 64 | */ |
Anaesthetix | 0:978110f7f027 | 65 | void mode(PinMode mode); |
Anaesthetix | 0:978110f7f027 | 66 | |
Anaesthetix | 0:978110f7f027 | 67 | /* Function: operator int() |
Anaesthetix | 0:978110f7f027 | 68 | * A shorthand for <read> |
Anaesthetix | 0:978110f7f027 | 69 | */ |
Anaesthetix | 0:978110f7f027 | 70 | operator int() { |
Anaesthetix | 0:978110f7f027 | 71 | return read(); |
Anaesthetix | 0:978110f7f027 | 72 | } |
Anaesthetix | 0:978110f7f027 | 73 | |
Anaesthetix | 0:978110f7f027 | 74 | private: |
Anaesthetix | 0:978110f7f027 | 75 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
Anaesthetix | 0:978110f7f027 | 76 | LPC_GPIO_TypeDef *_gpio; |
Anaesthetix | 0:978110f7f027 | 77 | #endif |
Anaesthetix | 0:978110f7f027 | 78 | PortName _port; |
Anaesthetix | 0:978110f7f027 | 79 | uint32_t _mask; |
Anaesthetix | 0:978110f7f027 | 80 | }; |
Anaesthetix | 0:978110f7f027 | 81 | |
Anaesthetix | 0:978110f7f027 | 82 | } // namespace mbed |
Anaesthetix | 0:978110f7f027 | 83 | |
Anaesthetix | 0:978110f7f027 | 84 | #endif |
Anaesthetix | 0:978110f7f027 | 85 | |
Anaesthetix | 0:978110f7f027 | 86 | #endif |