This is my quadcopter prototype software, still in development!
quadv3/mbed/PortInOut.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_PORTINOUT_H |
Anaesthetix | 0:978110f7f027 | 6 | #define MBED_PORTINOUT_H |
Anaesthetix | 0:978110f7f027 | 7 | |
Anaesthetix | 0:978110f7f027 | 8 | #include "device.h" |
Anaesthetix | 0:978110f7f027 | 9 | |
Anaesthetix | 0:978110f7f027 | 10 | #if DEVICE_PORTINOUT |
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: PortInOut |
Anaesthetix | 0:978110f7f027 | 18 | * A multiple pin digital in/out used to set/read multiple bi-directional pins |
Anaesthetix | 0:978110f7f027 | 19 | */ |
Anaesthetix | 0:978110f7f027 | 20 | class PortInOut { |
Anaesthetix | 0:978110f7f027 | 21 | public: |
Anaesthetix | 0:978110f7f027 | 22 | |
Anaesthetix | 0:978110f7f027 | 23 | /* Constructor: PortInOut |
Anaesthetix | 0:978110f7f027 | 24 | * Create an PortInOut, connected to the specified port |
Anaesthetix | 0:978110f7f027 | 25 | * |
Anaesthetix | 0:978110f7f027 | 26 | * Variables: |
Anaesthetix | 0:978110f7f027 | 27 | * port - Port to connect to (Port0-Port5) |
Anaesthetix | 0:978110f7f027 | 28 | * mask - A bitmask to identify which bits in the port should be included (0 - ignore) |
Anaesthetix | 0:978110f7f027 | 29 | */ |
Anaesthetix | 0:978110f7f027 | 30 | PortInOut(PortName port, int mask = 0xFFFFFFFF); |
Anaesthetix | 0:978110f7f027 | 31 | |
Anaesthetix | 0:978110f7f027 | 32 | /* Function: write |
Anaesthetix | 0:978110f7f027 | 33 | * Write the value to the output port |
Anaesthetix | 0:978110f7f027 | 34 | * |
Anaesthetix | 0:978110f7f027 | 35 | * Variables: |
Anaesthetix | 0:978110f7f027 | 36 | * value - An integer specifying a bit to write for every corresponding port pin |
Anaesthetix | 0:978110f7f027 | 37 | */ |
Anaesthetix | 0:978110f7f027 | 38 | void write(int value); |
Anaesthetix | 0:978110f7f027 | 39 | |
Anaesthetix | 0:978110f7f027 | 40 | /* Function: read |
Anaesthetix | 0:978110f7f027 | 41 | * Read the value currently output on the port |
Anaesthetix | 0:978110f7f027 | 42 | * |
Anaesthetix | 0:978110f7f027 | 43 | * Variables: |
Anaesthetix | 0:978110f7f027 | 44 | * returns - An integer with each bit corresponding to associated port pin setting |
Anaesthetix | 0:978110f7f027 | 45 | */ |
Anaesthetix | 0:978110f7f027 | 46 | int read(); |
Anaesthetix | 0:978110f7f027 | 47 | |
Anaesthetix | 0:978110f7f027 | 48 | /* Function: output |
Anaesthetix | 0:978110f7f027 | 49 | * Set as an output |
Anaesthetix | 0:978110f7f027 | 50 | */ |
Anaesthetix | 0:978110f7f027 | 51 | void output(); |
Anaesthetix | 0:978110f7f027 | 52 | |
Anaesthetix | 0:978110f7f027 | 53 | /* Function: input |
Anaesthetix | 0:978110f7f027 | 54 | * Set as an input |
Anaesthetix | 0:978110f7f027 | 55 | */ |
Anaesthetix | 0:978110f7f027 | 56 | void input(); |
Anaesthetix | 0:978110f7f027 | 57 | |
Anaesthetix | 0:978110f7f027 | 58 | /* Function: mode |
Anaesthetix | 0:978110f7f027 | 59 | * Set the input pin mode |
Anaesthetix | 0:978110f7f027 | 60 | * |
Anaesthetix | 0:978110f7f027 | 61 | * Variables: |
Anaesthetix | 0:978110f7f027 | 62 | * mode - PullUp, PullDown, PullNone, OpenDrain |
Anaesthetix | 0:978110f7f027 | 63 | */ |
Anaesthetix | 0:978110f7f027 | 64 | void mode(PinMode mode); |
Anaesthetix | 0:978110f7f027 | 65 | |
Anaesthetix | 0:978110f7f027 | 66 | /* Function: operator= |
Anaesthetix | 0:978110f7f027 | 67 | * A shorthand for <write> |
Anaesthetix | 0:978110f7f027 | 68 | */ |
Anaesthetix | 0:978110f7f027 | 69 | PortInOut& operator= (int value) { |
Anaesthetix | 0:978110f7f027 | 70 | write(value); |
Anaesthetix | 0:978110f7f027 | 71 | return *this; |
Anaesthetix | 0:978110f7f027 | 72 | } |
Anaesthetix | 0:978110f7f027 | 73 | |
Anaesthetix | 0:978110f7f027 | 74 | PortInOut& operator= (PortInOut& rhs) { |
Anaesthetix | 0:978110f7f027 | 75 | write(rhs.read()); |
Anaesthetix | 0:978110f7f027 | 76 | return *this; |
Anaesthetix | 0:978110f7f027 | 77 | } |
Anaesthetix | 0:978110f7f027 | 78 | |
Anaesthetix | 0:978110f7f027 | 79 | /* Function: operator int() |
Anaesthetix | 0:978110f7f027 | 80 | * A shorthand for <read> |
Anaesthetix | 0:978110f7f027 | 81 | */ |
Anaesthetix | 0:978110f7f027 | 82 | operator int() { |
Anaesthetix | 0:978110f7f027 | 83 | return read(); |
Anaesthetix | 0:978110f7f027 | 84 | } |
Anaesthetix | 0:978110f7f027 | 85 | |
Anaesthetix | 0:978110f7f027 | 86 | private: |
Anaesthetix | 0:978110f7f027 | 87 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
Anaesthetix | 0:978110f7f027 | 88 | LPC_GPIO_TypeDef *_gpio; |
Anaesthetix | 0:978110f7f027 | 89 | #endif |
Anaesthetix | 0:978110f7f027 | 90 | PortName _port; |
Anaesthetix | 0:978110f7f027 | 91 | uint32_t _mask; |
Anaesthetix | 0:978110f7f027 | 92 | }; |
Anaesthetix | 0:978110f7f027 | 93 | |
Anaesthetix | 0:978110f7f027 | 94 | } // namespace mbed |
Anaesthetix | 0:978110f7f027 | 95 | |
Anaesthetix | 0:978110f7f027 | 96 | #endif |
Anaesthetix | 0:978110f7f027 | 97 | |
Anaesthetix | 0:978110f7f027 | 98 | #endif |