This is my quadcopter prototype software, still in development!

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?

UserRevisionLine numberNew contents of line
Anaesthetix 0:978110f7f027 1 /* mbed Microcontroller Library - DigitalInOut
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_DIGITALINOUT_H
Anaesthetix 0:978110f7f027 6 #define MBED_DIGITALINOUT_H
Anaesthetix 0:978110f7f027 7
Anaesthetix 0:978110f7f027 8 #include "platform.h"
Anaesthetix 0:978110f7f027 9 #include "PinNames.h"
Anaesthetix 0:978110f7f027 10 #include "PeripheralNames.h"
Anaesthetix 0:978110f7f027 11 #include "Base.h"
Anaesthetix 0:978110f7f027 12
Anaesthetix 0:978110f7f027 13 namespace mbed {
Anaesthetix 0:978110f7f027 14
Anaesthetix 0:978110f7f027 15 /* Class: DigitalInOut
Anaesthetix 0:978110f7f027 16 * A digital input/output, used for setting or reading a bi-directional pin
Anaesthetix 0:978110f7f027 17 */
Anaesthetix 0:978110f7f027 18 class DigitalInOut : public Base {
Anaesthetix 0:978110f7f027 19
Anaesthetix 0:978110f7f027 20 public:
Anaesthetix 0:978110f7f027 21
Anaesthetix 0:978110f7f027 22 /* Constructor: DigitalInOut
Anaesthetix 0:978110f7f027 23 * Create a DigitalInOut connected to the specified pin
Anaesthetix 0:978110f7f027 24 *
Anaesthetix 0:978110f7f027 25 * Variables:
Anaesthetix 0:978110f7f027 26 * pin - DigitalInOut pin to connect to
Anaesthetix 0:978110f7f027 27 */
Anaesthetix 0:978110f7f027 28 DigitalInOut(PinName pin, const char* name = NULL);
Anaesthetix 0:978110f7f027 29
Anaesthetix 0:978110f7f027 30 /* Function: write
Anaesthetix 0:978110f7f027 31 * Set the output, specified as 0 or 1 (int)
Anaesthetix 0:978110f7f027 32 *
Anaesthetix 0:978110f7f027 33 * Variables:
Anaesthetix 0:978110f7f027 34 * value - An integer specifying the pin output value,
Anaesthetix 0:978110f7f027 35 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1
Anaesthetix 0:978110f7f027 36 */
Anaesthetix 0:978110f7f027 37 void write(int value) {
Anaesthetix 0:978110f7f027 38 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
Anaesthetix 0:978110f7f027 39
Anaesthetix 0:978110f7f027 40 if(value) {
Anaesthetix 0:978110f7f027 41 _gpio->FIOSET = _mask;
Anaesthetix 0:978110f7f027 42 } else {
Anaesthetix 0:978110f7f027 43 _gpio->FIOCLR = _mask;
Anaesthetix 0:978110f7f027 44 }
Anaesthetix 0:978110f7f027 45
Anaesthetix 0:978110f7f027 46 #elif defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 47
Anaesthetix 0:978110f7f027 48 if(value) {
Anaesthetix 0:978110f7f027 49 LPC_GPIO->SET[_index] = _mask;
Anaesthetix 0:978110f7f027 50 } else {
Anaesthetix 0:978110f7f027 51 LPC_GPIO->CLR[_index] = _mask;
Anaesthetix 0:978110f7f027 52 }
Anaesthetix 0:978110f7f027 53 #endif
Anaesthetix 0:978110f7f027 54 }
Anaesthetix 0:978110f7f027 55
Anaesthetix 0:978110f7f027 56 /* Function: read
Anaesthetix 0:978110f7f027 57 * Return the output setting, represented as 0 or 1 (int)
Anaesthetix 0:978110f7f027 58 *
Anaesthetix 0:978110f7f027 59 * Variables:
Anaesthetix 0:978110f7f027 60 * returns - An integer representing the output setting of the pin if it is an output,
Anaesthetix 0:978110f7f027 61 * or read the input if set as an input
Anaesthetix 0:978110f7f027 62 */
Anaesthetix 0:978110f7f027 63 int read() {
Anaesthetix 0:978110f7f027 64 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
Anaesthetix 0:978110f7f027 65
Anaesthetix 0:978110f7f027 66 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
Anaesthetix 0:978110f7f027 67 #elif defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 68 return ((LPC_GPIO->PIN[_index] & _mask) ? 1 : 0);
Anaesthetix 0:978110f7f027 69 #endif
Anaesthetix 0:978110f7f027 70 }
Anaesthetix 0:978110f7f027 71
Anaesthetix 0:978110f7f027 72
Anaesthetix 0:978110f7f027 73 /* Function: output
Anaesthetix 0:978110f7f027 74 * Set as an output
Anaesthetix 0:978110f7f027 75 */
Anaesthetix 0:978110f7f027 76 void output();
Anaesthetix 0:978110f7f027 77
Anaesthetix 0:978110f7f027 78 /* Function: input
Anaesthetix 0:978110f7f027 79 * Set as an input
Anaesthetix 0:978110f7f027 80 */
Anaesthetix 0:978110f7f027 81 void input();
Anaesthetix 0:978110f7f027 82
Anaesthetix 0:978110f7f027 83 /* Function: mode
Anaesthetix 0:978110f7f027 84 * Set the input pin mode
Anaesthetix 0:978110f7f027 85 *
Anaesthetix 0:978110f7f027 86 * Variables:
Anaesthetix 0:978110f7f027 87 * mode - PullUp, PullDown, PullNone, OpenDrain
Anaesthetix 0:978110f7f027 88 */
Anaesthetix 0:978110f7f027 89 void mode(PinMode pull);
Anaesthetix 0:978110f7f027 90
Anaesthetix 0:978110f7f027 91 #ifdef MBED_OPERATORS
Anaesthetix 0:978110f7f027 92 /* Function: operator=
Anaesthetix 0:978110f7f027 93 * A shorthand for <write>
Anaesthetix 0:978110f7f027 94 */
Anaesthetix 0:978110f7f027 95 DigitalInOut& operator= (int value) {
Anaesthetix 0:978110f7f027 96 write(value);
Anaesthetix 0:978110f7f027 97 return *this;
Anaesthetix 0:978110f7f027 98 }
Anaesthetix 0:978110f7f027 99
Anaesthetix 0:978110f7f027 100 DigitalInOut& operator= (DigitalInOut& rhs) {
Anaesthetix 0:978110f7f027 101 write(rhs.read());
Anaesthetix 0:978110f7f027 102 return *this;
Anaesthetix 0:978110f7f027 103 }
Anaesthetix 0:978110f7f027 104
Anaesthetix 0:978110f7f027 105 /* Function: operator int()
Anaesthetix 0:978110f7f027 106 * A shorthand for <read>
Anaesthetix 0:978110f7f027 107 */
Anaesthetix 0:978110f7f027 108 operator int() {
Anaesthetix 0:978110f7f027 109 return read();
Anaesthetix 0:978110f7f027 110 }
Anaesthetix 0:978110f7f027 111 #endif
Anaesthetix 0:978110f7f027 112
Anaesthetix 0:978110f7f027 113 #ifdef MBED_RPC
Anaesthetix 0:978110f7f027 114 virtual const struct rpc_method *get_rpc_methods();
Anaesthetix 0:978110f7f027 115 static struct rpc_class *get_rpc_class();
Anaesthetix 0:978110f7f027 116 #endif
Anaesthetix 0:978110f7f027 117
Anaesthetix 0:978110f7f027 118 protected:
Anaesthetix 0:978110f7f027 119
Anaesthetix 0:978110f7f027 120 PinName _pin;
Anaesthetix 0:978110f7f027 121
Anaesthetix 0:978110f7f027 122 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
Anaesthetix 0:978110f7f027 123 LPC_GPIO_TypeDef *_gpio;
Anaesthetix 0:978110f7f027 124 #elif defined(TARGET_LPC11U24)
Anaesthetix 0:978110f7f027 125 int _index;
Anaesthetix 0:978110f7f027 126 #endif
Anaesthetix 0:978110f7f027 127
Anaesthetix 0:978110f7f027 128 uint32_t _mask;
Anaesthetix 0:978110f7f027 129
Anaesthetix 0:978110f7f027 130 };
Anaesthetix 0:978110f7f027 131
Anaesthetix 0:978110f7f027 132 } // namespace mbed
Anaesthetix 0:978110f7f027 133
Anaesthetix 0:978110f7f027 134 #endif