This is my quadcopter prototype software, still in development!
quadv3/mbed/PortOut.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 - PortOut |
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_PORTOUT_H |
Anaesthetix | 0:978110f7f027 | 6 | #define MBED_PORTOUT_H |
Anaesthetix | 0:978110f7f027 | 7 | |
Anaesthetix | 0:978110f7f027 | 8 | #include "device.h" |
Anaesthetix | 0:978110f7f027 | 9 | |
Anaesthetix | 0:978110f7f027 | 10 | #if DEVICE_PORTOUT |
Anaesthetix | 0:978110f7f027 | 11 | |
Anaesthetix | 0:978110f7f027 | 12 | #include "platform.h" |
Anaesthetix | 0:978110f7f027 | 13 | #include "PinNames.h" |
Anaesthetix | 0:978110f7f027 | 14 | #include "Base.h" |
Anaesthetix | 0:978110f7f027 | 15 | |
Anaesthetix | 0:978110f7f027 | 16 | #include "PortNames.h" |
Anaesthetix | 0:978110f7f027 | 17 | |
Anaesthetix | 0:978110f7f027 | 18 | namespace mbed { |
Anaesthetix | 0:978110f7f027 | 19 | /* Class: PortOut |
Anaesthetix | 0:978110f7f027 | 20 | * A multiple pin digital out |
Anaesthetix | 0:978110f7f027 | 21 | * |
Anaesthetix | 0:978110f7f027 | 22 | * Example: |
Anaesthetix | 0:978110f7f027 | 23 | * > // Toggle all four LEDs |
Anaesthetix | 0:978110f7f027 | 24 | * > |
Anaesthetix | 0:978110f7f027 | 25 | * > #include "mbed.h" |
Anaesthetix | 0:978110f7f027 | 26 | * > |
Anaesthetix | 0:978110f7f027 | 27 | * > // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23 |
Anaesthetix | 0:978110f7f027 | 28 | * > #define LED_MASK 0x00B40000 |
Anaesthetix | 0:978110f7f027 | 29 | * > |
Anaesthetix | 0:978110f7f027 | 30 | * > PortOut ledport(Port1, LED_MASK); |
Anaesthetix | 0:978110f7f027 | 31 | * > |
Anaesthetix | 0:978110f7f027 | 32 | * > int main() { |
Anaesthetix | 0:978110f7f027 | 33 | * > while(1) { |
Anaesthetix | 0:978110f7f027 | 34 | * > ledport = LED_MASK; |
Anaesthetix | 0:978110f7f027 | 35 | * > wait(1); |
Anaesthetix | 0:978110f7f027 | 36 | * > ledport = 0; |
Anaesthetix | 0:978110f7f027 | 37 | * > wait(1); |
Anaesthetix | 0:978110f7f027 | 38 | * > } |
Anaesthetix | 0:978110f7f027 | 39 | * > } |
Anaesthetix | 0:978110f7f027 | 40 | */ |
Anaesthetix | 0:978110f7f027 | 41 | class PortOut { |
Anaesthetix | 0:978110f7f027 | 42 | public: |
Anaesthetix | 0:978110f7f027 | 43 | |
Anaesthetix | 0:978110f7f027 | 44 | /* Constructor: PortOut |
Anaesthetix | 0:978110f7f027 | 45 | * Create an PortOut, connected to the specified port |
Anaesthetix | 0:978110f7f027 | 46 | * |
Anaesthetix | 0:978110f7f027 | 47 | * Variables: |
Anaesthetix | 0:978110f7f027 | 48 | * port - Port to connect to (Port0-Port5) |
Anaesthetix | 0:978110f7f027 | 49 | * mask - A bitmask to identify which bits in the port should be included (0 - ignore) |
Anaesthetix | 0:978110f7f027 | 50 | */ |
Anaesthetix | 0:978110f7f027 | 51 | PortOut(PortName port, int mask = 0xFFFFFFFF); |
Anaesthetix | 0:978110f7f027 | 52 | |
Anaesthetix | 0:978110f7f027 | 53 | /* Function: write |
Anaesthetix | 0:978110f7f027 | 54 | * Write the value to the output port |
Anaesthetix | 0:978110f7f027 | 55 | * |
Anaesthetix | 0:978110f7f027 | 56 | * Variables: |
Anaesthetix | 0:978110f7f027 | 57 | * value - An integer specifying a bit to write for every corresponding PortOut pin |
Anaesthetix | 0:978110f7f027 | 58 | */ |
Anaesthetix | 0:978110f7f027 | 59 | void write(int value); |
Anaesthetix | 0:978110f7f027 | 60 | |
Anaesthetix | 0:978110f7f027 | 61 | /* Function: read |
Anaesthetix | 0:978110f7f027 | 62 | * Read the value currently output on the port |
Anaesthetix | 0:978110f7f027 | 63 | * |
Anaesthetix | 0:978110f7f027 | 64 | * Variables: |
Anaesthetix | 0:978110f7f027 | 65 | * returns - An integer with each bit corresponding to associated PortOut pin setting |
Anaesthetix | 0:978110f7f027 | 66 | */ |
Anaesthetix | 0:978110f7f027 | 67 | int read(); |
Anaesthetix | 0:978110f7f027 | 68 | |
Anaesthetix | 0:978110f7f027 | 69 | /* Function: operator= |
Anaesthetix | 0:978110f7f027 | 70 | * A shorthand for <write> |
Anaesthetix | 0:978110f7f027 | 71 | */ |
Anaesthetix | 0:978110f7f027 | 72 | PortOut& operator= (int value) { |
Anaesthetix | 0:978110f7f027 | 73 | write(value); |
Anaesthetix | 0:978110f7f027 | 74 | return *this; |
Anaesthetix | 0:978110f7f027 | 75 | } |
Anaesthetix | 0:978110f7f027 | 76 | |
Anaesthetix | 0:978110f7f027 | 77 | PortOut& operator= (PortOut& rhs) { |
Anaesthetix | 0:978110f7f027 | 78 | write(rhs.read()); |
Anaesthetix | 0:978110f7f027 | 79 | return *this; |
Anaesthetix | 0:978110f7f027 | 80 | } |
Anaesthetix | 0:978110f7f027 | 81 | |
Anaesthetix | 0:978110f7f027 | 82 | /* Function: operator int() |
Anaesthetix | 0:978110f7f027 | 83 | * A shorthand for <read> |
Anaesthetix | 0:978110f7f027 | 84 | */ |
Anaesthetix | 0:978110f7f027 | 85 | operator int() { |
Anaesthetix | 0:978110f7f027 | 86 | return read(); |
Anaesthetix | 0:978110f7f027 | 87 | } |
Anaesthetix | 0:978110f7f027 | 88 | |
Anaesthetix | 0:978110f7f027 | 89 | private: |
Anaesthetix | 0:978110f7f027 | 90 | #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) |
Anaesthetix | 0:978110f7f027 | 91 | LPC_GPIO_TypeDef *_gpio; |
Anaesthetix | 0:978110f7f027 | 92 | #endif |
Anaesthetix | 0:978110f7f027 | 93 | PortName _port; |
Anaesthetix | 0:978110f7f027 | 94 | uint32_t _mask; |
Anaesthetix | 0:978110f7f027 | 95 | }; |
Anaesthetix | 0:978110f7f027 | 96 | |
Anaesthetix | 0:978110f7f027 | 97 | } // namespace mbed |
Anaesthetix | 0:978110f7f027 | 98 | |
Anaesthetix | 0:978110f7f027 | 99 | #endif |
Anaesthetix | 0:978110f7f027 | 100 | |
Anaesthetix | 0:978110f7f027 | 101 | #endif |